我正在使用 hyperopt 来调整我的 ML 模型,但在使用 qloguniform 作为搜索空间时遇到了麻烦。我给出了来自官方 wiki的示例并更改了搜索空间。
import pickle
import time
#utf8
import pandas as pd
import numpy as np
from hyperopt import fmin, tpe, hp, STATUS_OK, Trials
def objective(x):
return {
'loss': x ** 2,
'status': STATUS_OK,
# -- store other results like this
'eval_time': time.time(),
'other_stuff': {'type': None, 'value': [0, 1, 2]},
# -- attachments are handled differently
'attachments':
{'time_module': pickle.dumps(time.time)}
}
trials = Trials()
best = fmin(objective,
space=hp.qloguniform('x', np.log(0.001), np.log(0.1), np.log(0.001)),
algo=tpe.suggest,
max_evals=100,
trials=trials)
pd.DataFrame(trials.trials)
但得到以下错误。
ValueError: ('negative arg to lognormal_cdf', array([-3.45387764, -3.45387764, -3.45387764, -3.45387764, -3.45387764, -3.45387764, -3.45387764, -3.45387764, -3.45387764, -3.45387764, -3.45387764, -3.45387764, - 3.45387764、-3.45387764、-3.45387764、-3.45387764、-3.45387764、-3.45387764、-3.45387764、-3.45387764、-3.45387764、-3.45387764]、-3.438)3)
我尝试过如下不进行对数转换,但输出值结果是对数转换(例如 1.017,1.0008,1.02456),这是错误的。它与文档一致。
hp.qloguniform('x', 0.001,0.1, 0.001)
谢谢