Skip to content
StackDecode
AI & ML Atlas
Machine LearningtechniqueAnimated walkthrough

Cross-Validation

Estimates how well a model generalises by training and testing on different splits.

The idea

In k-fold cross-validation the data is cut into k parts. Each part takes a turn as the test set while the model trains on the rest. Averaging the k scores gives a steadier estimate than one split, and the same procedure compares models and hyper-parameters fairly.

Watch it run

The pipeline lights up one step at a time. Use the controls to pause or step through it.

  1. 1Shuffle the data and split it into k folds.
  2. 2Train on k − 1 folds.
  3. 3Evaluate on the held-out fold.
  4. 4Repeat so each fold is the test fold once.
  5. 5Average the k scores.
1/5

Step by step

  1. 1Shuffle the data and split it into k folds.
  2. 2Train on k − 1 folds.
  3. 3Evaluate on the held-out fold.
  4. 4Repeat so each fold is the test fold once.
  5. 5Average the k scores.

Where it is used

Model selection and honest performance estimates.

Watch out for

Leaking information across folds (for example scaling before splitting, or related rows in different folds) inflates the score. Time series need ordered splits.

Related