Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let collect_predictions() handle unavailable parameters more informatively #765

Open
hfrick opened this issue Nov 21, 2023 · 0 comments
Open
Labels
feature a feature request or enhancement

Comments

@hfrick
Copy link
Member

hfrick commented Nov 21, 2023

If we request the predictions for parameters values that were not used during tuning, we get an empty tibble back. We could error informatively here or at least warn that this is the reason for the empty tibble.

library(tidymodels)

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

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

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

# only whole numbers
spline_grid <- expand.grid(disp = 2:5, wt = 2:5)

spline_res <- tune_grid(lin_mod, spline_rec, resamples = folds, 
                        grid = spline_grid, control = control_grid(save_pred = TRUE))
# this is fine
pred <- collect_predictions(spline_res)

# now with degrees of freedom not part of the tuning
# this should warn or error informatively
collect_predictions(spline_res, parameters = tibble(disp = 1.1, wt = 2.2))
#> # A tibble: 0 × 7
#> # ℹ 7 variables: id <chr>, .pred <dbl>, .row <int>, disp <dbl>, wt <dbl>,
#> #   mpg <dbl>, .config <chr>

Created on 2023-11-21 with reprex v2.0.2

@EmilHvitfeldt EmilHvitfeldt added the feature a feature request or enhancement label Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants