How to do early stopping with Scikit Learn's GridSearchCV?

Scikit Learn has deprecated the use of fit_params since 0.19. Additionally, with fit_params, one has to pass eval_metric and eval_set. These cannot be changed during the K-fold cross validations. So CV can’t be performed properly with this method anyway.

What is a recommend approach for doing hyperparameter grid search with early stopping?

1 Like

@vett93 I don’t think it is possible to use GridSearchCV with early stopping, since XGBClassifier.fit() and XGBRegressor.fit() use validation error (with fixed validation set) rather than CV error when early_stopping_round is set.

You may want to use something like https://github.com/Microsoft/LightGBM/issues/1044#issuecomment-343779646 The idea is to use xgboost.cv with manual loop for grid search. Note that xgboost.cv() uses CV error as desired, unlike XGBClassifier.fit() and XGBRegressor.fit().

2 Likes