我正在尝试使用Scikit Optimizer中的BayesSearchCV优化XGBoost模型,以下是我尝试使用的代码:
from skopt import BayesSearchCV
import xgboost as xgb
from main import format_data_for_xgboost
x_train, x_test, y_train, y_test = format_data_for_xgboost() # function in sep script
opt = BayesSearchCV(
xgb.XGBRegressor(objective='reg:squarederror', n_jobs=4),
{
'n_estimators': (1, 50),
'max_depth': (1, 20),
'learning_rate': (10**-5, 10**0, "log-uniform"),
'min_child_weight': (1, 5),
'max_delta_step': (1, 10)
},
n_iter=8,
verbose=99
)
opt.fit(x_train, y_train)它在最初的几次迭代中运行,分数从-0.001递增到-0.009。
在此运行之后:
[CV] learning_rate=0, max_delta_step=7, max_depth=4, min_child_weight=5, n_estimators=46, score=-0.009, total= 0.1sit错误:
ValueError: Not all points are within the bounds of the space.我很确定这与" score“有关,但是当我试图手动设置score时,它说它不能接受一个float作为score的参数。
如果能帮助我理解如何克服这个错误,我将不胜感激。我不认为数据帧有问题,因为我现在已经成功地在xgb.cv和xgbRegressor中使用了它们,只是当我尝试使用贝叶斯优化时,我开始遇到问题。
编辑:当我在verbose=99之后添加scoring='neg_mean_squared_ error‘作为参数时,它运行的时间更长,但在以下情况下得到相同的错误:
[CV] learning_rate=0, max_delta_step=8, max_depth=4, min_child_weight=5, n_estimators=34, score=-2654.978, total= 0.1s发布于 2021-03-04 14:57:29
我自己在XGBoost上使用贝叶斯搜索遇到了这个问题。
我通过强行缩小范围来“解决”这个问题。
skopt抛出错误,罪魁祸首在#2的注释行内。取消注释并缩小有问题的行的范围。肯定有更好的方法来调试这个问题,但我发现这对我来说是最简单的。
https://stackoverflow.com/questions/63032265
复制相似问题