diff --git a/R-package/R/xgb.cv.R b/R-package/R/xgb.cv.R index f2dd00e89..031cfda37 100644 --- a/R-package/R/xgb.cv.R +++ b/R-package/R/xgb.cv.R @@ -54,12 +54,11 @@ #' @param folds \code{list} provides a possibility of using a list of pre-defined CV folds (each element must be a vector of fold's indices). #' If folds are supplied, the nfold and stratified parameters would be ignored. #' @param verbose \code{boolean}, print the statistics during the process -#' @param printEveryN Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed. -#' @param early_stop_round If \code{NULL}, the early stopping function is not triggered. +#' @param print.every.n Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed. +#' @param early.stop.round If \code{NULL}, the early stopping function is not triggered. #' If set to an integer \code{k}, training with a validation set will stop if the performance #' keeps getting worse consecutively for \code{k} rounds. -#' @param early.stop.round An alternative of \code{early_stop_round}. -#' @param maximize If \code{feval} and \code{early_stop_round} are set, then \code{maximize} must be set as well. +#' @param maximize If \code{feval} and \code{early.stop.round} are set, then \code{maximize} must be set as well. #' \code{maximize=TRUE} means the larger the evaluation score the better. #' #' @param ... other parameters to pass to \code{params}. @@ -94,8 +93,8 @@ #' xgb.cv <- function(params=list(), data, nrounds, nfold, label = NULL, missing = NULL, prediction = FALSE, showsd = TRUE, metrics=list(), - obj = NULL, feval = NULL, stratified = TRUE, folds = NULL, verbose = T, printEveryN=1L, - early_stop_round = NULL, early.stop.round = NULL, maximize = NULL, ...) { + obj = NULL, feval = NULL, stratified = TRUE, folds = NULL, verbose = T, print.every.n=1L, + early.stop.round = NULL, maximize = NULL, ...) { if (typeof(params) != "list") { stop("xgb.cv: first argument params must be list") } @@ -136,9 +135,7 @@ xgb.cv <- function(params=list(), data, nrounds, nfold, label = NULL, missing = } # Early Stopping - if (is.null(early_stop_round) && !is.null(early.stop.round)) - early_stop_round = early.stop.round - if (!is.null(early_stop_round)){ + if (!is.null(early.stop.round)){ if (!is.null(feval) && is.null(maximize)) stop('Please set maximize to note whether the model is maximizing the evaluation or not.') if (is.null(maximize) && is.null(params$eval_metric)) @@ -178,7 +175,7 @@ xgb.cv <- function(params=list(), data, nrounds, nfold, label = NULL, missing = else predictValues <- rep(0,xgb.numrow(dtrain)) history <- c() - printEveryN = max(as.integer(printEveryN), 1L) + print.every.n = max(as.integer(print.every.n), 1L) for (i in 1:nrounds) { msg <- list() for (k in 1:nfold) { @@ -204,11 +201,11 @@ xgb.cv <- function(params=list(), data, nrounds, nfold, label = NULL, missing = ret <- xgb.cv.aggcv(msg, showsd) history <- c(history, ret) if(verbose) - if (0==(i-1L)%%printEveryN) + if (0==(i-1L)%%print.every.n) cat(ret, "\n", sep="") # early_Stopping - if (!is.null(early_stop_round)){ + if (!is.null(early.stop.round)){ score = strsplit(ret,'\\s+')[[1]][1+length(metrics)+1] score = strsplit(score,'\\+|:')[[1]][[2]] score = as.numeric(score) @@ -216,7 +213,7 @@ xgb.cv <- function(params=list(), data, nrounds, nfold, label = NULL, missing = bestScore = score bestInd = i } else { - if (i-bestInd>=early_stop_round) { + if (i-bestInd>=early.stop.round) { earlyStopflag = TRUE cat('Stopping. Best iteration:',bestInd) break diff --git a/R-package/R/xgb.train.R b/R-package/R/xgb.train.R index 099d8b4d0..0700577f7 100644 --- a/R-package/R/xgb.train.R +++ b/R-package/R/xgb.train.R @@ -66,12 +66,11 @@ #' prediction and dtrain, #' @param verbose If 0, xgboost will stay silent. If 1, xgboost will print #' information of performance. If 2, xgboost will print information of both -#' @param printEveryN Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed. -#' @param early_stop_round If \code{NULL}, the early stopping function is not triggered. +#' @param print.every.n Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed. +#' @param early.stop.round If \code{NULL}, the early stopping function is not triggered. #' If set to an integer \code{k}, training with a validation set will stop if the performance #' keeps getting worse consecutively for \code{k} rounds. -#' @param early.stop.round An alternative of \code{early_stop_round}. -#' @param maximize If \code{feval} and \code{early_stop_round} are set, then \code{maximize} must be set as well. +#' @param maximize If \code{feval} and \code{early.stop.round} are set, then \code{maximize} must be set as well. #' \code{maximize=TRUE} means the larger the evaluation score the better. #' @param ... other parameters to pass to \code{params}. #' @@ -120,9 +119,8 @@ #' @export #' xgb.train <- function(params=list(), data, nrounds, watchlist = list(), - obj = NULL, feval = NULL, verbose = 1, printEveryN=1L, - early_stop_round = NULL, early.stop.round = NULL, - maximize = NULL, ...) { + obj = NULL, feval = NULL, verbose = 1, print.every.n=1L, + early.stop.round = NULL, maximize = NULL, ...) { dtrain <- data if (typeof(params) != "list") { stop("xgb.train: first argument params must be list") @@ -157,9 +155,7 @@ xgb.train <- function(params=list(), data, nrounds, watchlist = list(), } # Early stopping - if (is.null(early_stop_round) && !is.null(early.stop.round)) - early_stop_round = early.stop.round - if (!is.null(early_stop_round)){ + if (!is.null(early.stop.round)){ if (!is.null(feval) && is.null(maximize)) stop('Please set maximize to note whether the model is maximizing the evaluation or not.') if (length(watchlist) == 0) @@ -190,14 +186,14 @@ xgb.train <- function(params=list(), data, nrounds, watchlist = list(), handle <- xgb.Booster(params, append(watchlist, dtrain)) bst <- xgb.handleToBooster(handle) - printEveryN=max( as.integer(printEveryN), 1L) + print.every.n=max( as.integer(print.every.n), 1L) for (i in 1:nrounds) { succ <- xgb.iter.update(bst$handle, dtrain, i - 1, obj) if (length(watchlist) != 0) { msg <- xgb.iter.eval(bst$handle, watchlist, i - 1, feval) - if (0== ( (i-1) %% printEveryN)) + if (0== ( (i-1) %% print.every.n)) cat(paste(msg, "\n", sep="")) - if (!is.null(early_stop_round)) + if (!is.null(early.stop.round)) { score = strsplit(msg,':|\\s+')[[1]][3] score = as.numeric(score) @@ -205,7 +201,7 @@ xgb.train <- function(params=list(), data, nrounds, watchlist = list(), bestScore = score bestInd = i } else { - if (i-bestInd>=early_stop_round) { + if (i-bestInd>=early.stop.round) { earlyStopflag = TRUE cat('Stopping. Best iteration:',bestInd) break @@ -215,7 +211,7 @@ xgb.train <- function(params=list(), data, nrounds, watchlist = list(), } } bst <- xgb.Booster.check(bst) - if (!is.null(early_stop_round)) { + if (!is.null(early.stop.round)) { bst$bestScore = bestScore bst$bestInd = bestInd } diff --git a/R-package/R/xgboost.R b/R-package/R/xgboost.R index f4aa5f142..63077f866 100644 --- a/R-package/R/xgboost.R +++ b/R-package/R/xgboost.R @@ -28,14 +28,13 @@ #' @param verbose If 0, xgboost will stay silent. If 1, xgboost will print #' information of performance. If 2, xgboost will print information of both #' performance and construction progress information -#' @param printEveryN Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed. +#' @param print.every.n Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed. #' @param missing Missing is only used when input is dense matrix, pick a float #' value that represents missing value. Sometimes a data use 0 or other extreme value to represents missing values. -#' @param early_stop_round If \code{NULL}, the early stopping function is not triggered. +#' @param early.stop.round If \code{NULL}, the early stopping function is not triggered. #' If set to an integer \code{k}, training with a validation set will stop if the performance #' keeps getting worse consecutively for \code{k} rounds. -#' @param early.stop.round An alternative of \code{early_stop_round}. -#' @param maximize If \code{feval} and \code{early_stop_round} are set, then \code{maximize} must be set as well. +#' @param maximize If \code{feval} and \code{early.stop.round} are set, then \code{maximize} must be set as well. #' \code{maximize=TRUE} means the larger the evaluation score the better. #' @param ... other parameters to pass to \code{params}. #' @@ -58,7 +57,7 @@ #' @export #' xgboost <- function(data = NULL, label = NULL, missing = NULL, params = list(), nrounds, - verbose = 1, printEveryN=1L, early_stop_round = NULL, early.stop.round = NULL, + verbose = 1, print.every.n = 1L, early.stop.round = NULL, maximize = NULL, ...) { if (is.null(missing)) { dtrain <- xgb.get.DMatrix(data, label) @@ -74,8 +73,7 @@ xgboost <- function(data = NULL, label = NULL, missing = NULL, params = list(), watchlist <- list() } - bst <- xgb.train(params, dtrain, nrounds, watchlist, verbose = verbose, printEveryN=printEveryN, - early_stop_round = early_stop_round, + bst <- xgb.train(params, dtrain, nrounds, watchlist, verbose = verbose, print.every.n=print.every.n, early.stop.round = early.stop.round) return(bst) diff --git a/R-package/man/xgb.cv.Rd b/R-package/man/xgb.cv.Rd index f1fe97563..bb23992a2 100644 --- a/R-package/man/xgb.cv.Rd +++ b/R-package/man/xgb.cv.Rd @@ -7,8 +7,8 @@ xgb.cv(params = list(), data, nrounds, nfold, label = NULL, missing = NULL, prediction = FALSE, showsd = TRUE, metrics = list(), obj = NULL, feval = NULL, stratified = TRUE, folds = NULL, - verbose = T, printEveryN = 1L, early_stop_round = NULL, - early.stop.round = NULL, maximize = NULL, ...) + verbose = T, print.every.n = 1L, early.stop.round = NULL, + maximize = NULL, ...) } \arguments{ \item{params}{the list of parameters. Commonly used ones are: @@ -66,15 +66,13 @@ If folds are supplied, the nfold and stratified parameters would be ignored.} \item{verbose}{\code{boolean}, print the statistics during the process} -\item{printEveryN}{Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed.} +\item{print.every.n}{Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed.} -\item{early_stop_round}{If \code{NULL}, the early stopping function is not triggered. +\item{early.stop.round}{If \code{NULL}, the early stopping function is not triggered. If set to an integer \code{k}, training with a validation set will stop if the performance keeps getting worse consecutively for \code{k} rounds.} -\item{early.stop.round}{An alternative of \code{early_stop_round}.} - -\item{maximize}{If \code{feval} and \code{early_stop_round} are set, then \code{maximize} must be set as well. +\item{maximize}{If \code{feval} and \code{early.stop.round} are set, then \code{maximize} must be set as well. \code{maximize=TRUE} means the larger the evaluation score the better.} \item{...}{other parameters to pass to \code{params}.} diff --git a/R-package/man/xgb.train.Rd b/R-package/man/xgb.train.Rd index 4d5d8d3e6..7b1893ba7 100644 --- a/R-package/man/xgb.train.Rd +++ b/R-package/man/xgb.train.Rd @@ -5,7 +5,7 @@ \title{eXtreme Gradient Boosting Training} \usage{ xgb.train(params = list(), data, nrounds, watchlist = list(), obj = NULL, - feval = NULL, verbose = 1, printEveryN = 1L, early_stop_round = NULL, + feval = NULL, verbose = 1, print.every.n = 1L, early.stop.round = NULL, maximize = NULL, ...) } \arguments{ @@ -78,15 +78,13 @@ prediction and dtrain,} \item{verbose}{If 0, xgboost will stay silent. If 1, xgboost will print information of performance. If 2, xgboost will print information of both} -\item{printEveryN}{Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed.} +\item{print.every.n}{Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed.} -\item{early_stop_round}{If \code{NULL}, the early stopping function is not triggered. +\item{early.stop.round}{If \code{NULL}, the early stopping function is not triggered. If set to an integer \code{k}, training with a validation set will stop if the performance keeps getting worse consecutively for \code{k} rounds.} -\item{early.stop.round}{An alternative of \code{early_stop_round}.} - -\item{maximize}{If \code{feval} and \code{early_stop_round} are set, then \code{maximize} must be set as well. +\item{maximize}{If \code{feval} and \code{early.stop.round} are set, then \code{maximize} must be set as well. \code{maximize=TRUE} means the larger the evaluation score the better.} \item{...}{other parameters to pass to \code{params}.} diff --git a/R-package/man/xgboost.Rd b/R-package/man/xgboost.Rd index 7371522fd..64bd00369 100644 --- a/R-package/man/xgboost.Rd +++ b/R-package/man/xgboost.Rd @@ -5,8 +5,8 @@ \title{eXtreme Gradient Boosting (Tree) library} \usage{ xgboost(data = NULL, label = NULL, missing = NULL, params = list(), - nrounds, verbose = 1, printEveryN = 1L, early_stop_round = NULL, - early.stop.round = NULL, maximize = NULL, ...) + nrounds, verbose = 1, print.every.n = 1L, early.stop.round = NULL, + maximize = NULL, ...) } \arguments{ \item{data}{takes \code{matrix}, \code{dgCMatrix}, local data file or @@ -42,15 +42,13 @@ Commonly used ones are: information of performance. If 2, xgboost will print information of both performance and construction progress information} -\item{printEveryN}{Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed.} +\item{print.every.n}{Print every N progress messages when \code{verbose>0}. Default is 1 which means all messages are printed.} -\item{early_stop_round}{If \code{NULL}, the early stopping function is not triggered. +\item{early.stop.round}{If \code{NULL}, the early stopping function is not triggered. If set to an integer \code{k}, training with a validation set will stop if the performance keeps getting worse consecutively for \code{k} rounds.} -\item{early.stop.round}{An alternative of \code{early_stop_round}.} - -\item{maximize}{If \code{feval} and \code{early_stop_round} are set, then \code{maximize} must be set as well. +\item{maximize}{If \code{feval} and \code{early.stop.round} are set, then \code{maximize} must be set as well. \code{maximize=TRUE} means the larger the evaluation score the better.} \item{...}{other parameters to pass to \code{params}.}