xgb_fit: Fit an xgboost model for each row of a 'resamples' object

View source: R/xgb_fit.R

xgb_fitR Documentation

Fit an xgboost model for each row of a resamples object

Description

Fit an xgboost model for each row of a resamples object

Usage

xgb_fit(object, cores = 1, threads = 1, ...)

## S3 method for class 'resamples'
xgb_fit(object, cores = 1, threads = 1, ...)

## S3 method for class 'resamples_grid'
xgb_fit(object, cores = 1, threads = 1, ...)

Arguments

object

of class resamples (created by a ⁠resample_***()⁠ function) or of class resamples_grid (created by param_grid()).

cores

integer, number of cores to use for parallel computation.

threads

number of threads used to fit each model in parallel. threads cannot be >1 when cores>1. When fitting models over many rather small resamples, parallelising over cores is likely more efficient. When fitting few (sometimes even one) model or when each model is very big, parallelising each fit through threads is likely more efficient.

...

passed to fit_one_xgb() and then later 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
resample_boot(mtcars, 3) %>%
  xgb_fit(resp="mpg", expl=c("cyl", "hp", "qsec"),
    eta=0.1, max_depth=4, nrounds=20)

resample_boot(mtcars, 2) %>%
  param_grid(eta=c(0.1, 0.2)) %>%
  xgb_fit(resp="mpg", expl=c("cyl", "hp", "qsec"),
    max_depth=4, nrounds=20)

# classification
mtcarsf <- mutate(mtcars, cyl=factor(cyl))
resample_boot(mtcarsf, 3) %>%
  xgb_fit(resp="cyl", expl=c("mpg", "hp", "qsec"),
    eta=0.1, max_depth=4, nrounds=20)

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