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

Add repeats argument (#327) #330

Merged
merged 3 commits into from
Jul 2, 2022
Merged

Add repeats argument (#327) #330

merged 3 commits into from
Jul 2, 2022

Conversation

mikemahoney218
Copy link
Member

I accidentally pushed this to main 🤦 I reverted immediately (git reset --soft HEAD~1 && git push -f) and believe things are fine, but sorry about that.

That said! This PR fixes #327 by:

  • Adding a repeats argument to group_vfold_cv()
  • Adding an error to both group_vfold_cv() and vfold_cv() when repeats is used with v == max_v
library(rsample)

vfold_cv(mtcars, v = 2, repeats = 2)
#> #  2-fold cross-validation repeated 2 times 
#> # A tibble: 4 × 3
#>   splits          id      id2  
#>   <list>          <chr>   <chr>
#> 1 <split [16/16]> Repeat1 Fold1
#> 2 <split [16/16]> Repeat1 Fold2
#> 3 <split [16/16]> Repeat2 Fold1
#> 4 <split [16/16]> Repeat2 Fold2
vfold_cv(mtcars, v = nrow(mtcars), repeats = 2)
#> Error in `vfold_cv()`:
#> ! Repeated resampling when `v` is 32 would create identical resamples

group_vfold_cv(mtcars, cyl, v = 2, repeats = 2)
#> # Group 2-fold cross-validation 
#> # A tibble: 4 × 3
#>   splits          id      id2      
#>   <list>          <chr>   <chr>    
#> 1 <split [11/21]> Repeat1 Resample1
#> 2 <split [21/11]> Repeat1 Resample2
#> 3 <split [14/18]> Repeat2 Resample1
#> 4 <split [18/14]> Repeat2 Resample2
group_vfold_cv(mtcars, cyl, v = length(unique(mtcars$cyl)), repeats = 2)
#> Error in `group_vfold_cv()`:
#> ! Repeated resampling when `v` is 3 would create identical resamples
group_vfold_cv(mtcars, cyl, v = NULL, repeats = 2)
#> Error in `group_vfold_cv()`:
#> ! Repeated resampling when `v` is `NULL` would create identical resamples

Created on 2022-07-01 by the reprex package (v2.0.1)

@mikemahoney218 mikemahoney218 marked this pull request as ready for review July 1, 2022 19:13
Copy link
Member

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙌

@juliasilge juliasilge merged commit 9ccae02 into main Jul 2, 2022
@juliasilge juliasilge deleted the mike/327 branch July 2, 2022 16:13
@github-actions
Copy link

This pull request 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 Jul 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

group_vfold_cv() should have a repeats argument
2 participants