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

split_to_rset() uses randomness when it doesn't need to #264

Closed
DavisVaughan opened this issue Aug 18, 2020 · 1 comment · Fixed by #273
Closed

split_to_rset() uses randomness when it doesn't need to #264

DavisVaughan opened this issue Aug 18, 2020 · 1 comment · Fixed by #273
Labels
bug an unexpected problem or unintended behavior feature a feature request or enhancement

Comments

@DavisVaughan
Copy link
Member

Extracted from #11 (comment), because I now believe this is a separate standalone issue.

split_to_rset() calls rsample::mc_cv() just to get the structure of that rset subclass, but then we override the results with x. HOWEVER, it relies on randomness to generate the object that we overwrite. This causes some confusion with reproducibility between last_fit() and direct usage of fit()/predict().

> tune:::split_to_rset
function (x) 
{
    prop <- length(x$in_id)/nrow(x$data)
    res <- rsample::mc_cv(x$data, times = 1, prop = prop)
    res$splits[[1]] <- x
    res
}

Since we really just need to generate the structure the rset object, we should consider using the below rewrite instead. It is still suboptimal because it hardcodes the structure of an mc_cv rset, but I can live with that.

# Manually construct an `mc_cv()` rset.
# Don't call `mc_cv()` directly, as that will mess with the random seed
split_to_rset <- function(x) {
  times <- 1L
  prop <- length(x$in_id) / nrow(x$data)
  strata <- FALSE
  
  attrib <- list(prop = prop, times = times, strata = strata)
  
  splits <- list(x)
  
  ids <- "Resample1"
  
  rsample::new_rset(
    splits = list(x), 
    ids = ids,
    attrib = attrib,
    subclass = c("mc_cv", "rset")
  )
}
@juliasilge juliasilge added bug an unexpected problem or unintended behavior feature a feature request or enhancement labels Aug 18, 2020
@github-actions
Copy link

github-actions bot commented Mar 6, 2021

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 Mar 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants