#| child: aaa.Rmd
#| include: false

r descr_models("gen_additive_mod", "mgcv")

Tuning Parameters

#| label: earth-param-info
#| echo: false
defaults <- 
  tibble::tibble(parsnip = c("select_features", "adjust_deg_free"),
                 default = c("FALSE", "1.0"))

param <-
  gen_additive_mod() |> 
  set_engine("mgcv") |> 
  make_parameter_list(defaults)

This model has r nrow(param) tuning parameters:

#| label: earth-param-list
#| echo: false
#| results: asis
param$item

Translation from parsnip to the original package (regression)

#| label: glm-reg
gen_additive_mod(adjust_deg_free = numeric(1), select_features = logical(1)) |> 
  set_engine("mgcv") |> 
  set_mode("regression") |> 
  translate()

Translation from parsnip to the original package (classification)

#| label: glm-cls
gen_additive_mod(adjust_deg_free = numeric(1), select_features = logical(1)) |> 
  set_engine("mgcv") |> 
  set_mode("classification") |> 
  translate()

Model fitting

This model should be used with a model formula so that smooth terms can be specified. For example:

#| include: false
library(mgcv)
library(mgcv)
gen_additive_mod() |> 
  set_engine("mgcv") |> 
  set_mode("regression") |> 
  fit(mpg ~ wt + gear + cyl + s(disp, k = 10), data = mtcars)

The smoothness of the terms will need to be manually specified (e.g., using s(x, df = 10)) in the formula. Tuning can be accomplished using the adjust_deg_free parameter.

When using a workflow, pass the model formula to [workflows::add_model()]'s formula argument, and a simplified preprocessing formula elsewhere.

spec <- 
  gen_additive_mod() |> 
  set_engine("mgcv") |> 
  set_mode("regression")

workflow() |> 
  add_model(spec, formula = mpg ~ wt + gear + cyl + s(disp, k = 10)) |> 
  add_formula(mpg ~ wt + gear + cyl + disp) |> 
  fit(data = mtcars) |> 
  extract_fit_engine()

To learn more about the differences between these formulas, see [?model_formula][parsnip::model_formula].

Preprocessing requirements

#| child: template-makes-dummies.Rmd

Case weights

#| child: template-uses-case-weights.Rmd

Saving fitted model objects

#| child: template-butcher.Rmd

References



Try the parsnip package in your browser

Any scripts or data that you put into this service are public.

parsnip documentation built on June 8, 2025, 12:10 p.m.