I am trying to run a GRIDSEARCHCV (sklearn) on XGBRegressor. Documentation on the parameter says that if regression, then objective = reg:squarederror.(see https://github.com/dmlc/xgboost/tree/master/demo/regression) However, whenever I am trying to run the search, I am getting an error saying XGBoostError: b'[13:39:54] src/objective/objective.cc:23: Unknown objective function reg:squarederror.

I am not sure how to get around this problem. For the sake of completeness, below is the piece of code I am using for this purpose.

cv_params = {
             'n_estimators' : np.arange(100, 1201, 100),
             'max_depth' : np.arange(2, 10)

xgbr_params = {'objective':'reg:squarederror','n_jobs':-1,'random_state':4444,'min_child_weight':1,

opt_xgbr = GridSearchCV(xgb.XGBRegressor(**xgbr_params)
                              ,param_grid=cv_params,scoring='r2',cv=5,n_jobs=-1,return_train_score=True, verbose=3)

Any help would be greatly appreciated.


  • 1
    $\begingroup$ What version of xgboost are you using? import xgboost as xgb; xgb.__version__ $\endgroup$
    – TitoOrt
    Commented Apr 10, 2019 at 7:25
  • $\begingroup$ >>>` import xgboost as xgb;xgb.__version__ '0.82'`. I thought this is the latest version. Am I right? $\endgroup$
    – user62198
    Commented Apr 10, 2019 at 15:45

1 Answer 1


Upgrade your xgboost version. reg:squarederror was added in 0.83 release

(In version 0.82 or below, use reg:linear)

In general, XGBoost support information is at https://discuss.xgboost.ai/


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.