Skip to contents

Fast generalized additive models for large datasets. Calls mgcv::bam() from package mgcv. For smaller datasets, use regr.gam instead.

Formula

A gam formula specific to the task at hand is required for the formula parameter (see example and ?mgcv::formula.gam). Beware, if no formula is provided, a fallback formula is used that will make the model behave like a glm (this behavior is required for the unit tests). Only features specified in the formula will be used, superseding columns with col_roles "feature" in the task.

Offset

If a Task contains a column with the offset role, it is automatically incorporated during training via the offset argument in mgcv::bam(). No offset is applied during prediction for this learner.

Custom mlr3 parameters

  • control is passed to mgcv::gam.control() as a list. Unlike regr.gam, the individual control options are not exposed as hyperparameters, because nthreads is both a control option and an argument of mgcv::bam().

  • discrete is a parameter of both mgcv::bam() and mgcv::predict.bam(), with different defaults. Only the training parameter is exposed, and prediction uses the default of mgcv::predict.bam().

  • Only the training parameter nthreads is tagged with "threads", so mlr3::set_threads() does not change the prediction parameter n.threads.

Dictionary

This Learner can be instantiated via lrn():

lrn("regr.bam")

Meta Information

  • Task type: “regr”

  • Predict Types: “response”, “se”

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

  • Required Packages: mlr3, mlr3extralearners, mgcv

Parameters

IdTypeDefaultLevelsRange
formulauntyped--
familycharactergaussiangaussian, poisson-
methodcharacterfREMLfREML, GCV.Cp, GACV.Cp, REML, P-REML, ML, P-ML-
controluntypedlist()-
selectlogicalFALSETRUE, FALSE-
scalenumeric0\((-\infty, \infty)\)
gammanumeric1\([1, \infty)\)
knotsuntypedNULL-
spuntypedNULL-
min.spuntypedNULL-
paraPenuntypedNULL-
chunk.sizeinteger10000\([1, \infty)\)
rhonumeric0\((-\infty, \infty)\)
AR.startuntypedNULL-
discretelogicalFALSETRUE, FALSE-
nthreadsinteger1\([1, \infty)\)
use.chollogicalFALSETRUE, FALSE-
samfracnumeric1\([0, 1]\)
coefuntypedNULL-
drop.unused.levelslogicalTRUETRUE, FALSE-
GuntypedNULL-
drop.interceptlogicalNULLTRUE, FALSE-
in.outuntypedNULL-
neiuntypedNULL-
clusteruntypedNULL-
gc.levelinteger0\([0, \infty)\)
termsuntypedNULL-
excludeuntypedNULL-
block.sizeinteger50000\((-\infty, \infty)\)
n.threadsinteger1\([1, \infty)\)

References

Hastie, J T, Tibshirani, J R (2017). Generalized additive models. Routledge.

Wood, Simon (2012). “mgcv: Mixed GAM Computation Vehicle with GCV/AIC/REML smoothness estimation.”

See also

Author

Tino-Rg

Super classes

mlr3::Learner -> mlr3::LearnerRegr -> LearnerRegrBam

Methods

Inherited methods


LearnerRegrBam$new()

Creates a new instance of this R6 class.

Usage


LearnerRegrBam$clone()

The objects of this class are cloneable with this method.

Usage

LearnerRegrBam$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# simple example
t = tsk("mtcars")
l = lrn("regr.bam")
l$param_set$values$formula = mpg ~ cyl + am + s(disp) + s(hp)
l$train(t)
l$model
#> 
#> Family: gaussian 
#> Link function: identity 
#> 
#> Formula:
#> mpg ~ cyl + am + s(disp) + s(hp)
#> 
#> Estimated degrees of freedom:
#> 5.11 1.00  total = 9.11 
#> 
#> fREML score: 67.84661