cv_sl: Cross-validated Super Learner

View source: R/cv_sl.R

cv_slR Documentation

Cross-validated Super Learner

Description

Cross-validated Super Learner

Usage

cv_sl(lrnr_sl, eval_fun)

Arguments

lrnr_sl

a Lrnr_sl object specifying the Super Learner. Note that the cv_control argument of Lrnr_sl can be specified to control the inner cross-validation of lrnr_sl, as shown in the example.

eval_fun

the evaluation function, either a loss or risk function, for evaluating the Super Learner's predictions.

Value

A list of containing the following: the table of cross-validated risk estimates of the super learner and the candidate learners used to construct it, and either a matrix of coefficients for the super learner on each fold or a list for the metalearner fit on each fold.

Examples

## Not run: 
data(cpp_imputed)
cpp_task <- sl3_Task$new(
  data = cpp_imputed,
  covariates = c("apgar1", "apgar5", "parity", "gagebrth", "mage"),
  outcome = "haz"
)
glm_lrn <- Lrnr_glm$new()
ranger_lrn <- Lrnr_ranger$new()
lasso_lrn <- Lrnr_glmnet$new()
sl <- Lrnr_sl$new(
  learners = list(glm_lrn, ranger_lrn, lasso_lrn),
  cv_control = list(V = 5),
  verbose = FALSE
)
cv_sl_object <- cv_sl(
  lrnr_sl = sl, eval_fun = loss_squared_error
)

## End(Not run)

tlverse/sl3 documentation built on Nov. 18, 2024, 12:46 a.m.