Closed
Description
The current implementation of gen_additive_mod
disables fit_xy
due to the "mgcv" engine's use of formulas to specify smooths. I think this restriction is too mgcv
specific, and may cause issues for other engines which specify smooths outside of the formula. Ideally, fit_xy
could be disabled when engine = "mgcv"
, and enabled otherwise.
As an example, I am currently working on a package, wand
, which allows users to specify smooths outside of a formula (example follows). I've currently got it running as its own model, nn_additive_mod
, to work around the fit_xy
restriction, but I think it would be a good candidate engine for gen_additive_mod
.
# install.packages("pak")
# pak::pak("ben-e/wand")
library(wand)
library(modeldata)
library(parsnip)
library(recipes)
library(workflows)
data(bivariate)
# Using a workflow
wand_recipe <- recipe(Class ~ A + B, data = bivariate_train)
wand_recipe <- step_log(wand_recipe, all_numeric_predictors())
wand_spec <- nn_additive_mod(engine = "wand",
mode = "classification",
# Smooths are specified within a list, note that
# `B` here has already been log-transformed by
# the recipe.
smooth_specs = list(s_mlp(B)))
wand_wf <- workflow(preprocessor = wand_recipe, spec = wand_spec)
wand_fit <- fit(wand_wf, data = bivariate_train)
# Using a formula
wand_spec <- nn_additive_mod(engine = "wand",
mode = "regression",
# Rather than log-transforming with a recipe we
# can just do it in the smooth spec.
# If we want to specify the A ~ log(B) in the
# fit formula, then the smooth needs to be
# specified as s_mlp(`log(B)`).
smooth_specs = list(s_mlp(log(B))))
wand_fit <- fit(wand_spec,
A ~ B,
data = bivariate_train)
# This unfortunately does not translate well because nn_additive_mod is using
# the fit_xy interface which translates the formula to a dataframe prior to
# calling wand.
# As such, the fit formula can't accept something like A ~ s_mlp(log(B)),
# unlike gen_additive_mod which can accept a formula like `A ~ s(log(B))`
# In this case I'd just recommend users use wand directly:
# wand(A ~ s_mlp(log(B)))
I'd love to hear what ya'll think, thank you!
Ben