Skip to contents

A wrapper for glmnet::glmnet() for use in nadir::super_learner().

Usage

lnr_glmnet(data, formula, weights = NULL, lambda = 0.2, ...)

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

glmnet predictions will by default, if lambda is unspecified, return a matrix of predictions for varied lambda values, hence the need to explicitly handle the lambda argument in building glmnet learners.

See also

learners

Examples

lnr_glmnet(mtcars, mpg ~ hp + disp + am + wt, lambda = .5)(mtcars)
#>  [1] 23.65983 22.88221 25.08887 20.77045 18.11832 20.17456 15.60465 22.29851
#>  [9] 21.42236 19.69112 19.69112 16.04590 17.08273 16.93025 11.69132 10.85825
#> [17] 10.64547 26.27146 28.47886 27.41477 23.45078 18.63051 18.88972 14.78128
#> [25] 16.88327 27.07958 25.69827 26.94490 17.32470 21.23641 13.95742 23.20216