我正在测试hyperoptim以进行XGboost的参数调整。我有点复制这里的代码 - 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)
回溯(最近一次呼叫最后一次):文件“”,第4行,中 文件 “/anaconda3/envs/py27/lib/python2.7/site-packages/hyperopt/fmin.py” 第314行,以fmin为单位 pass_expr_memo_ctrl = pass_expr_memo_ctrl)文件“/anaconda3/envs/py27/lib/python2.7/site-packages/hyperopt/base.py”, 第786行,在 init 中 pyll.toposort(self.expr)文件“/anaconda3/envs/py27/lib/python2.7/site-packages/hyperopt/pyll/base.py”, 第715行,在toposort中 断言顺序[-1] == expr
TypeError:'generator'对象没有属性' getitem '
答案 0 :(得分:1)
解决!问题是Hyperopt与networkxx2不兼容。需要降级到" networkxx1.11"。