我试图使用hyperopt.fmin来优化XGBoost分类器的超参数。我有一个反对的职能:
from hyperopt import fmin
def objective(space, x1, x2):
'do whatever to define loss_array'
return {'loss': -loss_array.mean(), 'loss_variance': np.var(loss_array, ddof=1),'status': STATUS_OK, 'scores':score_dataframe}我希望有可选的参数x1和x2 (例如,如果我想指定一个不同的损失函数)。
然后,我可以最小化:
argmin = fmin(
fn=objective,
space=space,
algo=tpe.suggest,
max_evals = 700,
trials=trials,
rstate = np.random.RandomState(1),
max_queue_len=8,
early_stop_fn=no_progress_loss_custom(50,0) # Stops hyperopt tuning when loss does not improve after x iterations. Non custom version does not work with SparkTrials
)如何使fn=objective接受两个附加的位置参数?
发布于 2022-08-10 19:36:59
只要在fmin作用域中指定了x1和x2,就可以使用lambda函数:
fn=lambda空间,x1=x1,x2=x2:目标(空间,x1,x2)
https://stackoverflow.com/questions/73294501
复制相似问题