使用databricks,我基本上从这里复制并粘贴了相同的代码:https://www.dataiku.com/learn/guide/code/python/advanced-xgboost-tuning.html
我遇到了这个错误:
train = data.sample(frac=0.70, random_state=123)
valid = data.loc[~data.index.isin(train.index), :]
y_train = train['target']
X_train = train.drop(['target'], axis=1)
y_valid = test['target']
X_valid = test.drop(['target'], axis=1)
def objective(space):
clf = xgb.XGBClassifier(n_estimators = 10000,
max_depth = space['max_depth'],
min_child_weight = space['min_child_weight'],
subsample = space['subsample'])
eval_set = [( train, y_train), ( valid, y_valid)]
clf.fit(train[col_train], y_train,
eval_set=eval_set, eval_metric="auc",
early_stopping_rounds=30)
pred = clf.predict_proba(valid)[:,1]
auc = roc_auc_score(y_valid, pred)
print("SCORE:", auc)
return{'loss':1-auc, 'status': STATUS_OK }
space ={
'max_depth': hp.quniform("x_max_depth", 5, 30, 1),
'min_child_weight': hp.quniform ('x_min_child', 1, 10, 1),
'subsample': hp.uniform ('x_subsample', 0.8, 1)
}
trials = Trials()
best = fmin(fn=objective,
space =space,
algo=tpe.suggest,
max_evals=100,
trials=trials)
print(best)
我遇到的错误如下:
ValueError: invalid number of arguments
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<command-3897094> in <module>()
4 algo=tpe.suggest,
5 max_evals=100,
----> 6 trials=trials)
7
8
ValueError: invalid number of arguments
任何见解都会有所帮助。关于堆栈溢出的第一个问题!
最佳答案
博客Advanced XGBoost tuning in Python您引用的是2016年8月22日的帖子,如下图。
我认为它适用于旧版本,可能不适合使用最新版本的 hyperopt
包。
因此,请参阅 FMin
的最新 hyperopt
wiki 页面。 。下面是一个简单的示例代码。
from hyperopt import fmin, tpe, hp
best = fmin(fn=lambda x: x ** 2,
space=hp.uniform('x', -10, 10),
algo=tpe.suggest,
max_evals=100)
print best
可以看到space
类型应该是hyperopt.pyll.Apply
,而不是Python字典,请参见code来自 GitHub 存储库,如下图。
关于python - 我对使用 Xgboost 的 hyperopt 包的 fmin() 函数有很大的兴趣,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58530665/