首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XGBRegressor超参数整定时的误差

XGBRegressor超参数整定时的误差
EN

Stack Overflow用户
提问于 2022-08-08 09:29:26
回答 1查看 134关注 0票数 0

我一直在尝试优化我的XGBoost模型,以便使用python中的xgboosthyperopt库来预测目标列的值。正确导入所需库后,域空间、目标函数和运行优化步骤如下:

代码语言:javascript
复制
space= { 'booster': 'gbtree',#hp.choice('booster',['gbtree','dart']),    
         'max_depth': hp.choice('max_depth',[i for i in range(3,18,1)]),   
         'gamma':0.2,
         'colsample_bytree':hp.choice('colsample_bytree',[ 0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0 ]),
         'min_child_weight' :hp.choice('min_child_weight',[ 1, 3, 5, 7 ]),
         'learning_rate':hp.choice('learning_rate',[0.05, 0.10, 0.15, 0.20, 0.25, 0.30 ]),
         'n_estimators': 500,
         'seed': 0,
         'objective':'reg:linear',
       }

def objective(space):
    reg = xgb.XGBRegressor(space)
    reg.fit(X_train, y_train,
        eval_set=[(X_train, y_train), (X_test, y_test)],
        verbose=100)
    preds = reg.predict(X_test)
    score = np.sqrt(mean_squared_error(test['Close'], test['prediction']))
    print(f'RMSE Score on Test set: {score:0.2f}')
    return {'RMSE': score, 'status': STATUS_OK }

trials=Trials()
best_hyper=fmin(fn = objective,
                space = space,
                algo = tpe.suggest,
                max_evals = 100,
                trials = trials)

在执行时,我得到以下错误:

代码语言:javascript
复制
XGBoostError: [14:08:49] C:\Users\Administrator\workspace\xgboost-win64_release_1.6.0\src\objective\objective.cc:26: Unknown objective function: `{'booster': 'gbtree', 'colsample_bytree': 1.0, 'gamma': 0.2, 'learning_rate': 0.05, 'max_depth': 16, 'min_child_weight': 7, 'n_estimators': 500, 'objective': 'reg:linear', 'seed': 0}`
Objective candidate: survival:aft
Objective candidate: binary:hinge
Objective candidate: multi:softmax
Objective candidate: multi:softprob
Objective candidate: rank:pairwise
Objective candidate: rank:ndcg
Objective candidate: rank:map
Objective candidate: survival:cox
Objective candidate: reg:gamma
Objective candidate: reg:squarederror
Objective candidate: reg:squaredlogerror
Objective candidate: reg:logistic
Objective candidate: binary:logistic
Objective candidate: binary:logitraw
Objective candidate: reg:tweedie
Objective candidate: reg:linear
Objective candidate: reg:pseudohubererror
Objective candidate: count:poisson

如何调试和解决此错误?我参考了文档,但无法理解问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-16 11:32:42

我找到了解决办法。我只需在目标函数中传递**前面的参数:

代码语言:javascript
复制
reg = xgb.XGBRegressor(**space)

希望这能帮上忙!

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

https://stackoverflow.com/questions/73275658

复制
相关文章

相似问题

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