Skip to contents

Classification via logistic regression. Calls stats::glm() with family set to "binomial".

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.

Initial parameter values

  • model:

    • Actual default: TRUE.

    • Adjusted default: FALSE.

    • Reason for change: Save some memory.

Offset

If a Task has a column with the role offset, it will automatically be used during training. The offset is incorporated through the formula interface to ensure compatibility with stats::glm(). We add it to the model formula as offset(<column_name>) and also include it in the training data. During prediction, the default behavior is to use the offset column from the test set (enabled by use_pred_offset = TRUE). Otherwise, if the user sets use_pred_offset = FALSE, a zero offset is applied, effectively disabling the offset adjustment during prediction.

Dictionary

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

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

Meta Information

  • Task type: “classif”

  • Predict Types: “response”, “prob”

  • Feature Types: “logical”, “integer”, “numeric”, “character”, “factor”, “ordered”

  • Required Packages: mlr3, mlr3learners, 'stats'

Parameters

IdTypeDefaultLevelsRange
dispersionuntypedNULL-
epsilonnumeric1e-08\((-\infty, \infty)\)
etastartuntyped--
maxitnumeric25\((-\infty, \infty)\)
modellogicalTRUETRUE, FALSE-
mustartuntyped--
singular.oklogicalTRUETRUE, FALSE-
startuntypedNULL-
tracelogicalFALSETRUE, FALSE-
xlogicalFALSETRUE, FALSE-
ylogicalTRUETRUE, FALSE-
use_pred_offsetlogicalTRUETRUE, FALSE-

Contrasts

To ensure reproducibility, this learner always uses the default contrasts:

Setting the option "contrasts" does not have any effect. Instead, set the respective hyperparameter or use mlr3pipelines to create dummy features.

See also

Other Learner: mlr_learners_classif.cv_glmnet, mlr_learners_classif.glmnet, mlr_learners_classif.kknn, mlr_learners_classif.lda, 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.nnet, mlr_learners_regr.ranger, mlr_learners_regr.svm, mlr_learners_regr.xgboost

Super classes

mlr3::Learner -> mlr3::LearnerClassif -> LearnerClassifLogReg

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.

Usage


Method clone()

The objects of this class are cloneable with this method.

Usage

LearnerClassifLogReg$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (requireNamespace("stats", quietly = TRUE)) {
# Define the Learner and set parameter values
learner = lrn("classif.log_reg")
print(learner)

# Define a Task
task = tsk("sonar")

# 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()
}
#> 
#> ── <LearnerClassifLogReg> (classif.log_reg): Logistic Regression ───────────────
#> • Model: -
#> • Parameters: use_pred_offset=TRUE
#> • Packages: mlr3, mlr3learners, and stats
#> • Predict Types: [response] and prob
#> • Feature Types: logical, integer, numeric, character, factor, and ordered
#> • Encapsulation: none (fallback: -)
#> • Properties: offset, twoclass, and weights
#> • Other settings: use_weights = 'use'
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> 
#> Call:  stats::glm(formula = form, family = "binomial", data = data, 
#>     model = FALSE)
#> 
#> Coefficients:
#> (Intercept)           V1          V10          V11          V12          V13  
#>    -285.756     -677.894     -138.149     -256.903      518.509      -95.833  
#>         V14          V15          V16          V17          V18          V19  
#>       5.969       88.531     -317.354      127.805       73.806     -146.011  
#>          V2          V20          V21          V22          V23          V24  
#>    1042.352      258.374     -233.810      407.294     -305.507      388.313  
#>         V25          V26          V27          V28          V29           V3  
#>    -295.362      -67.455      220.419      -15.845     -171.077     -592.316  
#>         V30          V31          V32          V33          V34          V35  
#>     366.534     -363.831      176.149      -62.702       89.860       53.869  
#>         V36          V37          V38          V39           V4          V40  
#>    -126.325     -105.908       -4.911      504.074      146.961     -543.467  
#>         V41          V42          V43          V44          V45          V46  
#>     307.564     -245.771       50.703      528.297     -947.786      853.212  
#>         V47          V48          V49           V5          V50          V51  
#>    -368.984     1132.261      582.159       80.766    -4700.025     2208.161  
#>         V52          V53          V54          V55          V56          V57  
#>     682.343     1965.509    -1969.410    -5174.850    -1851.471    -2349.680  
#>         V58          V59           V6          V60           V7           V8  
#>    6718.001     2307.788      135.176     2462.877        4.320      123.704  
#>          V9  
#>     175.307  
#> 
#> Degrees of Freedom: 138 Total (i.e. Null);  78 Residual
#> Null Deviance:	    192.1 
#> Residual Deviance: 8.973e-09 	AIC: 122
#> classif.ce 
#>  0.3043478