ML0003 Overfitting

What is overfitting and how to avoid overfitting?

Answer

Overfitting happens when a model learns the training data too well (including its noise and outliers) and as a result performs poorly on new, unseen data. The model becomes too specialized to the training set and fails to generalize. The telltale sign is a growing generalization gap: training loss keeps falling while validation loss turns back up. To avoid overfitting: simplify the model, get more data or use data augmentation, apply regularization (L1/L2), validate frequently with early stopping, and for neural networks use dropout.

(1) Definition: The model memorizes noise as if it were signal, so training error keeps dropping while test error rises.
(2) Detection: Watch the train/validation loss gap and use cross-validation: wildly varying performance across folds indicates overfitting.
(3) Remedies: More or augmented data, L1/L2 regularization, dropout, early stopping, or a smaller model; all reduce effective capacity or expose the model to more variation.

Training loss keeps decreasing while validation loss turns upward, with an early stopping marker

Figure 1: The validation loss minimum marks the ideal stopping point; training past it widens the generalization gap; that widening is overfitting.

Mathematical Formulation:
\mathcal{L}_{\mathrm{reg}}(\theta) = \mathcal{L}(\theta) + \lambda \lVert \theta \rVert_2^2
\mathrm{gap} = \mathcal{L}_{\mathrm{val}}(\theta) - \mathcal{L}_{\mathrm{train}}(\theta)

Where:

  • \mathcal{L}(\theta) is the original training loss over parameters \theta.
  • \lambda is the regularization strength; larger values shrink the weights \theta toward zero, trading training fit for generalization.
  • \lVert \theta \rVert_2^2 is the squared L2 norm of the weights (weight decay); an L1 penalty \lVert \theta \rVert_1 instead drives weights to exactly zero.
  • \mathcal{L}_{\mathrm{val}} and \mathcal{L}_{\mathrm{train}} are validation and training loss; a small, stable gap indicates good generalization.
Bias-variance tradeoff: total error is U-shaped over model complexity

Figure 2: Why the remedies work: they move the model left along the complexity axis, out of the high-variance region and back toward the total-error minimum.


Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *