freecoding.school100% FREE · NO SIGNUP
Tensor TownISSUE #30 of 120

cross-validation · k-fold · stratified

NeuraVSThe Overfit Ogre
Neura saysCross-validation estimates real performance by training/testing on rotated data folds.

A single train/test split can be lucky or unlucky. k-fold cross-validation splits data into k parts, trains on k-1 and tests on the held-out fold, rotating through all k, then averages — a more reliable performance estimate that uses all data for both roles. Stratified folds preserve class ratios. Use it especially on smaller datasets where one split is too noisy.

Power-ups you unlock

The Overfit Ogre attacks — common mistakes

Boss battleExplain why averaging over folds beats a single split.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>5-fold: train on 4 parts, test on 1, rotate ×5
average the 5 scores → reliable estimate</pre></body></html>
▶ Open the interactive comic issue
‹ Overfitting · The Bias-Variance TradeTrain · Val · Test Splits ›