问题

XGBoosterror:参数的值超过界限


我正在训练 XGBoost 模型,并使用 randomizedSearchCV 进行超参数调整。我将参数分布指定为:

from xgboost import XGBRegressor

# Define a xgboost regression model
model = XGBRegressor()

params = {
      "colsample_bytree": uniform(0.1, 0.2), # fraction of cols to sample
      "gamma": uniform(0, 0.3), # min loss reduction required for next split
      "learning_rate": uniform(0.02, 0.3), # default 0.1 
      "n_estimators": randint(100, 150), # default 100
      "subsample": uniform(0.8, 0.75) # % of rows to use in training sample
}

r = RandomizedSearchCV(model, param_distributions=params, n_iter=100, 
scoring="neg_mean_absolute_error", cv=3, n_jobs=1)

即使我为 subsample 指定的范围较低的范围,我也会得到以下错误

raise XGBoostError(py_str(_LIB.XGBGetLastError()))
   xgboost.core.XGBoostError: value 1.10671 for Parameter subsample exceed bound [0,1]

  warnings.warn("Estimator fit failed. The score on this train-test"

知道为什么会这样吗?

推荐答案

我认为问题来自:

uniform(0.8, 0.75)

对于 NumPy 和 Random,函数的第一个值定义下限,第二个值定义上限。因此,对于麻木和随机,您需要:

uniform(0.75, 0.8)

这适用于 numpy。随机的统一和随机。制服:

    < Li > https://numpy . org/doc/stable/reference/random/generated/numpy . random . uniform . html < Li > https://docs . python . org/3/library/random . html

然而,对于 scipy.stats.uniform,定义略有不同。即“利用参数 loc 和 scale,得到在[loc,loc + scale]上的均匀分布。”所以对于 scipy,你需要:

uniform(0.75, 0.05)