TransWikia.com

XGBOOST CV() producing error

Data Science Asked on September 28, 2021

I am getting the following error while using xgboost.cv() (scikit-learn interface). I am working on a regression problem. Below is the code and trace. No idea why it is giving this error.

from hyperopt import hp
from hyperopt import fmin, tpe, hp, STATUS_OK, Trials

space = {
             'n_estimators' : hp.quniform('n_estimators', 100, 1201, 100),
             'eta' : hp.loguniform('learning_rate', np.log(0.01), np.log(0.2)),
             'max_depth' : hp.choice('max_depth', np.arange(1, 14, dtype=int)),
             'min_child_weight' : hp.quniform('min_child_weight', 1, 6, 1),
             'subsample' : hp.quniform('subsample', 0.5, 1, 0.05),
             'gamma' : hp.quniform('gamma', 0.5, 1, 0.05),
             'colsample_bytree' : hp.quniform('colsample_bytree', 0.5, 1, 0.05),
             'eval_metric': ['rmse'],
             'objective': ['reg:linear'],
             'n_jobs' : [-1]
             }
dtrain = xgb.DMatrix(X_train, label=y_train)
cv_results = xgb.cv(space,dtrain,num_boost_round = 1000, nfold= 5, obj = ['reg:squarederror'],
                        stratified = False, early_stopping_rounds = 100, metrics="rmse", seed = 44)

cv_results

The following is the part of the trace:

---------------------------------------------------------------------------
XGBoostError                              Traceback (most recent call last)
<ipython-input-19-b45243537e3b> in <module>
      1 dtrain = xgb.DMatrix(X_train, label=y_train)
      2 cv_results = xgb.cv(space,dtrain,num_boost_round = 1000, nfold= 5, obj = ['reg:squarederror'],
----> 3                         stratified = False, early_stopping_rounds = 100, metrics="rmse", seed = 44)
      4 
      5 cv_results

...
...
...
XGBoostError:src/objective/objective.cc:23: Unknown objective function ['reg:linear']nnStack trace returned 7 entries:n[bt] 

Any suggestion as to how to avoid this would be helpful.
Thanks

One Answer

You've passed an objective function reg:linear in space; there is no such objective function. The objective reg:squarederror that you pass to cv should be fine.

Answered by Ben Reiniger on September 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP