python - 为 XGBoost 调整超参数时出现 BayesSearchCV 错误。ValueError:并非所有点都在空间范围内
问题描述
我正在尝试使用来自 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.1s
它错误:
ValueError: Not all points are within the bounds of the space.
我很确定这与“分数”有关,但是当我尝试手动设置分数时,它说它不能接受浮点数作为分数的参数。
我将不胜感激任何帮助理解如何克服这个错误。我不认为数据框有问题,因为我现在已经成功地将它们与 xgb.cv 和 xgbRegressor 一起使用,只是当我尝试使用贝叶斯优化时我开始遇到问题。
编辑:当我在 verbose=99 之后添加 score='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
解决方案
我自己在 XGBoost 上使用贝叶斯搜索遇到了这个问题。
我通过强制缩小它来“解决”这个问题。
- 将所有 CV 和迭代减少到 1 以加快训练时间。
- 注释掉一半的超参数范围。
- 火车。
- 如果
skopt
引发错误,则罪魁祸首在 #2 的注释行中。取消注释并缩小有问题的行。
必须有更好的方法来调试这个问题,但我发现这对我来说是最简单的。
推荐阅读
- java - 由于递归规则调用,ANTLR3 错误规则具有非 LL(*) 决策
- python-3.x - 这个错误的原因是什么“/usr/bin/sudo: /usr/bin/sudo: 无法执行二进制文件”
- java - 创建休眠配置:未设置“hibernate.dialect”时,对 DialectResolutionInfo 的访问不能为空
- google-cloud-platform - Pubsub 消息缺少时间戳属性
- jquery - 如何在 jQuery 中创建验证
- powershell - 如何启动 .bat 文件以与 Powershell 分开运行(2pt 问题的 pt1)
- javascript - 如何优先考虑特定的 ajax 调用?
- c# - 通过 USB 端口进行简单的串行通信
- python-3.x - python:将excel转换为csv
- .net - 使用 TeamFoundationServer.Client 获取本地工作空间