Skip to contents

A multi-predictor is a named list of prediction functions produced by a single call to a learner, e.g. one prediction function per lambda value along a jointly-fit regularization path. super_learner() expands multi-predictors into distinct pseudo-learners (one per element) whose names are formed as paste(learner_name, names(predictors), sep = '_').

Usage

as_multi_predictor(predictors)

Arguments

predictors

A uniquely-named list of functions, each of which accepts newdata and returns a numeric vector of predictions with one entry per row of newdata.

Value

The same list, classed as nadir_multi_predictor.

Details

Learner authors may wrap any algorithm that fits many models in one pass (e.g., a lasso path, a boosting run saved at several iteration counts, etc.) with this to expose each sub-model along the path to the meta-learning stage of super_learner() at the cost of a single fit.

The sub-model names must be identical across calls on different training folds (i.e., deterministic given the learner arguments, not data-dependent), since super_learner() aligns pseudo-learners across folds by name.

See also

lnr_glmnet_grid lnr_hal_grid

Examples

# a custom grid learner returns one fitted predictor per tuning value;
# as_multi_predictor() marks the named collection so super_learner()
# expands it into one candidate learner per sub-model
mp <- as_multi_predictor(list(
  lambda_0.1 = function(newdata) rep(1, nrow(newdata)),
  lambda_1   = function(newdata) rep(2, nrow(newdata))
))
inherits(mp, "nadir_multi_predictor")
#> [1] TRUE
names(mp)
#> [1] "lambda_0.1" "lambda_1"  
mp$lambda_1(mtcars[1:3, ])
#> [1] 2 2 2