MACHINE LEARNING FUNDAMENTALS · MODEL FIT

Overfitting vs Underfitting
Finding Your Model's True Fit

Every machine learning model fails in one of two ways: it either learns too little from your data, or it memorizes too much of it. This guide breaks down both failure modes with real curves, real causes, and the exact fixes practitioners use to land in the sweet spot.

Underfitting
high bias
Balanced Fit
low bias · low variance
Overfitting
high variance
train error: high train/val gap: minimal val error: rising
Scroll to explore
01 · Introduction

Why models fail: it's always a fit problem

When a machine learning model performs poorly, the reason almost always traces back to one thing: how well the model's complexity matches the true complexity of the data. Too simple, and the model can't capture the underlying pattern at all. Too complex, and it starts memorizing noise instead of learning signal. These two failure modes are called underfitting and overfitting, and understanding them is the single most useful diagnostic skill in applied machine learning.

In this guide, we'll break down what each term actually means mathematically and intuitively, how to spot them using training curves, the bias-variance tradeoff that connects them, and the exact, practical techniques engineers use to fix each one. By the end, you'll be able to look at a loss curve and immediately diagnose what's going wrong.

02 · High Bias
UNDERFITTING

The model that never learned enough

Underfitting happens when a model is too simple to capture the true relationship in the data. It performs poorly on both the training set and the validation/test set, because it hasn't learned the pattern in the first place — there's nothing to "recall" and nothing to "generalize."

Statistically, this is described as high bias: the model makes strong, oversimplified assumptions about the data (e.g. fitting a straight line to a curved relationship), so its predictions are systematically off regardless of which data it sees.

Error Epochs both errors plateau high
Training loss Validation loss
Cause 01

Model too simple

Using linear regression for a clearly non-linear relationship, or a shallow network for a complex task.

Cause 02

Excessive regularization

Very high L1/L2 penalty or aggressive dropout can constrain the model so much it can't fit even the signal.

Cause 03

Too few features

Missing input features mean the model literally doesn't have the information needed to predict well.

Cause 04

Insufficient training

Stopping training too early, or too low a learning rate, before the model has converged.

Cause 05

Noisy or unscaled input

Unnormalized features can make gradient-based learning converge slowly to a poor solution.

Cause 06

Wrong algorithm choice

Some algorithms simply aren't expressive enough for certain problem structures, e.g. Naive Bayes on highly correlated features.

03 · High Variance
OVERFITTING

The model that memorized instead of learned

Overfitting happens when a model is so complex that it starts fitting the noise in the training data rather than the underlying pattern. Training loss keeps dropping — often close to zero — but validation loss starts climbing back up after an initial improvement.

This is described as high variance: the model's predictions swing wildly depending on exactly which training data it saw, because it has effectively memorized specific examples (including their noise and outliers) instead of the general relationship.

Error Epochs divergence point
Training loss Validation loss
Cause 01

Model too complex

Deep networks or high-degree polynomials with far more parameters than the data justifies.

Cause 02

Too little training data

A small dataset gives the model too few examples to distinguish real signal from random noise.

Cause 03

Training for too long

Continuing past the point of best validation performance lets the model start memorizing specifics.

Cause 04

No regularization

Skipping L1/L2 penalties, dropout, or weight decay leaves nothing to discourage memorization.

Cause 05

Noisy labels

A complex model can learn to reproduce mislabeled or noisy training examples exactly.

Cause 06

Data leakage

Validation data (or features derived from it) accidentally influencing training inflates apparent performance.

04 · The Core Tradeoff
BIAS–VARIANCE TRADEOFF

Two errors, one total cost

Total generalization error can be decomposed into three parts: bias (error from over-simplified assumptions), variance (error from sensitivity to the training set), and irreducible noise. As model complexity increases, bias goes down but variance goes up — they move in opposite directions.

The goal isn't to eliminate bias or variance entirely — it's impossible to zero out both. The goal is to find the complexity level where their combined error is lowest. That point is the "sweet spot" marked on the fit spectrum in the hero section above.

Error Model Complexity → sweet spot
Bias² Variance Total error
05 · Side-by-Side

Underfitting vs Overfitting at a glance

A quick reference for diagnosing which failure mode you're dealing with.

Signal Underfitting Overfitting
Training error High Very low
Validation error High High (rising)
Gap between train & val error Small Large
Bias / Variance High bias High variance
Model complexity Too low Too high
Typical cause Simple model, too few features Complex model, too little data
Primary fix direction Increase capacity / reduce regularization Reduce capacity / add regularization
06 · Diagnosis

