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

Prevent LOO through vfold_cv() #440

Closed
hfrick opened this issue Jul 12, 2023 · 1 comment · Fixed by #527
Closed

Prevent LOO through vfold_cv() #440

hfrick opened this issue Jul 12, 2023 · 1 comment · Fixed by #527
Labels
feature a feature request or enhancement tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day

Comments

@hfrick
Copy link
Member

hfrick commented Jul 12, 2023

We purposefully don't (fully) support LOO cross-validation in tidymodels: we have loo_cv() in rsample but it's not supported in tune.

However, you can create LOO cross-validation by doing:

vfold_cv(df,  v = nrow(df))

which then does not get caught in tune. Let's make vfold_cv() error for this case, with a reference to loo_cv().

library(tidymodels)

loo_folds <- loo_cv(mtcars)
v_folds <- vfold_cv(mtcars, v = nrow(mtcars))

wflow <- workflow(mpg ~ ., linear_reg())

fit_resamples(wflow, resamples = loo_folds)
#> Error in `check_rset()` at tune/R/tune_grid.R:334:2:
#> ! Leave-one-out cross-validation is not currently supported with tune.

fit_resamples(wflow, resamples = v_folds)
#> → A | warning: A correlation computation is required, but the inputs are size zero or one and the standard deviation cannot be computed. `NA` will be returned.
#> There were issues with some computations   A: x1
#> There were issues with some computations   A: x32
#> 
#> # Resampling results
#> # 32-fold cross-validation 
#> # A tibble: 32 × 4
#>    splits         id     .metrics         .notes          
#>    <list>         <chr>  <list>           <list>          
#>  1 <split [31/1]> Fold01 <tibble [2 × 4]> <tibble [1 × 3]>
#>  2 <split [31/1]> Fold02 <tibble [2 × 4]> <tibble [1 × 3]>
#>  3 <split [31/1]> Fold03 <tibble [2 × 4]> <tibble [1 × 3]>
#>  4 <split [31/1]> Fold04 <tibble [2 × 4]> <tibble [1 × 3]>
#>  5 <split [31/1]> Fold05 <tibble [2 × 4]> <tibble [1 × 3]>
#>  6 <split [31/1]> Fold06 <tibble [2 × 4]> <tibble [1 × 3]>
#>  7 <split [31/1]> Fold07 <tibble [2 × 4]> <tibble [1 × 3]>
#>  8 <split [31/1]> Fold08 <tibble [2 × 4]> <tibble [1 × 3]>
#>  9 <split [31/1]> Fold09 <tibble [2 × 4]> <tibble [1 × 3]>
#> 10 <split [31/1]> Fold10 <tibble [2 × 4]> <tibble [1 × 3]>
#> # ℹ 22 more rows
#> 
#> There were issues with some computations:
#> 
#>   - Warning(s) x32: A correlation computation is required, but the inputs are size ze...
#> 
#> Run `show_notes(.Last.tune.result)` for more information.

Created on 2023-07-12 with reprex v2.0.2

@hfrick hfrick added the feature a feature request or enhancement label Nov 1, 2023
@hfrick hfrick added the tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day label Jul 18, 2024
seb09 added a commit to seb09/rsample that referenced this issue Aug 15, 2024
vfold_cv() throws an error, if used for leave-one-out cross-validation, refering to loo_cv() instead.
Fixes tidymodels#440
Copy link

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant