fit_one_xgb: Fit an xgboost model to _one_ 'resamples' object

View source: R/fit_one_xgb.R

fit_one_xgbR Documentation

Fit an xgboost model to one resamples object

Description

This is the "workhorse" function called by the different methods of xgb_fit.

Usage

fit_one_xgb(
  object,
  resp,
  expl,
  params = list(),
  nrounds,
  verbose = 0,
  weight = NULL,
  threads = 1,
  ...
)

Arguments

object

of class resamples, created by a ⁠resample_***()⁠ function.

resp

name of the response variable.

expl

names of the explanatory variables.

params

named list of parameters passed to xgboost::xgb.train().

nrounds

number of boosting rounds (i.e. number of trees).

verbose

0 = silent, 1 = display performance, 2 = more verbose.

weight

a vector of observation-level weights, one per line of the training set.

threads

number of paralel threads used to fit each model. This is set to 1 by default to avoid conflict with parallelisation per resample (in xgb_fit()), which is often more efficient. Set this to more than 1 when fitting only one model.

...

other parameters passed to 'xgboost::xgb.Train()“

Value

The input object (a tibble of class resamples) with an additional column called model containing the fitted model object.

Examples

# regression
rs <- resample_identity(mtcars, 1)
m <- fit_one_xgb(object=rs,
  resp="mpg", expl=c("cyl", "hp", "qsec"),
  eta=0.1, max_depth=4,
  nrounds=20
)
m$model

# classification
mtcarsf <- mutate(mtcars, cyl=factor(cyl))
rs <- resample_identity(mtcarsf, 1)
m <- fit_one_xgb(object=rs,
  resp="cyl", expl=c("mpg", "hp", "qsec"),
  eta=0.1, max_depth=4,
  nrounds=20
)
m$model

# parameters can also be passed as a list
m_list <- fit_one_xgb(object=rs,
  resp="cyl", expl=c("mpg", "hp", "qsec"),
  params=list(eta=0.1, max_depth=4),
  nrounds=20
)
m$model[[1]]$params
m_list$model[[1]]$params

jiho/joml documentation built on Dec. 6, 2023, 5:50 a.m.