2.6.3 · D4Model Evaluation & Selection

Exercises — Training, validation, and test error

2,417 words11 min readBack to topic

This page is a graded workout for the parent topic. Every problem states its level (L1 = just recognise it, up to L5 = build something new). Try each one before opening the Solution toggle. After every level there is a [!mistake] callout that steel-mans the wrong path — the one that feels right — and shows the fix.

Before we start, one picture ties everything together. Keep it in your head for the whole page.

Figure — Training, validation, and test error

Symbols we will reuse (each is earned in the parent note, repeated here so line one makes sense):

  • ::: average loss on the training pile — measures fit.
  • ::: average loss on the validation pile — measures how well a chosen setting generalises.
  • ::: average loss on the test pile — the unbiased final grade.
  • ::: the generalization gap; big = overfitting.

L1 · Recognition

Exercise 1.1 — Name the pile

For each activity, say which pile (train / val / test) is being used.

  1. Gradient descent updates the weights.
  2. You compare lr = 0.01 vs lr = 0.001 and keep the better one.
  3. You report a single final accuracy number in your paper.
Recall Solution
  1. Training — only training data is allowed to move the parameters.
  2. Validation — comparing hyperparameter settings is a model-selection decision, exactly what the validation set is for.
  3. Test — the final, report-once number is the test error.

Exercise 1.2 — Order the three errors

For a healthily-fit model, put , , in the usual size order and say why.

Recall Solution

Usually .

  • Training error is smallest because the model optimised on that exact data.
  • Validation and test are on unseen data, so they are higher and roughly equal (both estimate the same true generalization error).
  • If , you tuned too hard on validation (leakage of a mild kind, see Data Leakage).

Exercise 1.3 — True or false

"You may look at the test set whenever you want, as long as you don't train on it."

Recall Solution

False. Looking at test error to decide anything (pick a model, stop training, change a feature) turns it into a validation set. It stops being unbiased. Rule: compute test error once, at the end.


L2 · Application

Exercise 2.1 — Compute the three errors

A regression model gives squared-error losses on 3 tiny piles:

  • Train losses:
  • Val losses:
  • Test losses:

Compute , , and the gap .

Recall Solution

Recall (plain average of the losses). A positive gap of hints at some overfitting.

Exercise 2.2 — Choose the split

You have labelled examples and plenty of hyperparameters to tune. Choose sensible sizes for train / val / test and justify with a number.

Recall Solution

Large dataset → a 98 / 1 / 1 split works.

  • Val samples.
  • Test samples.
  • Train . Why acceptable: is large enough that the error estimate is stable, and you keep the vast majority for training. On a small dataset you'd instead use k-fold cross-validation.

Exercise 2.3 — Pick the winner from a table

Three configs:

Config
A 0.15 0.42
B 0.08 0.38
C 0.02 0.55

Which do you deploy, and what is C's problem?

Recall Solution

Deploy B: it has the lowest validation error (), and validation error is the decision metric.

  • C has the lowest training error () but the highest validation error () → classic overfitting: it memorised the training pile.
  • Its gap is huge; B's gap is milder.

L3 · Analysis

Exercise 3.1 — Diagnose from a learning curve

Two models. Over training epochs:

  • Model P: falls to , stalls at .
  • Model Q: stalls at , stalls at .

For each, name the regime (underfit / overfit / good), the gap, and one fix.

Recall Solution
  • P: gap (large). → Overfitting. Fix: add regularization, more data, or early stopping (see Learning Curves).
  • Q: gap (tiny) but both errors high. → Underfitting (high bias). Fix: bigger / more expressive model, train longer, better features. Key insight: a small gap alone is not success — Q generalises "well" only in the sense that it's equally bad everywhere.

Exercise 3.2 — The optimistic test set

You had no validation set. You trained 50 models and kept the one with the lowest test error, reporting that number. Explain quantitatively-in-spirit why the reported number is too good.

Recall Solution

