tidymodels / tune

Tools for tidy parameter tuning
https://tune.tidymodels.org
Other
275 stars 42 forks source link

better error when passing a preprocessor with a workflow #912

Open topepo opened 3 months ago

topepo commented 3 months ago

In the code below, the tune_grid function takes a workflow and (inappropriately) a recipe. The code interprets the recipe as going to the ... and issues an unhelpful warning.

We should see if the ... contain any of the preprocessor classes and give a better error

library(tidymodels)

set.seed(6735)
folds <- vfold_cv(mtcars, v = 5)

spline_rec <-
  recipe(mpg ~ ., data = mtcars) %>%
  step_spline_natural(disp, deg_free = tune("disp")) %>%
  step_spline_natural(wt, deg_free = tune("wt"))

lin_mod <-
  linear_reg() %>%
  set_engine("lm")

spline_wflow <- workflow(spline_rec, lin_mod)

spline_grid <- expand.grid(disp = 2:5, wt = 2:5)

spline_res <-
  spline_wflow %>% 
  tune_grid(spline_rec, resamples = folds, grid = spline_grid)
#> Warning: The `...` are not used in this function but one or more objects were
#> passed: ''

Created on 2024-06-24 with reprex v2.1.0

This is probably also true of the other tune functions as well as those in finetune (tidymodels/finetune#114).

simonpcouch commented 3 months ago

Related/duplicate of https://github.com/tidymodels/tune/issues/829!