Skip to content
BIASED

Validation and overfitting

Block 1 of 8~3 min

Three sets, three jobs

The topic Data, features and leakage removed the leaks: no feature carries the answer, and every fitted step of the pipeline, from scaling to target encoding, sees only training rows. A clean split is necessary. It is not yet a measurement of the risk.

Three things can still go wrong. A validation score is an average over finitely many examples, so it is a random number with a spread. The model we report is usually the best of many tried on the same examples, so its score is biased upward. And the split must imitate how the model will be used, or the score answers a different question. This topic builds a protocol that handles all three.

Some notation first. The data DD hold nn labelled pairs. A model trained on a set TT is aTa_T. Its average loss on a disjoint set VV is

R^V(aT)=1∣V∣∑i∈VL(yi,aT(xi)).\hat R_V(a_T) = \frac{1}{\lvert V \rvert} \sum_{i \in V} L\big(y_i, a_T(x_i)\big) .

The topic What machine learning is showed the training error falling to zero while the risk exploded. So the standard protocol splits the data into three disjoint parts:

  • the training set fits the parameters of the model;
  • the validation set makes the choices that training does not make: hyperparameters, features, the model family, when to stop;
  • the test set is touched once, at the end, to report the risk of the final choice.

Why three and not two? Every decision made by looking at a set uses up some of its honesty. Compare twenty values of a hyperparameter on the validation set, and the winner's score includes the luck of that comparison. Only a set that played no part in any decision still gives an unbiased estimate.

A test score on mm independent examples is an average of mm losses, so its error bar is the one from Confidence intervals and the bootstrap: for an accuracy pp the standard error is p(1−p)/m\sqrt{p(1-p)/m}. A churn model with accuracy 0.850.85 on 500 test customers is at 0.85±0.0310.85 \pm 0.031 at the 95% level. Two models that differ by 0.020.02 on this test set cannot be told apart by separate intervals. The paired bootstrap from the same topic compares them on the same examples and is much sharper.

Answers are saved on the server and tied to this browser until you sign in.