How to detect it before it costs you

Detection comes down to comparing training performance against validation performance, ideally while the model is still training:

Plot learning curves. Track training and validation loss (or accuracy) across epochs. A large, growing gap signals overfitting; both curves plateauing at a poor value signals underfitting.

Use k-fold cross-validation. If performance varies wildly across folds, the model is likely overfitting to whichever fold it was trained on. Consistently poor performance across all folds points to underfitting.

Compare against a simple baseline. If a basic baseline model (e.g. predicting the mean, or a shallow tree) performs almost as well as your complex model, your complex model may be overfitting without adding real value.

Check residual patterns. For regression tasks, structured (non-random) residuals on the training set often indicate underfitting — the model is missing a pattern it should have captured.

07 · Solutions

Fixing underfitting

The general direction is to give the model more capacity and more signal to learn from.

Fix 01

Increase model complexity

Move to a more expressive architecture — deeper networks, higher-degree polynomial features, or ensemble methods.

Fix 02

Add or engineer features

Introduce interaction terms, domain-specific features, or additional data sources the model currently lacks.

Fix 03

Reduce regularization

Lower the L1/L2 penalty weight, dropout rate, or early-stopping aggressiveness.

Fix 04

Train for longer

Increase epochs or iterations, and confirm the optimizer has actually converged.

Fix 05

Tune the learning rate

A learning rate that's too small can look like underfitting when the model simply hasn't converged yet.

Fix 06

Remove excessive feature reduction

Revisit aggressive dimensionality reduction (e.g. PCA) that may have discarded useful signal.

08 · Solutions

Fixing overfitting

The general direction is to constrain the model and give it a clearer, larger, or noisier-resistant signal.

Fix 01

Add regularization

Apply L1 (Lasso) for sparsity or L2 (Ridge) to shrink weights, penalizing overly complex solutions.

Fix 02

Use dropout

Randomly deactivate neurons during training so the network can't rely on any single memorized path.

Fix 03

Early stopping

Halt training at the epoch where validation loss is lowest, before it starts climbing again.

Fix 04

Get more training data

More diverse examples make it harder for the model to memorize noise instead of the real pattern.

Fix 05

Data augmentation

Synthetically expand the training set (rotations, crops, noise injection, paraphrasing) to improve generalization.

Fix 06

Simplify or prune the model

Reduce layers/parameters, prune decision trees, or select fewer, more relevant features.

Fix 07

Cross-validation

Use k-fold cross-validation during model selection so performance estimates aren't tied to one lucky split.

Fix 08

Ensemble methods

Bagging (e.g. Random Forests) averages out the variance of individual high-complexity models.

Fix 09

Batch normalization

Stabilizes training dynamics in deep networks, which indirectly reduces overfitting risk.

09 · Applied Examples

What this looks like in practice

Example — Underfitting

House price prediction with a straight line

Fitting a single straight line to house prices that actually rise non-linearly with square footage produces large errors everywhere — on training rows and new listings alike. A polynomial or tree-based model captures the curve far better.

Example — Overfitting

House price prediction with degree-15 polynomial

A degree-15 polynomial can pass through almost every training point exactly, achieving near-zero training error — but it oscillates wildly between points, producing absurd predictions on new houses.

Example — Underfitting

Image classifier with too few layers

A single-layer network trying to classify complex images (e.g. distinguishing dog breeds) lacks the representational depth to learn meaningful visual features, capping accuracy low on all data splits.

Example — Overfitting

Image classifier on a tiny dataset

A deep CNN trained on only a few hundred images can reach 99% training accuracy while validation accuracy stalls near random chance — a textbook memorization signature.

10 · Quick Reference

Model-fit checklist

Plot learning curves every time you train — don't rely on a single final metric.

Hold out a validation set that the model never touches during training.

Start simple, then add complexity only as far as validation performance keeps improving.

Regularize by default on any model with high capacity relative to your dataset size.

Use cross-validation for small datasets to get a reliable performance estimate.

Re-check after every change — fixing overfitting too aggressively can swing you into underfitting.

The takeaway

Overfitting and underfitting sit at opposite ends of the same dial. Every modeling decision — architecture, regularization, data volume, training time — turns that dial. The job isn't to eliminate bias or variance, it's to find where their combined cost is lowest for your specific problem and dataset.

bias-variance tradeoff regularization cross-validation learning curves