Home / Deep Learning

Overfitting vs. Underfitting

By Updated

Adjust the Model Complexity and train the model for thousands of Epochs to see how it learns to memorize the training data.

Overview

A concrete demonstration

Fit ten data points that follow a gentle curve with a little noise on top.

  • Degree 1 (a straight line) cannot bend at all. It misses the shape everywhere — high error on training data and new data. Underfitting.
  • Degree 9 through ten points passes exactly through every one. Training error is zero, and between the points the curve swings wildly to values the real pattern never produces. Overfitting.
  • Degree 3 follows the trend and ignores the jitter. Slightly worse on the training set than degree 9, considerably better on anything new.

The degree-9 model is not "more accurate". It has memorised the noise, and noise does not repeat.

3
4000
2.0x
System Diagnosis

UNDERFITTING

Model is too simple to capture the curve of the data.
Live Training View
Train Data
Val Data
Model Prediction
True Function
Current Epoch 0

Train Error (MSE)

Error measured against blue dots. 0.000

Validation Error (MSE)

Error measured against orange dots. 0.000

Overfitting vs Underfitting: A Practical Guide

Both failures look like poor performance and need opposite fixes. Telling them apart is a question of whether the model can even represent the pattern, or whether it has memorised the noise around it.

The bias-variance decomposition

Expected error on unseen data splits into three parts:

error = bias² + variance + irreducible noise

Bias is error from wrong assumptions — a model too simple to represent the real relationship. High bias is underfitting, and it shows up as poor performance on training and validation data.Variance is sensitivity to the particular training sample — a model flexible enough to fit noise. High variance is overfitting: excellent training performance, poor validation performance.Irreducible noise is the part no model can remove. If the same inputs sometimes produce different outputs, no amount of capacity will fix it, and a validation loss that flattens above zero is often this rather than a failure.

Capacity trades the first two against each other: adding it lowers bias and raises variance. The best model sits where their sum is smallest, not where either is minimised.

Telling them apart from two numbers

The diagnosis needs only the training and validation loss, compared against each other and against what is achievable:

  • Both high, close together — underfitting. The model cannot represent the pattern. Add capacity, train longer, or reduce regularisation.
  • Training low, validation much higher — overfitting. The model has memorised. Add data, add regularisation, or reduce capacity.
  • Both low, close together — this is what you want.
  • Training loss above validation loss — usually not a paradox but an artefact: dropout and batch norm are active during training and disabled at validation, so the training number is measured on a handicapped model.

Fixes, in the order worth trying

For overfitting, more data is the only fix with no downside, and augmentation is the cheap approximation to it. After that: early stopping, which costs nothing; then dropout or weight decay; and only then a smaller model, since shrinking capacity is the bluntest option.

For underfitting, first confirm the model is training at all — a learning rate that is too high or too low looks exactly like insufficient capacity. Then widen or deepen the network, remove regularisation, train for longer, or improve the features. A model that cannot overfit a small subset of the training data has a bug, not a capacity problem, and that is the fastest test to run.

Two ways to be wrong

Underfitting is a model too simple to capture the pattern. Training error is high, validation error is high, and the two are similar. The model has not learned enough.

Overfitting is a model that learned the training data including its noise. Training error is very low, validation error is much higher, and the gap is the symptom. The model learned too much of the wrong thing.

The diagnosis needs only two numbers:

Training errorValidation errorDiagnosis
HighHigh, similarUnderfitting
LowMuch higherOverfitting
LowLow, similarA good fit
HighLower than trainingA bug or a leak

That last row is worth naming: validation better than training usually means augmentation is applied only to training data, dropout is inflating training loss, or the split leaked.

Reading the training curve

Plot both losses against epochs and the shape tells you what is happening.

Both falling, still close: keep training.

Both flat and high from early on: underfitting. The model, the features or the learning rate is the problem.

Training falling, validation flattening then rising: the classic overfitting signature. The point where validation turns up is where the model stopped generalising and started memorising, and it is exactly where early stopping should trigger.

Validation noisy but not trending: normal. Judge the trend over several epochs, not one.

A related check: if training accuracy reaches 100%, the model has memorised the training set. That is not automatically bad — large networks often do this and still generalise — but the validation curve is the only thing that tells you which case you are in.

Fixing underfitting

The model needs more capacity or better inputs.

  • A bigger model — more layers, more units.
  • Better features. On tabular data this usually matters more than the architecture.
  • Train longer. Check the curve is genuinely flat and not still descending.
  • Less regularisation — lower dropout, less weight decay.
  • A better learning rate. A rate far too low looks exactly like underfitting.
  • Check for bugs. Wrong labels, a broken loss, or gradients not reaching the parameters all present as underfitting.

