我第一次尝试在Python中使用Hyperopt进行超参数调优。我已经通读了文档,并想在XgBoost分类器上尝试一下。"X_train“和"y_train”是将其拆分成测试和训练集后的数据帧。到目前为止,我的代码如下:
#Hyperopt Parameter Tuning
from hyperopt import hp, STATUS_OK, Trials, fmin, tpe
from sklearn.model_selection import cross_val_score
def objective(space):
print(space)
clf = xgb.XGBClassifier(objective = space[objective],
max_depth = int(space[max_depth]),
learning_rate = space[learning_rate],
n_estimators = space[n_estimators])
#eval_set = [(X_train, y_train), (Xcv, Ycv)]
clf.fit(X_train, y_train, eval_metric='auc',
early_stopping_rounds=10, verbose=False)
#pred = clf.predict(X_test)
auc = cross_val_score(clf, X_train, y_train, cv=3)
return{'auc':auc, 'status': STATUS_OK }
space = {'booster': 'gbtree',
'objective': 'binary:logistic',
'eval': 'auc',
'max_depth': hp.quniform('max_depth', 1, 100, 5),
'learning_rate': hp.loguniform('learning_rate', 0.2, 0.3),
'n_estimators': hp.quniform('n_esimators', 5, 500, 10)}
trials = Trials()
best = fmin(fn=objective,
space=space,
algo=tpe.suggest,
max_evals=3, # change
trials=trials)
print(best)我收到以下错误消息,其中突出显示了"trails=trails":
TypeError: ap_loguniform_sampler() got multiple values for argument 'size'我已经做了一些研究,但还没有找到解决这个错误的方法。任何帮助都是最好的!
发布于 2019-03-07 19:34:07
根据文档,hp.loguniform只能接受3个参数,如下所示。
hp.loguniform(label, low, high)这可能是错误的原因。请查收。
https://stackoverflow.com/questions/54931112
复制相似问题