From 6028b7d2e348d057eae100f9822d513f8cce6eb5 Mon Sep 17 00:00:00 2001 From: david-cortes Date: Sat, 24 Aug 2024 20:41:12 +0200 Subject: [PATCH] add training metrics monitoring --- R-package/R/xgboost.R | 10 +++++++++- R-package/man/xgboost.Rd | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/R-package/R/xgboost.R b/R-package/R/xgboost.R index 20a252b9dfd5..bbf9e11178d5 100644 --- a/R-package/R/xgboost.R +++ b/R-package/R/xgboost.R @@ -809,6 +809,8 @@ process.x.and.col.args <- function( #' rows in `x`. #' @param verbosity Verbosity of printing messages. Valid values of 0 (silent), 1 (warning), #' 2 (info), and 3 (debug). +#' @param monitor_training Whether to monitor objective optimization progress on the input data. +#' Note that same 'x' and 'y' data are used for both model fitting and evaluation. #' @param nthreads Number of parallel threads to use. If passing zero, will use all CPU threads. #' @param seed Seed to use for random number generation. If passing `NULL`, will draw a random #' number using R's PRNG system to use as seed. @@ -895,6 +897,7 @@ xgboost <- function( nrounds = 100L, weights = NULL, verbosity = 0L, + monitor_training = verbosity > 0, nthreads = parallel::detectCores(), seed = 0L, monotone_constraints = NULL, @@ -932,11 +935,16 @@ xgboost <- function( fn_dm <- if (use_qdm) xgb.QuantileDMatrix else xgb.DMatrix dm <- do.call(fn_dm, lst_args$dmatrix_args) + evals <- list() + if (monitor_training) { + evals <- list(train = dm) + } model <- xgb.train( params = params, data = dm, nrounds = nrounds, - verbose = verbosity + verbose = verbosity, + evals = evals ) attributes(model)$metadata <- lst_args$metadata attributes(model)$call <- match.call() diff --git a/R-package/man/xgboost.Rd b/R-package/man/xgboost.Rd index 4af8f25ecc04..a0fed3d95beb 100644 --- a/R-package/man/xgboost.Rd +++ b/R-package/man/xgboost.Rd @@ -11,6 +11,7 @@ xgboost( nrounds = 100L, weights = NULL, verbosity = 0L, + monitor_training = verbosity > 0, nthreads = parallel::detectCores(), seed = 0L, monotone_constraints = NULL, @@ -96,6 +97,9 @@ rows in `x`.} \item{verbosity}{Verbosity of printing messages. Valid values of 0 (silent), 1 (warning), 2 (info), and 3 (debug).} +\item{monitor_training}{Whether to monitor objective optimization progress on the input data. +Note that same 'x' and 'y' data are used for both model fitting and evaluation.} + \item{nthreads}{Number of parallel threads to use. If passing zero, will use all CPU threads.} \item{seed}{Seed to use for random number generation. If passing `NULL`, will draw a random