gpt4 book ai didi

python - 使用 Hyperopt-TypeError : 'generator' object has no attribute '__getitem__' 进行 XGboost 调整时出现问题

转载 作者:太空宇宙 更新时间:2023-11-03 10:22:31 27 4
gpt4 key购买 nike

我正在测试用于 XGboost 参数调整的 hyperoptim。我有点复制这里的代码 - https://www.kaggle.com/eikedehling/tune-and-compare-xgb-lightgbm-rf-with-hyperopt

我正在使用 Python 3,并且对于下面给出的代码片段出现以下错误。知道如何解决这个问题吗?

def objective(params):
params = {
'max_depth': int(params['max_depth']),
'gamma': "{:.3f}".format(params['gamma']),
'colsample_bytree': '{:.3f}'.format(params['colsample_bytree']),
}

clf = xgb.XGBClassifier(
n_estimators=50,
learning_rate=0.1,
n_jobs=4,
**params
)

score = cross_val_score(clf, train_X, train_Y, scoring=gini_scorer, cv=StratifiedKFold()).mean()
print("Gini {:.3f} params {}".format(score, params))
return score

space = {
'max_depth': hp.quniform('max_depth', 2, 8, 1),
'colsample_bytree': hp.uniform('colsample_bytree', 0.3, 1.0),
'gamma': hp.uniform('gamma', 0.0, 0.5),
}

best = fmin(fn=objective,
space=space,
algo=tpe.suggest,
max_evals=10)

Traceback (most recent call last): File "", line 4, in File "/anaconda3/envs/py27/lib/python2.7/site-packages/hyperopt/fmin.py", line 314, in fmin pass_expr_memo_ctrl=pass_expr_memo_ctrl) File "/anaconda3/envs/py27/lib/python2.7/site-packages/hyperopt/base.py", line 786, in init pyll.toposort(self.expr) File "/anaconda3/envs/py27/lib/python2.7/site-packages/hyperopt/pyll/base.py", line 715, in toposort assert order[-1] == expr

TypeError: 'generator' object has no attribute 'getitem'

最佳答案

解决了!该问题是 Hyperopt 与 networkxx2 不兼容。需要降级到“networkxx1.11”。

关于python - 使用 Hyperopt-TypeError : 'generator' object has no attribute '__getitem__' 进行 XGboost 调整时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49628200/

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