Skip to main content

Crate solow_cv

Crate solow_cv 

Source
Expand description

§solow-cv

Cross-validation, resampling, and bootstrap for the Solow statistical stack.

The crate provides three composable layers:

  1. Splitters — KFold, StratifiedKFold, TimeSeriesSplit, LeaveOneOut, and ShuffleSplit behind the shared Splitter trait. Every splitter emits validated Vec<Split> fold lists that a caller can iterate, index, or run in parallel.

  2. Cross-validated scoring — cross_val_score runs a fit_and_score callback across every fold and returns the per-fold scores with mean, unbiased standard deviation, and standard error.

  3. Bootstrap confidence intervals — bootstrap_ci resamples with replacement and returns a percentile, reverse-percentile (“basic”), or Efron BCa confidence interval for any scalar statistic of a sample.

use ndarray::array;
use solow_cv::{KFold, Splitter};

let y = array![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0];
let kf = KFold::new(5)?.shuffle(false);
for split in kf.split(y.len())? {
    let (train, test) = (split.train, split.test);
    assert_eq!(train.len() + test.len(), y.len());
    // Fit on `y.select(Axis(0), &train)`; score on the test rows.
}

§Determinism

Random splits and bootstrap resamples use a well-tested 64-bit linear-congruential generator (Numerical Recipes’ MMIX constants), seeded by the caller. The stream is bit-for-bit portable across platforms; a fixed seed always produces the same folds and replicates.

Modules§

prelude
Commonly used imports.

Structs§

BootstrapCi
A point estimate together with its bootstrap confidence interval.
CombinatorialPurgedKFold
Combinatorial Purged K-Fold cross-validation with an optional embargo.
CrossValScores
Per-fold scores plus their summary.
GroupKFold
Group-aware K-fold cross-validation.
GroupShuffleSplit
GroupShuffleSplit — train/test split at the group level.
KFold
K-fold cross-validator with n_splits equal-sized folds.
LeaveOneOut
Leave-one-out cross-validation.
LeavePOut
Leave-P-Out cross-validation. Emits C(n, p) folds; use with care on large samples.
PurgedKFold
K-fold time-series splitter with a purge band and an optional embargo.
RepeatedKFold
Repeated K-Fold cross-validation.
RepeatedStratifiedKFold
Repeated Stratified K-Fold.
ShuffleSplit
Repeated random train / test splits at a chosen test fraction.
Split
One train / test fold. Indices are sample positions (0..n) that a caller hands to ndarray::select or a slice-based indexing helper.
StratifiedGroupKFold
Group-aware, class-stratified K-fold.
StratifiedKFold
K-fold cross-validator that preserves the per-class label distribution in every fold.
StratifiedShuffleSplit
StratifiedShuffleSplit.
TimeSeriesSplit
Expanding-window walk-forward validation for time series.

Enums§

BootstrapMethod
Bootstrap confidence-interval method.

Traits§

Splitter
Every splitter produces a validated list of folds.

Functions§

bootstrap_ci
Compute a bootstrap confidence interval for statistic(indices) on a sample of size n.
circular_block_bootstrap_indices
Circular block bootstrap — wraps blocks around the end of the sample.
cross_val_score
Run fit_and_score on every fold a splitter produces and collect the per-fold scores.
cross_val_score_from_folds
Variant of cross_val_score that takes a pre-computed list of folds directly — useful when the caller wants to share the same folds between multiple scoring passes (e.g. hyperparameter sweeps).
cross_val_score_parallel
Parallel counterpart of cross_val_score — evaluates every fold on a rayon thread pool and returns the scores in fold order.
learning_curve
Learning-curve evaluator — score at increasing training-set sizes.
moving_block_bootstrap_indices
Moving-block bootstrap indices — a resample of length n built from ⌈n / block_len⌉ overlapping blocks of length block_len.
permutation_test_score
Permutation-test-score — significance test for a cross-validated score.
stationary_bootstrap_indices
Stationary bootstrap — Politis-Romano (1994) — block lengths drawn from Geom(p) where p = 1 / expected_block_len.
validation_curve
Validation-curve evaluator — score at increasing values of a hyper-parameter.