Neural Networks & Transformers

AI · Neural Networks & Transformers

Overfitting vs. Underfitting: Diagnosing the Bias-Variance Trade-off

Two opposite ways a model can fail to generalize, and how to tell which one you're looking at from nothing more than a training curve.

8 min read
OverfittingBias-VarianceModel Evaluation

Every model that learns from data risks failing in one of two opposite ways. It can learn too little of the real pattern, or it can learn too much of the noise sitting on top of that pattern. Both failures look like "the model isn't working," but they call for opposite fixes — so the first skill worth building isn't how to fix either one, it's how to tell them apart.

Overfitting: memorizing the noise

A model overfits when it has effectively memorized quirks specific to the training set — the idiosyncratic phrasing of a few training examples, a handful of mislabeled rows, the exact pixel noise in a batch of photos — rather than learning the underlying pattern those examples were sampled from. The telltale symptom is a large, stubborn gap in performance: the model looks excellent on the data it was trained on and noticeably worse on new, unseen data. It hasn't learned to solve the problem; it has learned to recognize the training set.

Underfitting: not learning enough

Underfitting is the opposite failure. The model is too simple for the problem, or hasn't been trained long enough, to capture the real pattern in the data at all. Crucially, this shows up on both sides: an underfit model performs poorly on the training data and on unseen data, because it never found the signal in the first place. There's no gap to speak of — just uniformly disappointing performance.

The bias-variance framing

These two failure modes are really two ends of one dial, and the classical way to name that dial is bias and variance. A high-bias model is one that's too simple — it makes strong, rigid assumptions about the shape of the pattern and systematically misses the true relationship no matter how much data you feed it. High bias produces underfitting. A high-variance model is the opposite — it's flexible enough to be overly sensitive to the specific training examples it happened to see, so a slightly different training set would have produced a noticeably different model. High variance produces overfitting.

The trade-off part isn't optional: as you increase a model's capacity to reduce bias — letting it represent more complex functions so it can finally capture the real pattern — you almost always increase its variance at the same time, because that extra flexibility is just as happy to fit noise as signal. There is no free lunch here; the practical work of training a model is finding the point on that dial where bias and variance are both low enough that total error is minimized, not eliminating either one.

Reading the training curves

In practice, you rarely need clever diagnostics to tell these apart — you need a plot. Track the loss on the training set and on a held-out validation set at every epoch (or every N steps), and the shape of the two curves tells you almost everything.

python
for epoch in range(num_epochs):
    train_loss = run_epoch(model, train_loader, optimizer)
    val_loss = evaluate(model, val_loader)

    history["train_loss"].append(train_loss)
    history["val_loss"].append(val_loss)

    # The gap between these two numbers is the whole story:
    #   - both high, close together  -> underfitting
    #   - train keeps dropping, val stalls/rises -> overfitting
    print(f"epoch {epoch}: train={train_loss:.4f} val={val_loss:.4f}")
  • Underfitting's signature: both curves plateau at a high loss and stay close together. The model isn't struggling more on validation data than on training data — it's struggling equally on both, because it hasn't found the pattern in either.
  • Overfitting's signature: the classic diverging curves. Training loss keeps falling, often toward near-zero, while validation loss stalls and then starts climbing back up. That upward turn in validation loss is usually the exact point where the model stopped learning the general pattern and started learning the training set's specific noise.

A healthy fit, for comparison

A well-fit model shows both curves dropping together and settling near each other at a low loss — a small, stable gap rather than a widening one. That small remaining gap is expected; it's the point where nearly-zero-but-not-quite reflects genuine generalization rather than a red flag.

Capacity is the knob you're turning

Model capacity — roughly, how many parameters the model has and how flexible its function class is — is the lever that moves you along the bias-variance dial. Push capacity up without a corresponding increase in training data or added constraints, and you push the model toward overfitting: it now has enough free parameters to fit the training set's noise in addition to its signal. Push capacity down relative to how complex the underlying problem actually is, and you push the model toward underfitting: it simply doesn't have room to represent the true relationship, however much data you throw at it. Diagnosing the curve tells you which direction to move; it doesn't by itself tell you the model was the wrong size — training duration, data quantity, and the choice of architecture all interact with capacity in the same way.

Diagnosis first, treatment second

Once you've confirmed overfitting from the curves, the standard toolbox is well known — gather more training data, apply regularization, simplify the model, or stop training early at the point where validation loss bottoms out. Each of those deserves more than a paragraph, which is exactly why they get their own dedicated article on regularization and generalization. The point here is narrower: know which problem you have before you reach for a fix.

Key takeaways

  • Overfitting: great training performance, noticeably worse performance on unseen data — the model memorized noise instead of the pattern.
  • Underfitting: poor performance on both training and unseen data — the model never found the pattern at all.
  • High bias (too rigid) causes underfitting; high variance (too sensitive to the training sample) causes overfitting, and reducing one tends to increase the other.
  • On a training-vs-validation loss plot, underfitting looks like two flat curves stuck together; overfitting looks like diverging curves where validation loss stalls or rises while training loss keeps falling.
  • Raising model capacity without more data pushes toward overfitting; too little capacity for the problem pushes toward underfitting.
  • Diagnose from the curves first — the fix (more data, regularization, a simpler model, early stopping) depends entirely on which failure mode you're looking at.
2026 — Built by Arpit Mishra