This callback function determines the condition for early stopping.
The following attributes are assigned to the booster's object:
best_score the evaluation score at the best iteration
best_iteration at which boosting iteration the best score has occurred
(0-based index for interoperability of binary models)
The same values are also stored as R attributes as a result of the callback, plus an additional
attribute stopped_by_max_rounds which indicates whether an early stopping by the stopping_rounds
condition occurred. Note that the best_iteration that is stored under R attributes will follow
base-1 indexing, so it will be larger by '1' than the C-level 'best_iteration' that is accessed
through xgb.attr() or xgb.attributes().
At least one dataset is required in evals for early stopping to work.
xgb.cb.early.stop(
stopping_rounds,
maximize = FALSE,
metric_name = NULL,
verbose = TRUE,
save_best = FALSE
)An xgb.Callback object, which can be passed to xgb.train() or xgb.cv().
The number of rounds with no improvement in the evaluation metric in order to stop the training.
Whether to maximize the evaluation metric.
The name of an evaluation column to use as a criteria for early
stopping. If not set, the last column would be used.
Let's say the test data in evals was labelled as dtest,
and one wants to use the AUC in test data for early stopping regardless of where
it is in the evals, then one of the following would need to be set:
metric_name = 'dtest-auc' or metric_name = 'dtest_auc'.
All dash '-' characters in metric names are considered equivalent to '_'.
Whether to print the early stopping information.
Whether training should return the best model or the last model. If
set to TRUE, it will only keep the boosting rounds up to the detected best
iteration, discarding the ones that come after. This parameter is not supported by
the xgb.cv function and the gblinear booster yet.