r descr_models("gen_additive_mod", "mgcv")

Tuning Parameters

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:

param$item

Translation from parsnip to the original package (regression)

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)

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:

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.

However, when using a workflow, the best approach is to avoid using [workflows::add_formula()] and use [workflows::add_variables()] in conjunction with a model formula:

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

workflow() %>% 
  add_variables(outcomes = c(mpg), predictors = c(wt, gear, cyl, disp)) %>% 
  add_model(spec, formula = mpg ~ wt + gear + cyl + s(disp, k = 10)) %>% 
  fit(data = mtcars) %>% 
  extract_fit_engine()

The reason for this is that [workflows::add_formula()] will try to create the model matrix and fail to find/use s().

Preprocessing requirements


Case weights


Saving fitted model objects


References



Try the parsnip package in your browser

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

parsnip documentation built on Aug. 18, 2023, 1:07 a.m.