powered by
Returns a vector of fold IDs that preserves class proportions.
stratify_folds(y, nfolds = 10, seed = NULL)
Numeric vector with the same length as y.
y
Numeric vector for the (binomial) response variable.
Number of folds (default: 10).
An integer that is used as argument by set.seed() for offsetting the random number generator. Default is to not set a particular randomization seed.
set.seed()
y <- rbinom(100, 1, 0.3) foldids <- stratify_folds(y, nfolds = 5) table(y, foldids)
Run the code above in your browser using DataLab