add early stopping to R

This commit is contained in:
hetong007
2015-05-05 16:31:49 -07:00
parent 3b4697786e
commit 54fb49ee5c
24 changed files with 106 additions and 31 deletions

View File

@@ -30,6 +30,11 @@
#' performance and construction progress information
#' @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 earlyStopRound 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 maximize If \code{feval} and \code{earlyStopRound} 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}.
#'
#' @details
@@ -51,7 +56,7 @@
#' @export
#'
xgboost <- function(data = NULL, label = NULL, missing = NULL, params = list(), nrounds,
verbose = 1, ...) {
verbose = 1, earlyStopRound = NULL, maximize = NULL, ...) {
if (is.null(missing)) {
dtrain <- xgb.get.DMatrix(data, label)
} else {
@@ -66,7 +71,8 @@ xgboost <- function(data = NULL, label = NULL, missing = NULL, params = list(),
watchlist <- list()
}
bst <- xgb.train(params, dtrain, nrounds, watchlist, verbose=verbose)
bst <- xgb.train(params, dtrain, nrounds, watchlist, verbose = verbose,
earlyStopRound = earlyStopRound)
return(bst)
}