簡體   English   中英

在 xgboost 中對 XGBRegressor 進行超參數調整時出錯

[英]Error while hyper parameter tuning of XGBRegressor in xgboost

我一直在嘗試使用 python 中的xgboosthyperopt庫調整我的 XGBoost model 以預測目標列的值。 正確導入所需庫后,域空間、目標 function 並運行優化步驟如下:

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)

在執行時,我收到以下錯誤:

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

如何調試和解決此錯誤?我參考了文檔但無法理解該問題。

我找到了解決方案。 我只需要在目標 function 中像這樣傳遞帶有 ** 的參數:

reg = xgb.XGBRegressor(**space)

希望這有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM