Skip to contents

A wrapper for hal9001::fit_hal() for use in nadir::super_learner().

Usage

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

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

The multiplier parameter for the penalty; see ?glmnet::glmnet

...

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

Value

A prediction function that accepts newdata, which returns predictions (a numeric vector of values, one for each row of newdata).

Details

If a single lambda value is specified, fit_control$cv_select is set to FALSE, since fit_hal's default (cv_select = TRUE) hands lambda to cv.glmnet, which errors with "Need more than one value of lambda for cv.glmnet" — and inside super_learner() that error would cause lnr_hal to be silently dropped from the ensemble.

If a vector of lambda values is specified (with the default fit_control), the grid is treated as a search space: cv.glmnet internally selects a single lambda, and only that model's predictions are returned. To instead expose each lambda value in a grid to the meta-learning stage of super_learner() as its own candidate learner, use lnr_hal_grid.

See also

learners lnr_hal_grid

Examples

suppressWarnings({
  # hal prints a lot of messages about some threads not reaching convergence
  lnr_hal(mtcars, mpg ~ hp + am + cyl + disp)(mtcars)
})
#>  [1] 22.14994 22.14994 25.99455 17.55512 15.59462 19.83130 13.61723 26.85689
#>  [9] 24.30360 20.68476 20.68476 17.03116 17.03116 17.03116 12.88687 12.88885
#> [17] 12.88247 27.59698 27.71820 27.71820 25.20604 16.89972 17.21881 13.74927
#> [25] 14.82805 27.59219 25.53211 26.05026 15.87732 18.80094 14.44948 24.48803