Machine learning with football · Chapter 7 · Datasets and overfitting

L2 regularization

L2 makes big weights expensive. Early stopping quits while the model is still general.

Estimated time: 10 minutes · page 10 of 12

L2 and early stopping

The L2 term is the sum of the squared weights:

L2 = w₁² + w₂² + … + wₙ²

Squares punish big weights far more than small ones. With weights 0.2, −0.5, 5.0, −1.2, 0.3 and −0.1 the sum is 26.83, and 25 of it comes from the single 5.0. L2 pushes weights toward 0 but never exactly to 0, so no feature is dropped.

λ, the regularization rate, sets how much the penalty counts. Switch it on the board. At 0 the club weights grow freely and the validation curve climbs. At 0.02 they stay small, both curves flatten, and the gap between them nearly closes. The best λ depends on the data, so it's chosen on the validation set. It also interacts with the learning rate: a big learning rate pushes weights out, a big λ pulls them in, and changing one means re-tuning the other.

Early stopping is the cheap alternative: stop training where validation loss was lowest. The board marks that step. Training loss ends higher than it could be, but the model generalizes better. It's quick, and rarely the very best you can do.

Check yourself

Weights 0.2, −0.5, 5.0, −1.2, 0.3 and −0.1. What is the L2 term, and which weight dominates it?
True or false: L2 regularization removes features from the model.
What does early stopping do?

Leagues