Skip to content

Compatibility for resample weights with racing methods#135

Open
tjburch wants to merge 1 commit intotidymodels:mainfrom
tjburch:main
Open

Compatibility for resample weights with racing methods#135
tjburch wants to merge 1 commit intotidymodels:mainfrom
tjburch:main

Conversation

@tjburch
Copy link

@tjburch tjburch commented Feb 19, 2026

Finetune's racing functions (tune_race_anova, tune_race_win_loss) internally slice and reorder rsets using restore_rset() and randomize_resamples(). These all are incompatible against the new resample weights:

library(rsample)

set.seed(1)
folds <- vfold_cv(mtcars, v = 5)
weights <- c(1.0, 2.0, 3.0, 4.0, 5.0)
attr(folds, ".resample_weights") <- weights

# restore_rset: slices rows but leaves weights at original length
sliced <- finetune:::restore_rset(folds, 1:3)
length(attr(sliced, ".resample_weights"))
#> [1] 5 -- should be 3

# randomize_resamples: shuffles rows but weights stay in original order
set.seed(42)
shuffled <- finetune:::randomize_resamples(folds)
identical(attr(shuffled, ".resample_weights"), weights)
#> [1] TRUE

This PR updates racing_helpers.R to correctly handle the sample weights:
restore_rset() now subsets .resample_weights[index] alongside row.names, and randomize_resamples() tracks original row positions to reorder weights after the shuffling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant