AI State of the Art
Fundamentals/Machine Learning: The Basics/24 min
Section 13

Overfitting and Underfitting: Diagnosis and Solutions

Listen as a podcast →

Introduction: Two Ways to Fail

Your model can fail in two completely opposite ways.

Underfitting: the model is too simple for the data. It fails to catch even the real regularities. Its error on the training data itself is already high, that is the telltale sign.

Overfitting: the model is too flexible. It learns the training data by heart, accidents included. Training error very low, error on fresh data high, the gap between the two is what gives it away.

Visual example of overfitting
This image illustrates the phenomenon of overfitting where the model, being too complex, fits the training data (in red) perfectly but fails to generalize (in blue). The red curve follows the training points too closely, including their noise.Source : ResearchGate

This is the bias-variance trade-off: the foundation of all statistical learning.

Bias vs Variance

Bias-variance quadrant diagram
This diagram illustrates the four possible combinations of bias and variance in a machine learning model. The black dots represent the training data, while the concentric circles show the model's ability to fit the data.Source : ResearchGate

Bias

This is the model's systematic error. It makes overly simplistic assumptions and sticks with them.

Example: you predict that all Paris apartments cost 400k euros (your average), regardless of square footage. That's biased: you're systematically off.

Cause: model too simple for the data.

Variance

Sensitivity to small variations in the data. The model changes drastically if you slightly change the data.

Example: a very deep decision tree learns individual noise. Change one training sample = completely different tree.

Cause: model too complex, overfitting.

The Error Decomposition

Total Error=Bias2+Variance+Irreducible Noise\text{Total Error} = \text{Bias}^2 + \text{Variance} + \text{Irreducible Noise}

Three terms to name. Bias is the systematic gap between what the model predicts on average and the truth; it appears squared for a technical reason, in the derivation this error enters as a distance, and distances combine through their squares, as in Pythagoras. Variance is the spread of the predictions when you perturb the training data slightly. Irreducible noise is the genuinely unpredictable part of the data itself: nobody, human or machine, can guess it, and it therefore sets an error floor no model can cross.

In one sentence: a model's error breaks down into what it misses systematically, what it misses at random, and what nobody could have guessed.

Ideal: small bias + small variance.

Underfitting: high bias + low variance (systematically wrong but stable).

Overfitting: low bias + high variance (fits the training data but unpredictable).

The target-shooting analogy

High bias, low variance = all shots to the left (grouped but misplaced). Low bias, high variance = shots scattered around the target. Ideal = all shots in the center.

Recognizing Underfitting

Signs:

  • High training error. The model can't even learn its own data well.
  • Validation error similar to training error. No gap.
  • Poor performance everywhere. 50% accuracy on a two-class problem is exactly what a coin flip achieves.

Solutions:

  • Increase complexity: more layers, more neurons
  • Supply more informative input variables
  • Reduce regularization (the "brakes" on complexity)
  • Train longer
  • Try a better architecture

Recognizing Overfitting

Signs:

  • Large gap between training and validation error. Train = 2%, Validation = 15%.
  • Validation error that turns back up over epochs (an epoch is one complete pass over the training data). It falls at first, then rises.
  • Perfect in the lab, terrible in production. Your numbers are excellent, but the user sees a model that doesn't work.
A little overfitting is normal and desirable

Zero overfitting is nearly always disguised underfitting. The right setting leaves a small gap between training and validation: flexible enough to catch the real regularities, not flexible enough to learn the noise.

Learning Curves: Your Best Diagnostic Tool

Plot two curves: training error and validation error over epochs.

Underfitting

Both curves stay high and close together. Adding more data? It won't help (there isn't enough capacity to learn).

Overfitting

Training error goes down (the model is learning). Validation error goes back up (overfitting to noise). Growing gap = classic signal.

Ideal

Both curves go down together and stabilize low, with a small gap (0.5-5% max).

Error curves as a function of model complexity
This graph illustrates the evolution of training and test errors as a function of model complexity. In the ideal zone, both errors are low and close together, indicating a good balance.Source : AIML.com

Train/validation/test: the short version

This diagnosis assumes you have data the model has never seen. Hence the rule: never measure a model on the data that trained it, or you measure its memory rather than its understanding.

So the dataset gets cut in three:

  • The training set (70-80%): the data the weights are fitted on.
  • The validation set (10-15%): the data you watch during development, to pick settings and decide when to stop. The model never trains on it.
  • The test set (10-15%): the data you touch once, right at the end. It is the only honest estimate of real performance.

Why three and not two? Because if the same batch serves both to choose the settings and to measure the result, the measurement runs optimistic: trying a hundred configurations and keeping the best on that batch also selects the luckiest fluctuation.

When data is scarce, a variant lets you use all of it: cross-validation, where you cut into kk parts and each part takes its turn as the evaluation set.

All of that (the proportions, stratified splits, the special case of time-ordered data, and the trap of data leakage) is covered in detail in Train/validation/test. This page sticks to the diagnosis.

Splitting data into training, validation, and test sets
This image illustrates the need to divide available data into three distinct sets: the training set to learn the model, the validation set to tune hyperparameters, and the test set to evaluate final performance. This avoids evaluation bias and overfitting.Source : Daily Dose of Data Science

Practical Solutions Against Overfitting

1. More Data

The best solution if you can. More diversity makes memorization impossible.

2. Data augmentation

Create variants of your data without actually creating truly new data.

Images: rotation, left-right mirroring, zoom, random crop, added grain, brightness shifts. A mirrored cat is still a cat, so the label does not change, that is the whole condition to respect.

Text: paraphrase, synonym substitution, back-translation (translate then translate back to keep the meaning while varying the phrasing).

Tabular data: add slight random noise, or use SMOTE (Synthetic Minority Oversampling Technique), which manufactures new examples of the rare class by interpolating between existing ones.

Methods like RandAugment and AutoAugment go further: they search for which transformations help most, instead of leaving a human to choose.

Example of image augmentation for AI
This image illustrates different data augmentation techniques applied to an original cat image. These transformations help enrich a dataset to improve the performance of artificial intelligence models.Source : IBM

3. Regularization

Add penalties that force the model to stay simple.

L2 (weight decay): penalizes large weights.

Dropout: randomly deactivates neurons.

Comparison of a standard neural network and one with dropout
The image shows a standard neural network (left) and the same network after applying the dropout technique (right), where some neurons are randomly deactivated to prevent overfitting.Source : Medium

Early stopping: stop before the model starts overfitting.

(Details in the next section.)

4. Early Stopping

Super simple and super effective. Monitor the validation error during training. As soon as it stops going down (or starts going back up), stop and keep the best weights.

  • Epoch 1-10: validation error decreases (keep the weights)
  • Epoch 11-15: validation error goes back up (stop, use epoch 10 weights)

Zero computational overhead. Almost always helps.

Generalization error curve as a function of capacity
As a model begins training, highly biased and low in complexity, both the training error and validation error will decrease. This can be seen in the underfitting zone when looking at the bias and generalization. If the model trains for long enough the a very complex and unbiased model can be learned but the variance or error increases as seen in the overfitting zone. The validation set is used in conjunction with early stopping to determine the optimal training zone for a model.

5. Reduce Complexity

Fewer layers, fewer neurons, simpler model.

Warning: too simple = underfitting.

6. Ensembles of models

Combine several models, either by majority vote or by stacking (a second model learns to arbitrate between the first ones). This mechanically reduces variance.

Example: 10 decision trees instead of 1. The random variation of one is canceled out by the others.

Diagram of ensemble learning process with 3 learners
The image illustrates the principle of ensemble learning where multiple models (learners) are trained on bootstrapped samples of the dataset. Their individual predictions are combined to form a more robust final prediction, reducing the impact of each model's random variation.Source : GeeksforGeeks

Double descent: the counter-example

The reasoning above suggests a simple curve: the bigger the model, the lower the error, up to a turning point past which it overfits. Observation contradicts that picture once you push size very far.

Belkin and co-authors described in 2019 what they call double descent: error on fresh data falls, then rises around the point where the model has just enough parameters to memorize the training set exactly, then falls again as you keep growing it well beyond.

Reconciling modern machine learning practice and the bias-variance trade-off (Belkin et al., 2019)

It is tempting to conclude that this explains the success of large language models. Careful: the link is plausible and often asserted, but it is not established. Keep the cautious version, the bias-variance trade-off describes the regime of modest-sized models well, and stops being sufficient in the regime of massively oversized ones.

Training and test error curve
This image illustrates the overfitting phenomenon where the training error decreases but the test error increases after a certain interpolation threshold. This shows why very large models (like GPTs) can perform well despite their over-parameterization.Source : ResearchGate

Quick Diagnostic Checklist

  1. Plot training error vs validation error
  2. Large train/validation gap? -> Overfitting. Regularize, add data, reduce complexity
  3. High training error? -> Underfitting. Increase capacity, train longer
  4. Both low and close? -> Good fit. Validate on test set
  5. Check your data: labeling errors and outliers impose an error floor nothing will cross

Being able to make this diagnosis quickly is what separates the experienced practitioner from the beginner.

Why This Matters

Overfitting and underfitting are the two main enemies of applied ML. Until you master how to recognize and fix them, you're building blind. It's the most important thing after having data.

Check your understanding0 / 5

1. On the learning curves, what gives overfitting away?

2. Your model shows exactly the same error on training and validation, with no gap at all. Good news?

3. The training and validation error curves both stay high and close together. What should you do?

4. Why is the dataset cut into three sets (training, validation, test) rather than just two?

5. What does early stopping consist of?