calculate_resample_weights: Calculate resample weights from resample sizes

View source: R/utils.R

calculate_resample_weightsR Documentation

Calculate resample weights from resample sizes

Description

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.

Usage

calculate_resample_weights(rset)

Arguments

rset

An rset object from rsample.

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.

Value

A numeric vector of weights proportional to resample sizes, normalized to sum to 1.

See Also

add_resample_weights(), extract_resample_weights()

Examples

library(rsample)
folds <- vfold_cv(mtcars, v = 3)
weights <- calculate_resample_weights(folds)
weighted_folds <- add_resample_weights(folds, weights)

tune documentation built on April 17, 2026, 5:07 p.m.