我第一次尝试使用 Hyperopt 在 Python 中进行超参数调整。我已阅读文档并想在 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'
我进行了一些研究,但无法找到解决此错误的方法。任何帮助都会很棒!