GLM with Elastic Net Regularization Regression Learner
Source:R/LearnerRegrCVGlmnet.R
mlr_learners_regr.cv_glmnet.Rd
Generalized linear models with elastic net regularization.
Calls glmnet::cv.glmnet()
from package glmnet.
The default for hyperparameter family
is set to "gaussian"
.
Dictionary
This mlr3::Learner can be instantiated via the dictionary mlr3::mlr_learners or with the associated sugar function mlr3::lrn()
:
Meta Information
Task type: “regr”
Predict Types: “response”
Feature Types: “logical”, “integer”, “numeric”
Required Packages: mlr3, mlr3learners, glmnet
Parameters
Id | Type | Default | Levels | Range |
alignment | character | lambda | lambda, fraction | - |
alpha | numeric | 1 | \([0, 1]\) | |
big | numeric | 9.9e+35 | \((-\infty, \infty)\) | |
devmax | numeric | 0.999 | \([0, 1]\) | |
dfmax | integer | - | \([0, \infty)\) | |
eps | numeric | 1e-06 | \([0, 1]\) | |
epsnr | numeric | 1e-08 | \([0, 1]\) | |
exclude | integer | - | \([1, \infty)\) | |
exmx | numeric | 250 | \((-\infty, \infty)\) | |
family | character | gaussian | gaussian, poisson | - |
fdev | numeric | 1e-05 | \([0, 1]\) | |
foldid | untyped | NULL | - | |
gamma | untyped | - | - | |
grouped | logical | TRUE | TRUE, FALSE | - |
intercept | logical | TRUE | TRUE, FALSE | - |
keep | logical | FALSE | TRUE, FALSE | - |
lambda | untyped | - | - | |
lambda.min.ratio | numeric | - | \([0, 1]\) | |
lower.limits | untyped | - | - | |
maxit | integer | 100000 | \([1, \infty)\) | |
mnlam | integer | 5 | \([1, \infty)\) | |
mxit | integer | 100 | \([1, \infty)\) | |
mxitnr | integer | 25 | \([1, \infty)\) | |
nfolds | integer | 10 | \([3, \infty)\) | |
nlambda | integer | 100 | \([1, \infty)\) | |
offset | untyped | NULL | - | |
parallel | logical | FALSE | TRUE, FALSE | - |
penalty.factor | untyped | - | - | |
pmax | integer | - | \([0, \infty)\) | |
pmin | numeric | 1e-09 | \([0, 1]\) | |
prec | numeric | 1e-10 | \((-\infty, \infty)\) | |
predict.gamma | numeric | gamma.1se | \((-\infty, \infty)\) | |
relax | logical | FALSE | TRUE, FALSE | - |
s | numeric | lambda.1se | \([0, \infty)\) | |
standardize | logical | TRUE | TRUE, FALSE | - |
standardize.response | logical | FALSE | TRUE, FALSE | - |
thresh | numeric | 1e-07 | \([0, \infty)\) | |
trace.it | integer | 0 | \([0, 1]\) | |
type.gaussian | character | - | covariance, naive | - |
type.logistic | character | - | Newton, modified.Newton | - |
type.measure | character | deviance | deviance, class, auc, mse, mae | - |
type.multinomial | character | - | ungrouped, grouped | - |
upper.limits | untyped | - | - |
References
Friedman J, Hastie T, Tibshirani R (2010). “Regularization Paths for Generalized Linear Models via Coordinate Descent.” Journal of Statistical Software, 33(1), 1–22. doi:10.18637/jss.v033.i01 .
See also
Chapter in the mlr3book: https://mlr3book.mlr-org.com/chapters/chapter2/data_and_basic_modeling.html#sec-learners
Package mlr3extralearners for more learners.
as.data.table(mlr_learners)
for a table of available Learners in the running session (depending on the loaded packages).mlr3pipelines to combine learners with pre- and postprocessing steps.
Extension packages for additional task types:
mlr3proba for probabilistic supervised regression and survival analysis.
mlr3cluster for unsupervised clustering.
mlr3tuning for tuning of hyperparameters, mlr3tuningspaces for established default tuning spaces.
Other Learner:
mlr_learners_classif.cv_glmnet
,
mlr_learners_classif.glmnet
,
mlr_learners_classif.kknn
,
mlr_learners_classif.lda
,
mlr_learners_classif.log_reg
,
mlr_learners_classif.multinom
,
mlr_learners_classif.naive_bayes
,
mlr_learners_classif.nnet
,
mlr_learners_classif.qda
,
mlr_learners_classif.ranger
,
mlr_learners_classif.svm
,
mlr_learners_classif.xgboost
,
mlr_learners_regr.glmnet
,
mlr_learners_regr.kknn
,
mlr_learners_regr.km
,
mlr_learners_regr.lm
,
mlr_learners_regr.nnet
,
mlr_learners_regr.ranger
,
mlr_learners_regr.svm
,
mlr_learners_regr.xgboost
Super classes
mlr3::Learner
-> mlr3::LearnerRegr
-> LearnerRegrCVGlmnet
Methods
Method selected_features()
Returns the set of selected features as reported by glmnet::predict.glmnet()
with type
set to "nonzero"
.
Arguments
lambda
(
numeric(1)
)
Customlambda
, defaults to the active lambda depending on parameter set.
Returns
(character()
) of feature names.
Examples
if (requireNamespace("glmnet", quietly = TRUE)) {
# Define the Learner and set parameter values
learner = lrn("regr.cv_glmnet")
print(learner)
# Define a Task
task = tsk("mtcars")
# Create train and test set
ids = partition(task)
# Train the learner on the training ids
learner$train(task, row_ids = ids$train)
# print the model
print(learner$model)
# importance method
if("importance" %in% learner$properties) print(learner$importance)
# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)
# Score the predictions
predictions$score()
}
#> <LearnerRegrCVGlmnet:regr.cv_glmnet>: GLM with Elastic Net Regularization
#> * Model: -
#> * Parameters: family=gaussian
#> * Packages: mlr3, mlr3learners, glmnet
#> * Predict Types: [response]
#> * Feature Types: logical, integer, numeric
#> * Properties: selected_features, weights
#> Warning: Option grouped=FALSE enforced in cv.glmnet, since < 3 observations per fold
#>
#> Call: (if (cv) glmnet::cv.glmnet else glmnet::glmnet)(x = data, y = target, family = "gaussian")
#>
#> Measure: Mean-Squared Error
#>
#> Lambda Index Measure SE Nonzero
#> min 0.536 24 7.725 4.015 6
#> 1se 1.797 11 11.052 6.556 4
#> regr.mse
#> 19.12881