mlr_learners_regr.glm: Generalized Linear Regression

mlr_learners_regr.glmR Documentation

Generalized Linear Regression

Description

Generalized linear model. Calls stats::glm() from base package 'stats'. For logistic regression please use mlr_learners_classif.log_reg.

Dictionary

This Learner can be instantiated via lrn():

lrn("regr.glm")

Meta Information

  • Task type: “regr”

  • Predict Types: “response”, “se”

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

  • Required Packages: mlr3, mlr3extralearners, 'stats'

Parameters

Id Type Default Levels Range
singular.ok logical TRUE TRUE, FALSE -
x logical FALSE TRUE, FALSE -
y logical TRUE TRUE, FALSE -
model logical TRUE TRUE, FALSE -
etastart untyped - -
mustart untyped - -
start untyped NULL -
family character gaussian gaussian, poisson, quasipoisson, Gamma, inverse.gaussian -
na.action character - na.omit, na.pass, na.fail, na.exclude -
link character - logit, probit, cauchit, cloglog, identity, log, sqrt, 1/mu^2, inverse -
epsilon numeric 1e-08 (-\infty, \infty)
maxit numeric 25 (-\infty, \infty)
trace logical FALSE TRUE, FALSE -
dispersion untyped NULL -
type character link response, link, terms -
use_pred_offset logical TRUE TRUE, FALSE -

Initial parameter values

  • type

    • Actual default: "link"

    • Adjusted default: "response"

    • Reason for change: Response scale more natural for predictions.

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.

Super classes

mlr3::Learner -> mlr3::LearnerRegr -> LearnerRegrGlm

Methods

Public methods

Inherited methods

Method new()

Creates a new instance of this R6 class.

Usage
LearnerRegrGlm$new()

Method clone()

The objects of this class are cloneable with this method.

Usage
LearnerRegrGlm$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Author(s)

salauer

References

Hosmer Jr, W D, Lemeshow, Stanley, Sturdivant, X R (2013). Applied logistic regression, volume 398. John Wiley & Sons.

See Also

Examples


# Define the Learner
learner = mlr3::lrn("regr.glm")
print(learner)

# Define a Task
task = mlr3::tsk("mtcars")

# Create train and test set
ids = mlr3::partition(task)

# Train the learner on the training ids
learner$train(task, row_ids = ids$train)

print(learner$model)


# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)

# Score the predictions
predictions$score()


mlr-org/mlr3extralearners documentation built on June 11, 2025, 7:06 p.m.