Visual walkthrough — Training, validation, and test error
This page rebuilds ONE idea from the parent note from absolute zero: why a number computed on a small held-out pile of data (the validation error) is a trustworthy stand-in for how the model does on the whole infinite world of future data (the true error). We will earn every symbol before we use it, and every step gets a picture.
Step 1 — What is a "mistake"? Defining loss on one example
WHAT. Before averaging anything, we need to score a single prediction. A model is a function : you feed it an input (say, an image) and it returns a guess . The real answer is . The loss is just a number saying "how wrong was this one guess". Zero means perfect; bigger means worse.
WHY loss and not "right/wrong"? A yes/no correctness flag throws away how wrong you were. Loss keeps the size of the error, so we can do smooth maths (averaging, calculus) with it.
PICTURE. Look at one dot: the true value sits on the black line, the prediction sits on the orange curve, and the red gap between them is the loss.
Step 2 — The number we wish we could compute: true error
WHAT. The world produces examples according to some hidden recipe we call — a probability rule that says how likely each pair is. The true error is the average loss over the entire world, weighting each possible example by how often it appears:
WHY this is the real target. This is exactly the "competition performance" from the parent's music analogy — the mistake we make on genuinely new data. Everything else on this page is an attempt to estimate this one number.
WHY we can't just compute it. The symbol ("expected value") here means "add up the loss on every possible example, each weighted by its probability". That is an infinite sum over a recipe we never get to see. So is a real, fixed number — but it is hidden from us.
PICTURE. The whole cloud of grey dots is the world . is the average red gap over all of them — but we only ever get to see a handful.
Step 3 — The trick: replace the infinite average with a finite one
WHAT. We grab a validation set: examples that the model did not train on. We compute the plain average loss over just these:
WHY an average of a sample? Because we can compute this — it is a finite sum over data we actually hold. The bet we are making is: this measurable average is close to the unmeasurable . Step 4 justifies the bet.
WHY "not trained on" matters (previews Step 6). If the model had seen these points during training, it could have memorised them, making artificially tiny — a lie about the true error.
PICTURE. We highlight a small blue sub-cloud pulled out of the grey world. is the average red gap over only the blue dots.
Step 4 — Why the sample average converges: the Law of Large Numbers
WHAT. Each validation example gives one loss value . Because the points are drawn i.i.d. (independent, and each from the same recipe ), each is a fresh random draw whose expected value is exactly :
The Law of Large Numbers says: averaging many independent draws pulls the average toward the common expected value.
Term by term: the left side is what we measure; the arrow with means "as the held-out pile grows"; the right side is the hidden truth we were chasing in Step 2.
WHY this exact tool and not another? We specifically need a theorem that connects a finite average to an expected value. The Law of Large Numbers is precisely that bridge — it is the mathematical reason a poll of 1000 people predicts millions of voters. Averaging is the only operation that makes independent random errors cancel out.
HOW fast? The wobble of around shrinks like — quadruple the validation set to halve the noise. This is why the parent note says 1% of 100{,}000 (=1000 samples) is "enough": , a small wobble.
PICTURE. As grows left→right, the noisy curve settles onto the flat dashed line , inside a shrinking funnel.
Step 5 — The two silent assumptions (and where they hide)
WHAT. The convergence in Step 4 rests on exactly two words we underlined: i.i.d. and independent of training. Break either and the arrow no longer points at .
WHY call them out? Because in real projects they fail quietly — no error message, just a wrong number. This is the Data Leakage trap.
- Assumption A — same distribution (i.i.d.): validation data must come from the same world the model will face. If future data drifts (new camera, new users), estimates the old world, not the new one.
- Assumption B — independence from training: if a validation row also sat in the training set (a duplicate, or a leaked feature), the model may have memorised it.
PICTURE. Left: honest split — training (orange) and validation (blue) clouds are separate, so the blue average is unbiased. Right: leakage — a blue point overlaps an orange one; the model "already knows the answer," and drops below (green dashed).
Step 6 — Why the test set exists: selection re-biases validation
WHAT. Suppose we train many models and pick the one with the lowest (this is Model Selection). Even though each individual was unbiased in Step 4, the minimum of several noisy numbers is systematically below the truth — we selected the model that got lucky on this particular validation set.
WHY a separate test set fixes it. The test set is touched once, after all choices are locked. We never optimise against it, so no "luckiest of many" bias sneaks in — its average is a clean estimate for the already-chosen model.
PICTURE. Several validation errors scatter around (grey band); we circle the lowest (green) — it sits below the band. The single test measurement (red) lands back on the true line.
Step 7 — Degenerate cases: what happens at the extremes
WHAT. Every scenario the reader could hit:
- (no held-out data): the arrow in Step 4 has nothing to average. You have no estimate of generalisation — only training error, which overfitting makes meaningless.
- tiny (e.g. 5): the wobble is huge; is noise. Fix with Cross-Validation — rotate every fold through the validation role and average, so all data contributes to the estimate.
- huge (e.g. 40% of data): the estimate is stable but you starved training, raising both bias and variance of the model itself (see Learning Curves).
- Validation not i.i.d. (time series, grouped data): Step 4 fails silently; split by group / by time so the held-out set truly mimics the future.
WHY show these. The clean convergence of Step 4 is a best case; real datasets live near these edges, and knowing the failure shape tells you which knob to turn.
PICTURE. The bias–variance trade-off of the estimate itself vs held-out fraction : too small → high variance (red), too large → the model degrades (orange). The green valley is the sweet spot the parent's split ratios target.
The one-picture summary
The whole page in one frame: the infinite grey world (, the hidden target) → sampled into a finite blue validation pile (, measurable) → the Law of Large Numbers closes the gap as grows → but selecting the best model biases validation low, so a once-only red test measurement gives the honest final number.
Recall Feynman retelling — say it back in plain words
We want to know how badly our model will mess up on all future data, but "all future data" is infinite, so that number is hidden. Trick: grab a small honest handful of examples the model has never studied, measure the average mistake on them, and trust that this average is close to the hidden number. The reason we can trust it is the Law of Large Numbers — averaging many independent measurements cancels the randomness, and the leftover wobble shrinks like one over the square root of how many examples we grabbed. Two catches: the handful must come from the same world (i.i.d.) and the model must not have peeked at it during training, or the average lies low. And once we pick the best-scoring model out of many, that best score is luckily low, so we keep one final untouched pile — the test set — measured exactly once, to report the honest score. That's the whole reason for three sets. See Generalization Error for the formal version and Overfitting and Regularization for what makes the training–validation gap grow.
Recall Quick self-check
Why can't we compute directly? ::: It averages loss over the entire infinite data distribution , which we never fully observe. What theorem lets approximate ? ::: The Law of Large Numbers — the average of i.i.d. losses converges to their expected value. How does the estimate's noise scale with validation size? ::: Like — quadruple the set to halve the wobble. Why is a separate test set needed after model selection? ::: Choosing the minimum validation error biases it low; the once-only test set gives an unbiased score for the chosen model. What makes dip below ? ::: Data leakage — the model trained on (or memorised) validation examples, violating independence.