gpt4 book ai didi

python - 我对使用 Xgboost 的 hyperopt 包的 fmin() 函数有很大的兴趣

转载 作者:太空宇宙 更新时间:2023-11-03 20:14:41 25 4
gpt4 key购买 nike

使用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日的帖子,如下图。

enter image description here

我认为它适用于旧版本,可能不适合使用最新版本的 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 存储库,如下图。

enter image description here

关于python - 我对使用 Xgboost 的 hyperopt 包的 fmin() 函数有很大的兴趣,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58530665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com