Statistical Modeling and Generalization

Early Stopping

Early stopping as choosing the checkpoint with the best validation performance instead of the final training checkpoint.

Lesson
24

Goal

Understand early stopping as a practical rule for keeping the checkpoint that generalizes best, rather than assuming the model from the last training epoch is automatically the best model.

Motivation

Regularization changes the objective. Early stopping changes the training procedure.

The question here is:

If training keeps reducing the training loss, why would we ever stop before the end?

The answer is that the model can keep getting better at memorizing the training set while getting worse on unseen data. Validation metrics help us see that moment.

Prerequisites

Notation / Symbol Table

SymbolPlain-English nameMeaning
eepochOne pass through the training data.
L_train(e)training lossLoss measured on the training set after epoch e.
L_val(e)validation lossLoss measured on a held-out validation set after epoch e.
e_bestbest epochThe epoch whose validation performance is best so far.
ppatienceThe number of non-improving epochs we allow before stopping.

Core Ideas

We Usually Need Three Data Splits

The standard separation is:

That distinction matters because evaluation can leak into training. If you keep peeking at the test set and adjusting decisions, it stops being a real test set.

Training Curves And Validation Curves Behave Differently

Training loss often keeps decreasing for a long time. Validation loss behaves differently.

At first:

Later, once the model starts memorizing:

That rise is one of the clearest signs of overfitting during optimization.

Early Stopping Chooses The Best Validation Checkpoint

The rule is simple:

Keep track of the checkpoint with the best validation score, and stop training once improvement has meaningfully stopped.

The deployed model is not necessarily the final one. It is the one stored at e_best.

This is a deep habit shift for beginners. “Trained longer” is not automatically “better.”

Why Early Stopping Regularizes

Large models often learn broad patterns first and noisy idiosyncrasies later.

Early stopping works because it interrupts the training process before memorization becomes dominant.

So even though the architecture does not change, the effective learned function stays simpler than the function you might get after excessive training.

That is why early stopping is legitimately a regularizer.

Patience Prevents Overreacting To Noise

Validation metrics are noisy. A single bad epoch does not necessarily mean generalization has started collapsing.

That is why many training loops use patience:

Stop only after the validation metric has failed to improve for several consecutive epochs.

Patience smooths out random bumps and makes the stopping rule less jumpy.

Parameters Versus Hyperparameters

Early stopping also clarifies an important distinction.

Weights are learned automatically from the training data. The stopping rule is chosen by the practitioner.

That makes the stopping policy a hyperparameter choice, not an ordinary parameter value.

The same is true for:

Worked Example

Example 1: Picking The Best Epoch

Suppose the losses evolve like this:

EpochTrain lossValidation loss
10.920.95
20.710.74
30.550.58
40.430.47
50.340.45
60.260.46
70.190.50

The lowest validation loss occurs at epoch 5, so epoch 5 is the checkpoint to keep.

Epoch 7 fits the training set better, but it generalizes worse.

Example 2: Why Patience Helps

Suppose validation losses look like:

0.42
0.41
0.40
0.401
0.399
0.402

If you stop immediately after 0.401, you stop too soon. The next epoch actually improves to 0.399.

That is exactly what patience protects against.

Why This Shows Up In ML

Early stopping matters because training is expensive and generalization is the goal.

In practical ML systems, it helps you:

It is also one of the most accessible regularizers because it does not require changing the loss function at all.

Exercises

  1. Why is it a mistake to evaluate the test set after every epoch and use that to choose when to stop?
  2. If training loss keeps decreasing but validation loss starts increasing, what is the model probably learning?
  3. Suppose validation loss is lowest at epoch 18 but training ends at epoch 40. Which checkpoint should you deploy, and why?
  4. Why can a model trained for less time outperform the same architecture trained for longer?
  5. Why is patience usually better than stopping after the first validation setback?

Implementation Exercise

Write a TypeScript helper that scans a sequence of validation losses and returns:

Use a shape like:

type EarlyStoppingResult = {
  bestEpoch: number;
  bestValue: number;
  stopEpoch: number;
};

Then feed it a few synthetic validation curves and check that it chooses the checkpoint you would choose by inspection.

Reflection Questions