By trying 50 models and keeping the minimum test error, you are selecting the model that got lucky on that particular test pile's sampling noise. The minimum of many noisy estimates is biased below the true error.

  • This is exactly leakage through the selection process: the test set silently became a validation set.
  • Fix: reserve a separate validation set for the 50 comparisons; touch test once on the single chosen model. Its number will typically be worse — and honest.

Exercise 3.3 — Bias–variance reading

As model complexity rises, the informal decomposition is Sketch (in words) what happens to bias, variance, and , and where the best model sits.

Recall Solution
  • Bias ↓ (a more flexible model can represent the truth).
  • Variance ↑ (more ways to chase noise).
  • ↓ monotonically (always fits training data better).
  • = a U-shape: falls (bias shrinking dominates) then rises (variance blowing up dominates).
  • Best model = bottom of the U, where the marginal bias drop equals the marginal variance rise. See the figure below.
Figure — Training, validation, and test error

L4 · Synthesis

Exercise 4.1 — Design a full pipeline

You have points (small), want to compare polynomial degrees , and must report an honest final error. Design the protocol end-to-end, with numbers, using 5-fold cross-validation plus a held-out test set.

Recall Solution

Step 1 — Carve off test first. Hold out test points, locked away. Remaining for development. Step 2 — 5-fold CV on the 850. Each fold points.

  • For each degree : train on points, validate on the held-out , rotate 5 times.
  • Average the 5 validation errors → one stable per degree (see Cross-Validation). Step 3 — Select. Pick the with the smallest . Step 4 — Refit. Retrain that degree on all 850 development points (max data now that tuning is done). Step 5 — Report. Evaluate once on the test points → , the unbiased final grade. Why CV, not one split? With only 850 points a single 170-point validation set is noisy; averaging 5 folds cuts that variance.

Exercise 4.2 — Combine train+val, then justify the count

CIFAR-style: training images, test images. You split off for validation, tune, pick a config. How many images does the final model train on, and why is combining allowed?

Recall Solution
  • During tuning: train on , validate on .
  • After choosing the config, retrain on images.
  • Why allowed: the validation set's only job was choosing the hyperparameters; that decision is now frozen. Feeding those back in adds data and never let them influence which config we picked, so no leakage into model selection.
  • Test still stays at , untouched → remains honest.

L5 · Mastery

Exercise 5.1 — How noisy is my estimate?

A held-out set has points. Each per-point loss is (roughly) independent with variance . The reported error is . (a) Give the standard error (spread) of . (b) If and you want the spread of below , how many held-out points do you need?

Recall Solution

(a) The average of independent numbers each with variance has variance , so This is the Law of Large Numbers made quantitative: more held-out data → smaller spread → more trustworthy or . (b) Require with : So you need at least held-out points — which is exactly why a slice of a k dataset is plenty, but a -point validation set is dangerously noisy.

Exercise 5.2 — The multiple-comparisons penalty (synthesis)

You compare models on the same validation set. Even if all are truly equally good, the best-looking validation error is biased low. Argue why the bias grows with , and give the practical rule this implies.

Recall Solution

Each is the true error plus noise (mean , spread ). Selecting the minimum over noisy values, systematically picks a large-negative . The expected minimum of zero-mean noises drifts more negative as grows (with Gaussian noise it grows like ). Consequence: the validation score of your winner is optimistic, and more so the more configs you tried. Practical rules: (1) keep a truly untouched test set so this optimism is caught; (2) don't run thousands of configs against a tiny validation set; (3) prefer cross-validation to shrink .

Recall Quick self-quiz

Which pile may move the parameters? ::: Only the training pile. Which pile chooses hyperparameters? ::: The validation pile. How many times do you touch the test pile? ::: Once, at the very end. Standard error of an error estimate over points with per-point spread ? ::: . Sign of a healthy gap ? ::: Small and positive (near ).


Related: Overfitting and Regularization · Cross-Validation · Model Selection · Learning Curves · Generalization Error · Data Leakage