Creates random, stratified or grouped \(k\)-fold partitions.
Details
Random: observations are randomly permuted and dealt into
kfolds whose sizes differ by at most one.Stratified (
strata): the dealing is done within each stratum, so every fold has approximately the same distribution ofstrata. Numericstratawith more thann_binsdistinct values are first binned at their quantiles, which is useful for regression outcomes.Grouped (
groups): all observations from the same group (e.g. patient, site or time block) are placed in the same fold, preventing leakage between correlated observations. Groups are dealt into folds in decreasing order of size to balance fold sizes.