Skip to contents

A wrapper for hal9001::fit_hal() fit jointly over a decreasing grid of lambda values, for use in nadir::super_learner().

Usage

lnr_hal_grid(data, formula, weights = NULL, lambda, ...)

Arguments

data

A dataframe to train a learner / learners on.

formula

A regression formula to use inside this learner.

weights

Observation weights; see ?lm

lambda

A numeric vector of penalty values (a grid). Must be explicitly specified; see validate_lambda_grid for why auto-generated grids are not supported. Values are deduplicated and sorted in decreasing order.

...

Any extra arguments that should be passed to the internal model for model fitting purposes.

Value

A nadir_multi_predictor: a named list of prediction functions, one per lambda value, each of which accepts newdata and returns a numeric vector of predictions.

Details

Like lnr_glmnet_grid, this fits the entire lasso path (over the HAL basis expansion) in a single call and returns a multi-predictor with one prediction function per lambda value, which super_learner() expands into distinct pseudo-learners. Internally fit_hal is called with fit_control = list(cv_select = FALSE) so that the fits at every lambda in the grid are retained rather than one being selected by cv.glmnet.

Since the HAL basis expansion (typically the expensive step at prediction time) is shared across the whole grid, predictions for all lambda values on the same newdata are computed once and cached.

See also

learners lnr_hal lnr_glmnet_grid as_multi_predictor

Examples

# \donttest{
suppressWarnings({
  multi_predictor <- lnr_hal_grid(
    mtcars, mpg ~ hp + wt,
    lambda = c(0.01, 0.1, 1),
    max_degree = 1, num_knots = 3
  )
})
names(multi_predictor)
#> [1] "lambda_1"    "lambda_0.1"  "lambda_0.01"
# }