Skip to contents

Generalized additive models. Calls mgcv::gam from package mgcv.

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 gam 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.

Calls mgcv::gam from package mgcv.

Dictionary

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

mlr_learners$get("regr.gam")
lrn("regr.gam")

Meta Information

  • Task type: “regr”

  • Predict Types: “response”, “se”

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

  • Required Packages: mlr3extralearners, mgcv

Parameters

IdTypeDefaultLevelsRange
familycharactergaussiangaussian, poisson\((-\infty, \infty)\)
formulalist-\((-\infty, \infty)\)
offsetlistNULL\((-\infty, \infty)\)
methodcharacterGCV.CpGCV.Cp, GACV.Cp, REML, P-REML, ML, P-ML\((-\infty, \infty)\)
optimizerlistouter , newton\((-\infty, \infty)\)
scalenumeric0\((-\infty, \infty)\)
selectlogicalFALSETRUE, FALSE\((-\infty, \infty)\)
knotslistNULL\((-\infty, \infty)\)
splistNULL\((-\infty, \infty)\)
min.splistNULL\((-\infty, \infty)\)
HlistNULL\((-\infty, \infty)\)
gammanumeric1\([1, \infty)\)
paraPenlistNULL\((-\infty, \infty)\)
GlistNULL\((-\infty, \infty)\)
in.outlistNULL\((-\infty, \infty)\)
drop.unused.levelslogicalTRUETRUE, FALSE\((-\infty, \infty)\)
drop.interceptlogicalFALSETRUE, FALSE\((-\infty, \infty)\)
nthreadsinteger1\([1, \infty)\)
irls.regnumeric0\([0, \infty)\)
epsilonnumeric1e-07\([0, \infty)\)
maxitinteger200\((-\infty, \infty)\)
tracelogicalFALSETRUE, FALSE\((-\infty, \infty)\)
mgcv.tolnumeric1e-07\([0, \infty)\)
mgcv.halfinteger15\([0, \infty)\)
rank.tolnumeric1.490116e-08\([0, \infty)\)
nlmlistNULL\((-\infty, \infty)\)
optimlistNULL\((-\infty, \infty)\)
newtonlistNULL\((-\infty, \infty)\)
outerPIstepsinteger0\([0, \infty)\)
idLinksBaseslogicalTRUETRUE, FALSE\((-\infty, \infty)\)
scalePenaltylogicalTRUETRUE, FALSE\((-\infty, \infty)\)
efs.lspmaxinteger15\([0, \infty)\)
efs.tolnumeric0.1\([0, \infty)\)
scale.estcharacterfletcherfletcher, pearson, deviance\((-\infty, \infty)\)
edge.correctlogicalFALSETRUE, FALSE\((-\infty, \infty)\)
block.sizeinteger1000\((-\infty, \infty)\)
unconditionallogicalFALSETRUE, FALSE\((-\infty, \infty)\)

References

Wood, S.N. (2017) Generalized Additive Models: An Introduction with R (2nd edition). Chapman & Hall/ CRC, Boca Raton, Florida

Key Reference on GAMs generally:

Hastie (1993) in Chambers and Hastie (1993) Statistical Models in S. Chapman and Hall.

Hastie and Tibshirani (1990) Generalized Additive Models. Chapman and Hall.

See also

Author

JazzyPierrot

Super classes

mlr3::Learner -> mlr3::LearnerRegr -> LearnerRegrGam

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

LearnerRegrGam$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (requireNamespace("mgcv", quietly = TRUE)) {
  learner = mlr3::lrn("regr.gam")
  print(learner)

  # available parameters:
  learner$param_set$ids()
}
#> <LearnerRegrGam:regr.gam>
#> * Model: -
#> * Parameters: list()
#> * Packages: mlr3, mlr3extralearners, mgcv
#> * Predict Type: response
#> * Feature types: logical, integer, numeric
#> * Properties: weights
#>  [1] "family"             "formula"            "offset"            
#>  [4] "method"             "optimizer"          "scale"             
#>  [7] "select"             "knots"              "sp"                
#> [10] "min.sp"             "H"                  "gamma"             
#> [13] "paraPen"            "G"                  "in.out"            
#> [16] "drop.unused.levels" "drop.intercept"     "nthreads"          
#> [19] "irls.reg"           "epsilon"            "maxit"             
#> [22] "trace"              "mgcv.tol"           "mgcv.half"         
#> [25] "rank.tol"           "nlm"                "optim"             
#> [28] "newton"             "outerPIsteps"       "idLinksBases"      
#> [31] "scalePenalty"       "efs.lspmax"         "efs.tol"           
#> [34] "scale.est"          "edge.correct"       "block.size"        
#> [37] "unconditional"     

# simple example
t = mlr3::tsk("mtcars")
l = mlr3::lrn("regr.gam")
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:
#> 6.86 1.00  total = 10.86 
#> 
#> GCV score: 4.851986