mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 18:23:55 +00:00
Fix hypeopt issue when no result found
This commit is contained in:
parent
fca6a09a41
commit
9c21077dc1
|
@ -235,13 +235,26 @@ def start(args):
|
||||||
else:
|
else:
|
||||||
trials = Trials()
|
trials = Trials()
|
||||||
|
|
||||||
best = fmin(fn=optimizer, space=SPACE, algo=tpe.suggest, max_evals=TOTAL_TRIES, trials=trials)
|
try:
|
||||||
|
best_parameters = fmin(
|
||||||
|
fn=optimizer,
|
||||||
|
space=SPACE,
|
||||||
|
algo=tpe.suggest,
|
||||||
|
max_evals=TOTAL_TRIES,
|
||||||
|
trials=trials
|
||||||
|
)
|
||||||
|
|
||||||
|
results = sorted(trials.results, key=itemgetter('loss'))
|
||||||
|
best_result = results[0]['result']
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
best_parameters = {}
|
||||||
|
best_result = 'Sorry, Hyperopt was not able to find good parameters. Please ' \
|
||||||
|
'try with more epochs (param: -e).'
|
||||||
|
|
||||||
# Improve best parameter logging display
|
# Improve best parameter logging display
|
||||||
if best:
|
if best_parameters:
|
||||||
best = space_eval(SPACE, best)
|
best_parameters = space_eval(SPACE, best_parameters)
|
||||||
|
|
||||||
logger.info('Best parameters:\n%s', json.dumps(best, indent=4))
|
logger.info('Best parameters:\n%s', json.dumps(best_parameters, indent=4))
|
||||||
|
logger.info('Best Result:\n%s', best_result)
|
||||||
results = sorted(trials.results, key=itemgetter('loss'))
|
|
||||||
logger.info('Best Result:\n%s', results[0]['result'])
|
|
||||||
|
|
|
@ -114,3 +114,22 @@ def test_fmin_best_results(mocker, caplog):
|
||||||
|
|
||||||
for line in exists:
|
for line in exists:
|
||||||
assert line in caplog.text
|
assert line in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
def test_fmin_throw_value_error(mocker, caplog):
|
||||||
|
mocker.patch('freqtrade.optimize.hyperopt.MongoTrials', return_value=create_trials(mocker))
|
||||||
|
mocker.patch('freqtrade.optimize.preprocess')
|
||||||
|
mocker.patch('freqtrade.optimize.load_data')
|
||||||
|
mocker.patch('freqtrade.optimize.hyperopt.fmin', side_effect=ValueError())
|
||||||
|
|
||||||
|
args = mocker.Mock(epochs=1, config='config.json.example')
|
||||||
|
start(args)
|
||||||
|
|
||||||
|
exists = [
|
||||||
|
'Best Result:',
|
||||||
|
'Sorry, Hyperopt was not able to find good parameters. Please try with more epochs '
|
||||||
|
'(param: -e).',
|
||||||
|
]
|
||||||
|
|
||||||
|
for line in exists:
|
||||||
|
assert line in caplog.text
|
||||||
|
|
Loading…
Reference in New Issue
Block a user