The sanity check that settles it: try to overfit a tiny subset — 20 examples — deliberately. A correct model and training loop should reach near-zero loss on 20 examples within a few hundred steps. If it cannot, the problem is a bug, not capacity, and no amount of tuning will help.

Try this above

  1. Set Model Complexity to its minimum. The fitted curve cannot follow the data no matter how many Target Epochs you allow — more training will never fix underfitting.
  2. Push complexity to maximum and watch the curve thread every single point, including the ones that are clearly noise.
  3. Now raise Data Noise and repeat both. The high-complexity model gets dramatically worse; the low-complexity one barely changes, because it was never paying attention to the noise.
  4. Use Sim Speed to slow the fit and watch the moment the curve starts chasing individual points.

Which lever to pull

They need opposite treatment, which is why diagnosing correctly matters more than any individual fix.

  • Underfitting — more capacity, better features, train longer, reduce regularisation.
  • Overfitting — more data, less capacity, more regularisation (dropout, weight decay), early stopping.

What usually goes wrong

Treating overfitting by training less. Early stopping helps, but if a model overfits after two epochs the real problem is capacity against data volume, not epoch count.Adding data to fix underfitting. More data does not help a model that lacks the capacity to represent the pattern in the first place. It is the standard remedy for overfitting and close to useless for the opposite.

In one line

Too little capacity misses the signal; too much memorises the noise — and the cures point in opposite directions.

Fixing overfitting

In rough order of effectiveness:

More data. The only fix that reduces variance without adding bias, and the reason "get more data" is such a reliable answer.

Data augmentation. Effectively more data, and often the single biggest improvement on image tasks with a few thousand examples.

Early stopping. Free, and it directly targets the moment overfitting begins. Keep the best checkpoint, not the last.

Weight decay. Penalises large weights, pulling the model towards simpler solutions. Always worth having on.

Dropout. Standard in dense layers and transformers, less used in modern convolutional networks.

A smaller model. Effective and blunt; try the regularisers first, since a smaller model also lowers the achievable ceiling.

Transfer learning. With a few hundred examples, fine-tuning a pretrained model beats training a smaller one from scratch by a wide margin.

Label smoothing and mixup. Soften the targets so the model is not pushed towards absolute confidence.

The modern complication: double descent

The classical picture — a U-shaped test error, with a sweet spot of complexity in the middle — is incomplete for very large models.

As model size grows, test error falls, then rises around the point where the model can exactly interpolate the training data, and then falls again as the model grows larger still. Very large networks often generalise well despite fitting their training data perfectly, which classical theory did not predict.

Two practical implications. Training accuracy of 100% is not by itself evidence of a problem — look at validation. And with modern architectures, "make the model smaller" is a less automatic response than it used to be; more data, augmentation and regularisation usually beat shrinking the network.

The classical U-curve is still real. It is now understood as the first half of a longer story.

Both failures, on one dial

Capacity swept from far too little to far too much, with train and test error side by side. The two failures are opposite ends of one axis, and the gap between the two numbers is the diagnosis.

example_01.pyNumPy
Output

Questions people ask

How big a train/validation gap is acceptable? There is no universal number. What matters is whether validation performance is good enough and stable. A 2% gap on a hard task may be fine; a 30% gap rarely is.

Can a model overfit and underfit at once? Yes — high bias and high variance together, usually from a badly chosen model plus insufficient data. Both errors are large and the gap is also large.

Does more data always help? With overfitting, yes. With underfitting, no — a linear model fitted to a million points is still linear.

Should I stop as soon as validation loss rises? Use patience — wait several epochs, since validation loss is noisy and can dip and recover.

Is 100% training accuracy bad? Not necessarily, for large models. The validation curve is the evidence that matters.

How do I know if it is a bug rather than underfitting? Try to overfit 20 examples. If you cannot, it is a bug.

Recap in one screen

  • Underfitting: both errors high and similar. Overfitting: training low, validation much higher.
  • The gap measures variance; the level of the training error measures bias.
  • Fix underfitting with capacity, features, longer training and less regularisation.
  • Fix overfitting with more data, augmentation, early stopping, weight decay and dropout.
  • Always try to overfit a tiny subset first — failing that test means a bug, not a modelling problem.

Check yourself

0 of 3

Answer without scrolling back up.

  1. Training accuracy 99%, validation accuracy 62%. This is:

  2. Training accuracy 61%, validation accuracy 60%. This is:

  3. Which change would you expect to reduce overfitting?

Cheat sheet

Overfitting vs Underfitting

Both failures look like poor performance and need opposite fixes. Telling them apart is a question of whether the model can even represent the pattern, or whether it has memorised the noise around it.

DEEP LEARNING · vizlearn.in/deep_learning/overfitting_vs_underfitting.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.