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

Create caret2rsample() via new_rset() #232

Merged
merged 1 commit into from
Apr 8, 2021
Merged

Create caret2rsample() via new_rset() #232

merged 1 commit into from
Apr 8, 2021

Conversation

juliasilge
Copy link
Member

Closes #147

This PR creates the caret2rsample() objects via new_rset(), which means that tuning now works:

library(caret)
#> Loading required package: lattice
#> Loading required package: ggplot2
library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip


cvTrain <- trainControl(method = "cv", number = 5,
                        index = list(Fold1 = 10001:4e4, 
                                     Fold2 = c(1:1e4, 20001:4e4), 
                                     Fold3 = c(1:2e4, 30001:4e4), 
                                     Fold4 = 1:3e4),
                        indexOut = list(Fold1 = 1:1e4, 
                                        Fold2 = 10001:2e4,
                                        Fold3 = 20001:3e4,
                                        Fold4 = 30001:4e4))

diamond_folds <- caret2rsample(cvTrain, diamonds[1:4e4,])
diamond_folds
#> #  5-fold cross-validation using stratification 
#> # A tibble: 4 x 2
#>   splits                id   
#>   <list>                <chr>
#> 1 <split [30000/10000]> Fold1
#> 2 <split [30000/10000]> Fold2
#> 3 <split [30000/10000]> Fold3
#> 4 <split [30000/10000]> Fold4

linear_reg(penalty = tune(), mixture = 1) %>% 
  set_engine("glmnet") %>%
  tune_grid(
    price ~ .,
    resamples = diamond_folds,
    grid = 5
  )
#> # Tuning results
#> # 5-fold cross-validation using stratification 
#> # A tibble: 4 x 4
#>   splits                id    .metrics              .notes              
#>   <list>                <chr> <list>                <list>              
#> 1 <split [30000/10000]> Fold1 <tibble[,5] [10 × 5]> <tibble[,1] [0 × 1]>
#> 2 <split [30000/10000]> Fold2 <tibble[,5] [10 × 5]> <tibble[,1] [0 × 1]>
#> 3 <split [30000/10000]> Fold3 <tibble[,5] [10 × 5]> <tibble[,1] [0 × 1]>
#> 4 <split [30000/10000]> Fold4 <tibble[,5] [10 × 5]> <tibble[,1] [0 × 1]>

Created on 2021-04-07 by the reprex package (v2.0.0)

@juliasilge juliasilge requested a review from hfrick April 8, 2021 01:27
@juliasilge juliasilge merged commit 002e72b into master Apr 8, 2021
juliasilge added a commit that referenced this pull request Apr 8, 2021
@juliasilge juliasilge deleted the fix-caret-bug branch April 8, 2021 14:21
@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 Apr 23, 2021
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.

caret2rsample does not appear to work
2 participants