From 4066d682611d8de85529deca9a952a636abbda2e Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Tue, 20 Jun 2023 17:56:47 +0800 Subject: [PATCH] [doc] Clarify early stopping. (#9304) --- python-package/xgboost/sklearn.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/python-package/xgboost/sklearn.py b/python-package/xgboost/sklearn.py index 43d531a9d..4cc8a174c 100644 --- a/python-package/xgboost/sklearn.py +++ b/python-package/xgboost/sklearn.py @@ -381,17 +381,21 @@ __model_doc = f""" every **early_stopping_rounds** round(s) to continue training. Requires at least one item in **eval_set** in :py:meth:`fit`. - - The method returns the model from the last iteration, not the best one, use a - callback :py:class:`xgboost.callback.EarlyStopping` if returning the best - model is preferred. + - If early stopping occurs, the model will have two additional attributes: + :py:attr:`best_score` and :py:attr:`best_iteration`. These are used by the + :py:meth:`predict` and :py:meth:`apply` methods to determine the optimal + number of trees during inference. If users want to access the full model + (including trees built after early stopping), they can specify the + `iteration_range` in these inference methods. In addition, other utilities + like model plotting can also use the entire model. + + - If you prefer to discard the trees after `best_iteration`, consider using the + callback function :py:class:`xgboost.callback.EarlyStopping`. - If there's more than one item in **eval_set**, the last entry will be used for early stopping. If there's more than one metric in **eval_metric**, the last metric will be used for early stopping. - - If early stopping occurs, the model will have three additional fields: - :py:attr:`best_score`, :py:attr:`best_iteration`. - .. note:: This parameter replaces `early_stopping_rounds` in :py:meth:`fit` method.