This convenience function calculates weights proportional to the number of observations in each resample's analysis set. Larger resamples get higher weights. This ensures that resamples with more data have proportionally more influence on the final aggregated metrics.
Details
This is particularly useful for time-based resamples (e.g., expanding window CV) or stratified sampling where resamples might have slightly different sizes, in which resamples are imbalanced.
Examples
library(rsample)
folds <- vfold_cv(mtcars, v = 3)
weights <- calculate_resample_weights(folds)
weighted_folds <- add_resample_weights(folds, weights)