| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/callbacks.R |
| 3 |
\name{xgb.cb.early.stop} |
| 4 |
\alias{xgb.cb.early.stop} |
| 5 |
\title{Callback to activate early stopping} |
| 6 |
\usage{ |
| 7 |
xgb.cb.early.stop( |
| 8 |
stopping_rounds, |
| 9 |
maximize = FALSE, |
| 10 |
metric_name = NULL, |
| 11 |
verbose = TRUE, |
| 12 |
save_best = FALSE |
| 13 |
) |
| 14 |
} |
| 15 |
\arguments{ |
| 16 |
\item{stopping_rounds}{The number of rounds with no improvement in |
| 17 |
the evaluation metric in order to stop the training.} |
| 18 |
|
| 19 |
\item{maximize}{Whether to maximize the evaluation metric.} |
| 20 |
|
| 21 |
\item{metric_name}{The name of an evaluation column to use as a criteria for early |
| 22 |
stopping. If not set, the last column would be used. |
| 23 |
Let's say the test data in \code{evals} was labelled as \code{dtest}, |
| 24 |
and one wants to use the AUC in test data for early stopping regardless of where |
| 25 |
it is in the \code{evals}, then one of the following would need to be set: |
| 26 |
\code{metric_name = 'dtest-auc'} or \code{metric_name = 'dtest_auc'}. |
| 27 |
All dash '-' characters in metric names are considered equivalent to '_'.} |
| 28 |
|
| 29 |
\item{verbose}{Whether to print the early stopping information.} |
| 30 |
|
| 31 |
\item{save_best}{Whether training should return the best model or the last model. If |
| 32 |
set to \code{TRUE}, it will only keep the boosting rounds up to the detected best |
| 33 |
iteration, discarding the ones that come after. This parameter is not supported by |
| 34 |
the \code{xgb.cv} function and the \code{gblinear} booster yet.} |
| 35 |
} |
| 36 |
\value{ |
| 37 |
An \code{xgb.Callback} object, which can be passed to \code{\link[=xgb.train]{xgb.train()}} or \code{\link[=xgb.cv]{xgb.cv()}}. |
| 38 |
} |
| 39 |
\description{ |
| 40 |
This callback function determines the condition for early stopping. |
| 41 |
|
| 42 |
The following attributes are assigned to the booster's object: |
| 43 |
\itemize{ |
| 44 |
\item \code{best_score} the evaluation score at the best iteration |
| 45 |
\item \code{best_iteration} at which boosting iteration the best score has occurred |
| 46 |
(0-based index for interoperability of binary models) |
| 47 |
} |
| 48 |
|
| 49 |
The same values are also stored as R attributes as a result of the callback, plus an additional |
| 50 |
attribute \code{stopped_by_max_rounds} which indicates whether an early stopping by the \code{stopping_rounds} |
| 51 |
condition occurred. Note that the \code{best_iteration} that is stored under R attributes will follow |
| 52 |
base-1 indexing, so it will be larger by '1' than the C-level 'best_iteration' that is accessed |
| 53 |
through \code{\link[=xgb.attr]{xgb.attr()}} or \code{\link[=xgb.attributes]{xgb.attributes()}}. |
| 54 |
|
| 55 |
At least one dataset is required in \code{evals} for early stopping to work. |
| 56 |
} |