Train Tutorial: Val, Test Splits

TL;DRSplit data into train, validation, and test sets — and never let test leak.

The training set fits the model; the validation set tunes hyperparameters and picks models; the test set is touched once, at the end, to estimate real-world performance. Mixing them causes leakage — optimistic scores that collapse in production. The cardinal rule: the test set is sacred. Tuning on it is the most common way people fool themselves.

Key points

Common mistakes

Try it: Assign roles: which set tunes hyperparameters, which estimates real performance?

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>train → fit the model
val   → tune & select
test  → final, one-time judgment (never tune on it)</pre></body></html>
Open the interactive lesson →
Cross-Validation · K-Fold · Stratified Data Augmentation · Flips · Crops · Mixup