Home / Machine Learning

Cross Validation

Interactive explorer to visualize K-Fold splitting and validation logic.

Configuration

5

Higher k creates more folds but requires more training iterations.


Visualization

Fold: - / -
Train Data
Test Fold

Results

Ready to start.
Click 'Run Next Fold'
Average Accuracy
--%

Overview

Divide the examples into (k) folds. Fit (k) models: each run trains on (k-1) folds and evaluates on the remaining fold. Every row is held out once. With 100 rows and (k=5), each run trains on 80 rows and evaluates on 20.

How the folds work

Average the fold scores for a summary and inspect their spread. The standard deviation describes variation across these folds; it is not a confidence interval, because fold scores are not independent samples. Cross-validation estimates how the training procedure performs on similar data, not a guarantee for future populations.

Follow one evaluation

Set Folds (k) to 5 and press Run Next Fold until each fold has been held out. The visualizer shows which block is used for training and which for evaluation. Press Auto-Run All to compare the scores. A low-scoring fold may reveal a subgroup or an unstable split; do not hide it by reporting only the mean.

Choosing a split strategy

Five or ten folds are common practical choices, but the best value depends on data size, computation, and the task. Larger (k) means each model trains on a larger share of the data but requires more fits. Very large (k), including leave-one-out, can be computationally expensive and does not automatically produce a more reliable estimate.

  • Classification: stratified folds can preserve class proportions when random splitting is appropriate.
  • Repeated people, devices, or documents: use group-aware folds so one entity cannot occur on both sides.
  • Time series: use forward-chaining or time-series splits so training precedes evaluation.

Random k-fold is not suitable for every dataset. A split that leaks groups or future information gives a precise-looking answer to the wrong question.

Model selection and the final test

If you use the same cross-validation scores to choose among many models or settings, the best score tends to be optimistic because selection favored a lucky result. Use nested cross-validation when you need an estimate of the full tuning process, or keep an untouched test set for a final evaluation after choices are complete. Fit preprocessing separately inside each training fold, typically with a pipeline.

Common mistakes with K-Fold Cross Validation

  • Treating fold standard deviation as a confidence interval: the folds share much of their training data.
  • Using random folds for temporal or grouped data: the split must reflect how new examples arrive.
  • Tuning on the final test set: repeated choices turn it into validation data.
  • Comparing different folds for competing models: use the same splits to make comparisons more informative.

Sources and next steps

Predict, then reveal

About to run: set Folds (k) to its maximum (10). Before it does — what happens to the readout?

Committing to an answer first is the point — the reveal runs the experiment on the visualisation above and reads the real value back, so nothing here is scripted.

Check yourself

0 of 3

Answer without scrolling back up.

  1. What problem does k-fold cross-validation solve?

  2. For an imbalanced dataset, which variant should you reach for?

  3. What is the main cost of cross-validation?

Cheat sheet

K-Fold Cross Validation

Watch data split into k folds, each taking a turn as validation, and see why a single train/test split can flatter a model.

MACHINE LEARNING · vizlearn.in/machine_learning/cross_validation.html

Further reading

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.