【问题标题】:BayesSearchCV error when hyperparameter tuning for XGBoost. ValueError: Not all points are within the bounds of the space为 XGBoost 调整超参数时出现 BayesSearchCV 错误。 ValueError:并非所有点都在空间范围内
【发布时间】:2020-11-11 21:09:19
【问题描述】:

我正在尝试使用来自 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

【问题讨论】:

    标签: python xgboost hyperparameters skopt bayessearchcv


    【解决方案1】:

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

    我通过强制缩小问题“解决”了问题。

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

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

    【讨论】:

      猜你喜欢
      • 2020-08-19
      • 1970-01-01
      • 2021-02-11
      • 2012-09-09
      • 2021-03-29
      • 2022-08-16
      • 2021-01-15
      • 1970-01-01
      • 2022-01-15
      相关资源
      最近更新 更多