xgboost (version 0.3-1)

xgb.train: eXtreme Gradient Boosting Training

Description

The training function of xgboost

Usage

xgb.train(params = list(), data, nrounds, watchlist = list(), obj = NULL,
  feval = NULL, verbose = 1, ...)

Arguments

params
the list of parameters. Commonly used ones are:
  • objectiveobjective function, common ones are
    • reg:linearlinear regression
    • binary:logisticlogistic regression for classification
data
takes an xgb.DMatrix as the input.
nrounds
the max number of iterations
watchlist
what information should be printed when verbose=1 or verbose=2. Watchlist is used to specify validation set monitoring during training. For example user can specify watchlist=list(validation1=mat1, validation2=mat2) to wat
obj
customized objective function. Returns gradient and second order gradient with given prediction and dtrain,
feval
custimized evaluation function. Returns list(metric='metric-name', value='metric-value') with given prediction and dtrain,
verbose
If 0, xgboost will stay silent. If 1, xgboost will print information of performance. If 2, xgboost will print information of both
...
other parameters to pass to params.

Details

This is the training function for xgboost.

Parallelization is automatically enabled if OpenMP is present. Number of threads can also be manually specified via "nthread" parameter.

This function only accepts an xgb.DMatrix object as the input. It supports advanced features such as watchlist, customized objective function, therefore it is more flexible than xgboost.

Examples

Run this code
data(agaricus.train, package='xgboost')
dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label)
dtest <- dtrain
watchlist <- list(eval = dtest, train = dtrain)
param <- list(max.depth = 2, eta = 1, silent = 1)
logregobj <- function(preds, dtrain) {
   labels <- getinfo(dtrain, "label")
   preds <- 1/(1 + exp(-preds))
   grad <- preds - labels
   hess <- preds * (1 - preds)
   return(list(grad = grad, hess = hess))
}
evalerror <- function(preds, dtrain) {
  labels <- getinfo(dtrain, "label")
  err <- as.numeric(sum(labels != (preds > 0)))/length(labels)
  return(list(metric = "error", value = err))
}
bst <- xgb.train(param, dtrain, nround = 2, watchlist, logregobj, evalerror)

Run the code above in your browser using DataCamp Workspace