Learn R Programming

mlr3learners (version 0.5.1)

mlr_learners_classif.glmnet: GLM with Elastic Net Regularization Classification Learner

Description

Generalized linear models with elastic net regularization. Calls glmnet::glmnet() from package glmnet.

Arguments

Dictionary

This Learner can be instantiated via the dictionary mlr_learners or with the associated sugar function lrn():

mlr_learners$get("classif.glmnet")
lrn("classif.glmnet")

Meta Information

  • Task type: “classif”

  • Predict Types: “response”, “prob”

  • Feature Types: “logical”, “integer”, “numeric”

  • Required Packages: mlr3, mlr3learners, glmnet

Parameters

Id Type Default Levels Range
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]\)
exact logical FALSE TRUE, FALSE -
exclude integer - \([1, \infty)\)
exmx numeric 250 \((-\infty, \infty)\)
fdev numeric 1e-05 \([0, 1]\)
gamma numeric 1 \((-\infty, \infty)\)
intercept logical TRUE TRUE, FALSE -
lambda list - -
lambda.min.ratio numeric - \([0, 1]\)
lower.limits list - -
maxit integer 100000 \([1, \infty)\)
mnlam integer 5 \([1, \infty)\)
mxit integer 100 \([1, \infty)\)
mxitnr integer 25 \([1, \infty)\)
nlambda integer 100 \([1, \infty)\)
newoffset list - -
offset list NULL -
penalty.factor list - -
pmax integer - \([0, \infty)\)
pmin numeric 1e-09 \([0, 1]\)
prec numeric 1e-10 \((-\infty, \infty)\)
relax logical FALSE TRUE, FALSE -
s numeric 0.01 \([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.multinomial character - ungrouped, grouped -
upper.limits list - -

Internal Encoding

Starting with mlr3 v0.5.0, the order of class labels is reversed prior to model fitting to comply to the stats::glm() convention that the negative class is provided as the first factor level.

Super classes

mlr3::Learner -> mlr3::LearnerClassif -> LearnerClassifGlmnet

Methods

Public methods

Method new()

Creates a new instance of this R6 class.

Usage

LearnerClassifGlmnet$new()

Method selected_features()

Returns the set of selected features as reported by glmnet::predict.glmnet() with type set to "nonzero".

Usage

LearnerClassifGlmnet$selected_features(lambda = NULL)

Arguments

lambda

(numeric(1)) Custom lambda, defaults to the active lambda depending on parameter set.

Returns

(character()) of feature names.

Method clone()

The objects of this class are cloneable with this method.

Usage

LearnerClassifGlmnet$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

Caution: This learner is different to learners calling glmnet::cv.glmnet() in that it does not use the internal optimization of parameter lambda. Instead, lambda needs to be tuned by the user (e.g., via mlr3tuning). When lambda is tuned, the glmnet will be trained for each tuning iteration. While fitting the whole path of lambdas would be more efficient, as is done by default in glmnet::glmnet(), tuning/selecting the parameter at prediction time (using parameter s) is currently not supported in mlr3 (at least not in efficient manner). Tuning the s parameter is, therefore, currently discouraged.

When the data are i.i.d. and efficiency is key, we recommend using the respective auto-tuning counterparts in mlr_learners_classif.cv_glmnet(), mlr_learners_regr.cv_glmnet(), or mlr_learners_surv.cv_glmnet(). However, in some situations this is not applicable, usually when data are imbalanced or not i.i.d. (longitudinal, time-series) and tuning requires custom resampling strategies (blocked design, stratification).

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. 10.18637/jss.v033.i01.

See Also

  • Chapter in the mlr3book: https://mlr3book.mlr-org.com/basics.html#learners

  • Package mlr3extralearners for more learners.

  • Dictionary of Learners: mlr_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.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.cv_glmnet, mlr_learners_regr.glmnet, mlr_learners_regr.kknn, mlr_learners_regr.km, mlr_learners_regr.lm, mlr_learners_regr.ranger, mlr_learners_regr.svm, mlr_learners_regr.xgboost, mlr_learners_surv.cv_glmnet, mlr_learners_surv.glmnet, mlr_learners_surv.ranger, mlr_learners_surv.xgboost

Examples

Run this code
# NOT RUN {
if (requireNamespace("glmnet", quietly = TRUE)) {
  learner = mlr3::lrn("classif.glmnet")
  print(learner)

  # available parameters:
learner$param_set$ids()
}
# }

Run the code above in your browser using DataLab