Expand description
Cross-validation splitters.
Every splitter implements the single CvSplitter trait, which yields
(train_indices, test_indices) pairs — indices only, never materialized
data copies, matching scikit-learn’s memory-efficient convention. Callers
apply the indices to their data with ndarray fancy indexing
(ndarray::ArrayBase::select).
§Design note: how label- and group-aware splitters fit one trait
Milestone 1 of the project plan left one question open: should stratified /
group splitters need a separate trait taking y / groups, or can a
single trait serve everything? This crate resolves it in favour of one
trait. Label- and group-aware splitters
(StratifiedKFold, GroupKFold, StratifiedGroupKFold,
StratifiedShuffleSplit, RepeatedStratifiedKFold) take their labels /
groups at construction time and store them, then implement the same
CvSplitter::split as everything else.
The upside is uniformity: cross_validate,
learning_curve and friends accept any
S: CvSplitter with no special cases. The cost is that a stratified splitter
owns a copy of its label array — cheap in practice, since you always have y
in scope when you set up a CV loop, and labels are one small column.
§Fallibility
The plan sketched split as infallible (-> Vec<..>). It is promoted to
-> Result<Vec<..>> here because validation (too few samples, an impossible
time-series window, a label array whose length disagrees with n_samples)
genuinely can fail and a library should surface that rather than panic. The
per-split index math itself never fails once validation passes.
Structs§
- GroupK
Fold - Group K-fold cross-validation.
- KFold
- Plain K-fold cross-validation.
- Leave
OneOut - Leave-one-out cross-validation (LOO).
- RepeatedK
Fold - Repeated plain K-fold.
- Repeated
StratifiedK Fold - Repeated stratified K-fold.
- Shuffle
Split - Random-permutation cross-validation.
- Stratified
GroupK Fold - K-fold that tries to satisfy two constraints at once: keep class proportions balanced across folds and never let a group straddle the train/test boundary.
- StratifiedK
Fold - Stratified K-fold cross-validation.
- Stratified
Shuffle Split - Stratified random-permutation cross-validation.
- Time
Series Split - Time-series cross-validation (rolling-origin evaluation).
Enums§
- Subset
Size - How to size a train or test subset: an absolute count or a fraction of the dataset.
Traits§
- CvSplitter
- A cross-validation splitting strategy.