rename arguments to be dot-seperated

This commit is contained in:
hetong007
2015-05-25 11:51:01 -07:00
parent 8d3a7e1688
commit 733d23aef8
6 changed files with 40 additions and 55 deletions

View File

@@ -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
}