← chapter

Cross-validation

One train/test split gives you one number, and that number is part luck.

Hold out every slice in turn, score each, average. All your data tests, all of it trains — just never at the same time.

Why one split isn't enough

The rotation

Cut the data into k folds. Run k rounds. Each round: one fold held out, the rest train. Rotate until every fold has been the test set once.

Two numbers, not one

The estimate is the average of the k fold scores:

CVk=1kj=1ksj\mathrm{CV}_k = \frac{1}{k} \sum_{j=1}^{k} s_j

But report the spread too — how loudly the folds disagreed:

SDk=1kj=1k(sjCVk)2\mathrm{SD}_k = \sqrt{\frac{1}{k} \sum_{j=1}^{k} \left(s_j - \mathrm{CV}_k\right)^2}

0.75±0.010.75 \pm 0.01 and 0.75±0.060.75 \pm 0.06 are not the same result.

Watch it run

Five folds on 768 patients, one frame per round. The held-out fold marches across; the running mean settles; the band is ±1 std.

Fold 4 scores 0.830, fold 2 scores 0.669 — same model, different slice. Mean 0.750, band ±0.057. That width is the honest signal.

On imbalanced labels, stratify

The label is 35% positive. Plain contiguous folds swing from 0.255 to 0.416 positive per fold; stratified folds hold ≈ 0.35 everywhere.

Plain ±0.057, stratified ±0.012. Free, and the difference between quotable and noise.

Why it's more trustworthy

Thirty seeds. Single 80/20 split vs 5-fold CV mean. Same center, a quarter of the spread.

Single split: 0.739 ± 0.040 (0.649–0.799). CV mean: 0.739 ± 0.010 (0.718–0.763).

Takeaways