How to define smoothed models for a GAM using tidymodels and recipe?

You would add a supplementary formula to the workflow via add_model(gam_model, formula = <something>).

For your example, you could do something like:


full_recipe <- recipe(Species ~ Sepal.Length + Sepal.Width,
                      data = iris) |>
  step_normalize(all_numeric()) |>
  step_dummy(country)

<snip>

# Workflow including the model formula, preprocessing and model
gam_workflow <- workflow() |>
  add_recipe(full_recipe) |>
  add_model(gam_model, 
            formula = Species ~ s(Sepal.Length, bs="ps", k=10) + s(Sepal.Width, bs="ps", k=10))

There is more about this in the TMwR book too.

3 Likes