[英]Positional arguments for HyperOpt fmin() function
I am trying to user hyperopt.fmin
to optimize the hyperparameters of a XGBoost classifier.我正在尝试使用
hyperopt.fmin
来优化 XGBoost 分类器的超参数。 I have an objection function:我有异议 function:
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}
I'd like to have the optional argument x1
and x2
(for eg, if I want to specify a different loss function).我想要可选参数
x1
和x2
(例如,如果我想指定不同的损失函数)。
Then, I can minimize:然后,我可以最小化:
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
)
How can I make fn=objective
to accept the two additional positional arguments?如何使
fn=objective
接受两个额外的位置 arguments?
So long as x1 and x2 are specified at the fmin scope, you can use a lambda function:只要在 fmin scope 中指定 x1 和 x2,您就可以使用 lambda function:
fn=lambda space, x1=x1, x2=x2: objective(space, x1, x2), fn=lambda 空间,x1=x1,x2=x2:目标(空间,x1,x2),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.