pub fn nested_cross_validate<OS, IS, P, Tune, Fit, M>(
outer: &OS,
inner: &IS,
x: &Array2<f64>,
y: &Array1<f64>,
tune_fn: Tune,
fit_fn: Fit,
scorer: &(dyn Scorer + Sync),
) -> Result<NestedCvResults<P>>Expand description
Run nested cross-validation.
For each outer fold:
tune_fnreceives the outer-training data and theinnersplitter, runs whatever hyperparameter search it likes (grid,tpe, …) using its own inner-CV loop, and returns the best hyperparametersP.fit_fnrefits a final model with those hyperparameters on the full outer-training portion.- that model is scored once on the untouched outer-test portion.
The inner loop never sees the outer-test data, so the outer scores carry none
of the optimistic bias that tuning-and-evaluating on the same data produces.
tune_fn is kept agnostic to how tuning happens, so this composes with any
search approach rather than reimplementing one.
With the parallel feature the outer folds run concurrently over rayon.
§Errors
Propagates any error from outer.split(x.nrows()).