Cross-Validation Visualizer
Watch k-fold validation rotate: split → refit on k−1 folds → predict the held-out fold → score → repeat → aggregate.
A genuine k-fold teaching experiment using a tiny nearest-centroid classifier. Every fold recomputes class centroids from its training subset, validates only on the held-out fold, and contributes one real fold score to the final mean and spread.
Step by step
- Keep a final-test subset outside the cross-validation pool.
- Partition the CV pool into k non-overlapping validation folds, optionally stratified by class.
- For the active fold, fit the two class centroids using only the other k−1 folds.
- Predict each held-out point by the nearest fitted centroid and calculate validation accuracy.
- Rotate the validation role and refit from scratch for every fold.
- Aggregate the k held-out scores into a mean and fold-score standard deviation.
Core formulas
Nearest centroid
ŷ = argminₖ ||x − μₖ||²The tiny teaching classifier predicts the class whose training centroid is closest.
Fold accuracy
Accuracyⱼ = correctⱼ / nⱼEach fold is scored only on samples excluded from that fold's fit.
CV mean
CV = (1/k) Σ AccuracyⱼK-fold cross-validation summarizes validation performance across the rotations.
When to use Cross-Validation Visualizer
- Understanding why validation data must not fit the model it evaluates.
- Learning k-fold rotation and why every fold requires a genuine refit.
- Comparing ordinary and stratified class allocation while keeping final-test evidence separate.
Primary references
scikit-learn — Cross-validation: evaluating estimator performance