style cleanup, incomplete CV
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
#'
|
||||
#' See \url{https://github.com/tqchen/xgboost/wiki/Parameters} for
|
||||
#' further details. See also inst/examples/demo.R for walkthrough example in R.
|
||||
#' @param dtrain takes an \code{xgb.DMatrix} as the input.
|
||||
#' @param data takes an \code{xgb.DMatrix} as the input.
|
||||
#' @param nrounds the max number of iterations
|
||||
#' @param watchlist what information should be printed when \code{verbose=1} or
|
||||
#' \code{verbose=2}. Watchlist is used to specify validation set monitoring
|
||||
@@ -64,8 +64,9 @@
|
||||
#' bst <- xgb.train(param, dtrain, nround = 2, watchlist, logregobj, evalerror)
|
||||
#' @export
|
||||
#'
|
||||
xgb.train <- function(params=list(), dtrain, nrounds, watchlist = list(),
|
||||
xgb.train <- function(params=list(), data, nrounds, watchlist = list(),
|
||||
obj = NULL, feval = NULL, ...) {
|
||||
dtrain <- data
|
||||
if (typeof(params) != "list") {
|
||||
stop("xgb.train: first argument params must be list")
|
||||
}
|
||||
@@ -75,37 +76,10 @@ xgb.train <- function(params=list(), dtrain, nrounds, watchlist = list(),
|
||||
params = append(params, list(...))
|
||||
bst <- xgb.Booster(params, append(watchlist, dtrain))
|
||||
for (i in 1:nrounds) {
|
||||
if (is.null(obj)) {
|
||||
succ <- xgb.iter.update(bst, dtrain, i - 1)
|
||||
} else {
|
||||
pred <- xgb.predict(bst, dtrain)
|
||||
gpair <- obj(pred, dtrain)
|
||||
succ <- xgb.iter.boost(bst, dtrain, gpair)
|
||||
}
|
||||
succ <- xgb.iter.update(bst, dtrain, i - 1, obj)
|
||||
if (length(watchlist) != 0) {
|
||||
if (is.null(feval)) {
|
||||
msg <- xgb.iter.eval(bst, watchlist, i - 1)
|
||||
cat(msg)
|
||||
cat("\n")
|
||||
} else {
|
||||
cat("[")
|
||||
cat(i)
|
||||
cat("]")
|
||||
for (j in 1:length(watchlist)) {
|
||||
w <- watchlist[j]
|
||||
if (length(names(w)) == 0) {
|
||||
stop("xgb.eval: name tag must be presented for every elements in watchlist")
|
||||
}
|
||||
ret <- feval(xgb.predict(bst, w[[1]]), w[[1]])
|
||||
cat("\t")
|
||||
cat(names(w))
|
||||
cat("-")
|
||||
cat(ret$metric)
|
||||
cat(":")
|
||||
cat(ret$value)
|
||||
}
|
||||
cat("\n")
|
||||
}
|
||||
msg <- xgb.iter.eval(bst, watchlist, i - 1, feval)
|
||||
cat(paste(msg, "\n", sep=""))
|
||||
}
|
||||
}
|
||||
return(bst)
|
||||
|
||||
Reference in New Issue
Block a user