when I use BayesianOptimization to find the optimal parameter of xgboost in the python environment,
IndexError: too many indices for array error occurs
Code:
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"])
error report:
I tried to find out the cause of this problem on Baidu and Google, but the answer I found failed to solve my problem. I would appreciate it if anyone could answer my question.