← chapter

Train, validation, and test splits

Score a model on the data it trained on and the number is always good — it measures memory, not learning.

Hold data out, train without it, score on it once.

The one mistake

The split, to scale

60/20/20 of 768 patients: 460 train, 154 validation, 154 test.

The generalization gap

ε^trainε(h)ε^test\hat{\varepsilon}_{\text{train}} \le \varepsilon(h) \approx \hat{\varepsilon}_{\text{test}}

Training error is biased low because the model minimized exactly it. Test error, on held-out rows, is the unbiased estimate of the error you'll see in production.

Watch the gap open

A decision tree grown deeper each frame. Cyan = train accuracy, purple = held-out test. Train marches to 1.000; test peaks at depth 4 then falls.

The gap opens from 0.062 to 0.326. That gap is the model memorizing.

Optimistic vs honest

One unrestricted tree, scored two ways. On its training data: 1.000. On the held-out test set: 0.674. Same model — the only change is whether the data was seen.

Stratify for imbalance

Positive-class share in the test set: full data 0.349, stratified 0.348, random drifts to 0.338 — and the drift grows with rarer classes and smaller sets.

Takeaways