Skip to main content

Module splitters

Module splitters 

Source
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§

GroupKFold
Group K-fold cross-validation.
KFold
Plain K-fold cross-validation.
LeaveOneOut
Leave-one-out cross-validation (LOO).
RepeatedKFold
Repeated plain K-fold.
RepeatedStratifiedKFold
Repeated stratified K-fold.
ShuffleSplit
Random-permutation cross-validation.
StratifiedGroupKFold
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.
StratifiedKFold
Stratified K-fold cross-validation.
StratifiedShuffleSplit
Stratified random-permutation cross-validation.
TimeSeriesSplit
Time-series cross-validation (rolling-origin evaluation).

Enums§

SubsetSize
How to size a train or test subset: an absolute count or a fraction of the dataset.

Traits§

CvSplitter
A cross-validation splitting strategy.