A wrapper for glmnet::cv.glmnet() for use in nadir::super_learner().
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 grid for the penalty; see
?glmnet::cv.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
The returning prediction function defaults to passing s = "lambda.min"
to the predict.cv.glmnet method built into glmnet defaults to
predicting which says to use the minimum cross-validated loss lambda value
from the CV grid
cv.glmnet sets up. The other option is to pass s = "lambda.1se" to the
returned prediction function which
returns the largest lambda estimated to be within one standard deviation of the
CV-optimal lambda according to the stored cv.glmnet object.
Examples
lnr_cvglmnet(mtcars, mpg ~ hp + disp + am + wt)(mtcars)
#> [1] 24.33814 23.59874 25.83145 20.64185 17.60571 20.11482 14.66166 22.47464
#> [9] 21.38042 19.51270 19.51270 15.59561 16.58147 16.43649 11.25729 10.38604
#> [17] 10.06501 27.16957 29.37924 28.26458 23.29328 18.29057 18.53703 13.87878
#> [25] 16.43138 27.93795 26.42672 27.43795 17.09574 21.51946 13.33214 23.91088
