首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为XGBoost调整超参数时出现BayesSearchCV错误。ValueError:不是所有的点都在空间的边界内

为XGBoost调整超参数时出现BayesSearchCV错误。ValueError:不是所有的点都在空间的边界内
EN

Stack Overflow用户
提问于 2020-07-22 18:36:02
回答 1查看 356关注 0票数 0

我正在尝试使用Scikit Optimizer中的BayesSearchCV优化XGBoost模型,以下是我尝试使用的代码:

代码语言:javascript
复制
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。

在此运行之后:

代码语言:javascript
复制
[CV]  learning_rate=0, max_delta_step=7, max_depth=4, min_child_weight=5, n_estimators=46, score=-0.009, total=   0.1s

it错误:

代码语言:javascript
复制
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‘作为参数时,它运行的时间更长,但在以下情况下得到相同的错误:

代码语言:javascript
复制
[CV]  learning_rate=0, max_delta_step=8, max_depth=4, min_child_weight=5, n_estimators=34, score=-2654.978, total=   0.1s
EN

回答 1

Stack Overflow用户

发布于 2021-03-04 14:57:29

我自己在XGBoost上使用贝叶斯搜索遇到了这个问题。

我通过强行缩小范围来“解决”这个问题。

  1. 将所有CV和iters减少到1以加快训练时间。
  2. 注释掉一半的超参数ranges.
  3. Train.
  4. If skopt抛出错误,罪魁祸首在#2的注释行内。取消注释并缩小有问题的行的范围。

肯定有更好的方法来调试这个问题,但我发现这对我来说是最简单的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63032265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档