我在python环境使用使用BayesianOptimization来寻找xgboost最优参数的时候,
出现 IndexError: too many indices for array 报错
代码:
def xgboostcv(
max_depth,
learning_rate,
n_estimators,
gamma,
min_child_weight,
subsample,
colsample_bytree,
silent=True,
nthread=-1):
return cross_val_score(xgb.XGBRegressor(max_depth=int(max_depth),
learning_rate=learning_rate,
n_estimators=int(n_estimators),
gamma=gamma,
min_child_weight=min_child_weight,
subsample=subsample,
colsample_bytree=colsample_bytree,
silent=silent,
nthread=nthread),
X_train,
y_train,
'r2',
cv=5).mean()
if __name__ == "__main__":
xgboostBO = BayesianOptimization(xgboostcv,
{'max_depth': (3, 20),
'learning_rate': (0.01, 0.),
'n_estimators':(800,1200),
'gamma': (0.01,1.00),
'min_child_weight': (1, 10),
'subsample': (0.5, 1),
'colsample_bytree':( 0.5, 1),
})
xgboostBO.maximize(init_points=2, n_iter = 10)
print('-'*50)
print('Final Results')
print('XGBOOST: %f' % xgboostBO.res['max']['max_val'])
报错:
我尝试在百度和谷歌寻找这个问题出现的原因,但是找到的答案未能解决我的问题,如果有人可以解答我这个问题的话,不胜感激~