🎉 All courses are now 100% free for everyone — enroll today, no payment required.
AXIONCORE
Articles/Machine Learning Theory
MACHINE LEARNING THEORYINTERMEDIATE

Why Models Overfit: A Theory of Generalization

"The model memorized the data" is the surface explanation. Underneath it are empirical risk, hypothesis spaces, bias–variance, and the inductive biases that let a model guess correctly about points it has never seen.

19 min read|2026-08-27|overfitting · generalization · bias-variance · regularization · statistical learning

Say a model out loud: "it overfit." The usual gloss — it memorized the training data — is true, but it's a symptom, not a mechanism. To actually reason about overfitting, predict it, and fix it, you need the machinery underneath: empirical vs. expected risk, hypothesis spaces, bias and variance, and the inductive biases that let a model guess correctly about points it has never seen.

01 — the real problem

Generalization, Not Memorization

Every supervised learning problem starts from a dataset D = {(x₁,y₁), ..., (xₙ,yₙ)}, which we treat as n independent draws from some unknown distribution (x, y) ~ P(X, Y). Crucially, the dataset is not the goal — it is evidence. The model's job is to perform well on future samples drawn from that same distribution, most of which it will never see during training. Every idea in this article is downstream of that one asymmetry: we optimize on a finite sample, but we are graded on the whole population.

02 — risk

Empirical Risk vs. Expected Risk

Let f_θ(x) be the model with parameters θ, and let L be a loss function — mean squared error for regression, cross-entropy for classification. What the optimizer can actually compute is the average loss over the training set:

empirical (training) risk
R̂(θ) = (1/n) Σᵢ L(f_θ(xᵢ), yᵢ)

Training minimizes exactly this quantity: θ* = argmin_θ R̂(θ). But what we actually care about is the loss averaged over the entire population:

expected (generalization) risk
R(θ) = E₍X,Y₎~P [ L(f_θ(X), Y) ]
✦
The central problem
R̂(θ) ≠ R(θ). We can only ever observe the left-hand side. Every technique described below exists to keep the two from drifting apart.
figure — risk meter
Two numbers that should agree, and usually don't
0.06 R̂(θ) training
0.09 R(θ) expected
G = 0.03 generalization gap

03 — definition

What Overfitting Actually Means

With that vocabulary, overfitting has a precise definition: it is what happens when a model finds a setting of θ with very low empirical risk but comparatively high expected risk — R̂(θ) ↓ while R(θ) ↑. As complexity increases from zero, both curves fall together, because the model is learning real structure. Past some point, the model has run out of real structure to learn and starts absorbing whatever is left: noise, outliers, and coincidences specific to this particular sample. Training risk keeps falling — there is always more noise to memorize — but expected risk turns around and climbs.

figure — the central curve of this article
Training risk vs. expected risk, as a function of model complexity
model complexity →risksweet spotoverfitting zone
training risk R̂(θ)
expected risk R(θ)
R̂=0.09 · R=0.22 · gap=0.13
Drag your pointer across the plot. To the right of the dashed line, the model is still improving on the data it was trained on — and getting worse everywhere else.

04 — capacity

Why Model Complexity Matters

Concretely: fit a set of points with a degree-1 polynomial (y = w₀ + w₁x) and it has almost no freedom to misbehave — it can only underfit. Give it degree 20 (y = w₀ + w₁x + ... + w₂₀x²⁰) and it has enough free parameters to pass through nearly every training point exactly, f(xᵢ) = yᵢ for almost every i. Training error can be driven to zero. Test error has no reason to follow — the extra freedom was spent threading a needle through noise, not learning the underlying trend.

figure — interactive
Fit a polynomial to noisy data — and watch it break
xy
training points
held-out (test) points
true f(x)
fitted model f̂(x)
3good fit
TRAIN MSE
0.009
TEST MSE
0.009
14 fixed training points (blue) sample a true curve (dashed green) plus noise. Drag the degree slider up: training MSE keeps falling while test MSE (measured on 12 held-out points, red) turns around and explodes — the model is now fitting the noise, not the signal.

05 — capacity

Hypothesis Space

The formal name for "the set of functions a learning algorithm is capable of producing" is its hypothesis space, H. Linear models, polynomials, and deep networks form a strict nesting: H_linear ⊂ H_polynomial ⊂ H_deep nets. A larger hypothesis space is more expressive — but if |H| ≫ n, many different functions in H can fit the training data perfectly. Some of those functions generalize; most, for a sufficiently large H, do not. The training loss alone cannot tell them apart — this is the theoretical root of why overfitting becomes possible in the first place.

figure — capacity
Nested hypothesis spaces
H_linearH_polynomialH_deep nets
H_polynomial
y = w₀ + w₁x + ... + wₖxᵏ. Strictly contains every linear model, plus every curve up to degree k.
Every point still on this page belongs to H_linear; a much larger region belongs to H_deep nets. Bigger circles can represent more functions that pass through any fixed sample.

06 — modern ML

The Interpolation Surprise: Double Descent

The classical story — more parameters, more overfitting — runs into trouble with modern deep networks. It is common for a network to have far more parameters than training examples (parameters ≫ n), drive training loss to essentially zero, and still generalize surprisingly well. Past the point where a model has exactly enough capacity to interpolate every training point (the interpolation threshold), test error can spike — and then, remarkably, start falling again as capacity keeps growing. This second decline is double descent, and it is one reason "more parameters always means more overfitting" is not, by itself, a theoretically adequate account of modern deep learning.

figure — toggle
The classical U-curve vs. the modern double-descent curve
model complexity (parameters) →test error
test error vs. model complexity

07 — decomposition

Bias–Variance Decomposition

For squared error, expected prediction error decomposes cleanly:

the bias–variance–noise decomposition
Expected Error = Bias² + Variance + Irreducible Noise

Bias is systematic error from an overly restrictive hypothesis space — forcing y = w₀ + w₁x onto data that truly follows y = x³ + ε leaves error the model can never fit away, no matter how much data it sees. That is underfitting. Variance measures how much the fitted model changes when the training sample changes: retrain five times on five slightly different samples and check how far apart the five resulting models land. A model that swings wildly between re-samples has high variance — and high variance is the statistical signature of overfitting.

figure — five re-fits, one target
Bias and variance, made visible
Low bias · Low variance
Low bias · High variance
High bias · Low variance
High bias · High variance

Each dot is where a model — retrained on a slightly different sample — lands. Tight clusters mean low variance; clusters centered on the bullseye mean low bias. Overfitting models sit in the high-variance column.

Each dot is a model retrained on a different sample of the same underlying data. Tight clusters = low variance. Clusters centered on the bullseye = low bias. Overfit models cluster in the top-right: scattered, and lucky (or unlucky) to be near the truth at all.

08 — sample size

Why Small Datasets Invite Overfitting

Degrees of freedom are relative. Twenty training examples against a model with ten thousand parameters leaves enormous room for the optimizer to discover relationships that are purely accidental — " athletes with shoe size 10.5 tend to perform better" is a correlation a flexible enough model can and will find, given a small enough sample, purely from sampling noise. This is exactly the regime the polynomial-fitting figure above demonstrates: 14 points and an 11-degree polynomial is already enough freedom to chase noise instead of signal. The fix is rarely "a smarter model" — it's more data, a smaller hypothesis space, or deliberate regularization.

09 — the mechanism

Fitting the Noise

Suppose the real generative process is y = f(x) + ε, where ε is irreducible noise. The ideal model recovers f(x). An overfit model instead learns f̂(x) = f(x) + g(x), where g(x) is a function that happens to explain this sample's particular noise draw. It satisfies f̂(xᵢ) ≈ yᵢ beautifully — of course it does, it was built to. But g(x) was fit to noise that will never repeat, so at a new point x_new, f̂(x_new) can be arbitrarily poor.

figure — the arithmetic of a data point
Decomposing an observation
signal f(x)
+
noise ε
=
observed y

10 — the fix

Regularization

Instead of minimizing empirical risk alone, regularization adds an explicit complexity penalty:

regularized objective
J(θ) = R̂(θ) + λ · Ω(θ)

For L2 ("weight decay"), Ω(θ) = ||θ||²₂ — large weights get taxed, so the optimizer only uses them when the data really demands it. Between two functions that fit the training data similarly well, the one with smaller, smoother weights wins. That preference — smooth over oscillatory — is an inductive bias, injected on purpose. Weight decay is one route to it; so are dropout (randomly zeroing neurons during training so the network can't over-rely on any one of them), data augmentation (training on deliberate variations of each example so the model learns invariances instead of exact pixels), and early stopping, below.

figure — interactive
Turning up λ smooths the fit and shrinks the weights
0.00
f(x) — Ω(θ) penalizes the oscillatory, high-magnitude fit
weight magnitudes |θᵢ| under weight decay
θ0
θ1
θ2
θ3
θ4
θ5
At λ = 0 the curve chases every wiggle available to it. As λ grows, the L2 penalty makes large, oscillatory weights expensive — the fit relaxes toward something smoother, and every weight magnitude shrinks toward zero.

11 — the fix

Early Stopping & the Optimization Path

Rather than optimizing until training loss is fully minimized, stop when validation performance stops improving. This works because the optimization trajectory itself has a shape: early epochs learn broad, general structure; late epochs increasingly chase sample-specific noise. Stopping early is a way of capping model complexity through the training process, rather than through the architecture — which is part of why optimization itself can act as a form of regularization.

figure — animated training run
Training loss keeps improving. Validation loss doesn't.
early-stop hereepoch →loss
training loss
validation loss
Past roughly epoch 48, every further step reduces training loss while validation loss climbs — pure overfitting, visible directly in the optimization trace.

12 — workflow

Train / Validation / Test Discipline

A dataset should really be three: D = D_train ∪ D_val ∪ D_test. The test set is used exactly once, at the end — repeatedly tuning against it turns it into a second validation set, and generalization claims made against it quietly stop being true. This is test-set overfitting, and it is a failure mode of the researcher, not the model.

figure — click a segment
What each split is actually for
Train: Used to estimate θ — the weights the optimizer actually adjusts.

13 — measurement

The Generalization Gap

Formally, the generalization gap is the difference between the two risks from section 2:

generalization gap
G = R(θ) − R̂(θ)

An overfit model has a large, positive G. If R̂ = 0.01 but R = 0.25, then G = 0.24: the model fits the observed sample almost perfectly and performs poorly on everything else. Watching G — not training loss alone — is the honest way to monitor overfitting during development.

figure — worked example
A concrete generalization gap
0.01 R̂(θ) training
0.25 R(θ) expected
G = 0.24 generalization gap

14 — theory

VC Dimension & PAC Learning

Statistical learning theory asks a sharper question: under what conditions does low training error imply low test error? One classical tool is VC dimension, which roughly measures how many points a hypothesis class can "shatter" — label in every possible way. Higher capacity means a greater ability to fit arbitrary training labels, but it does not automatically mean worse generalization; that also depends on dataset size, regularization, the data distribution, and the optimization procedure. PAC ("probably approximately correct") learning formalizes this into guarantees: with enough samples relative to a hypothesis class's capacity, low empirical risk is probably close to low expected risk.

15 — modern nuance

Effective Complexity ≠ Parameter Count

A network with a billion parameters can behave as though its effective complexity is far lower than its raw parameter count suggests, because gradient descent doesn't explore the hypothesis space uniformly — it has its own preferences, an implicit regularization baked into the optimization dynamics themselves.

▲
Parameter count is not the whole story
parameter count ≠ effective complexity. This is precisely why "more parameters always means more overfitting" breaks down for modern deep networks — see double descent, above.

16 — the deepest idea

The Deepest Idea: Inductive Bias

Model complexity is only the most common cause of overfitting — it isn't the deepest one. The deepest problem is this: the training data does not, by itself, determine which function will perform well on unseen data. Two functions can agree perfectly on every training point — f₁(xᵢ) = f₂(xᵢ) = yᵢ for every i, so R̂(f₁) = R̂(f₂) = 0 — and still disagree arbitrarily everywhere else.

figure — the limits of training loss
Two functions, zero training loss, and no way to tell them apart from the data alone
f₂(x)f₁(x)
Both curves pass through every blue training point exactly. Training loss is 0 for both. Only something outside the loss function — an inductive bias — can prefer the smooth one.

Generalization, then, requires an inductive bias: something that tells the learning algorithm which of the many training-loss-minimizing solutions to prefer. That bias can come from the architecture, explicit regularization, the training algorithm itself, initialization, data augmentation, pretrained representations, feature engineering, the loss function, or the optimization dynamics. This is the fuller theoretical meaning of overfitting: not merely "too much capacity," but capacity without a bias telling the model what to prefer when the data alone can't decide.

17 — keep going

The Learning Hierarchy

If you want to go deeper on ML theory, this is roughly the order that builds on itself most cleanly:

figure — roadmap
Nine ideas, in the order that builds
Hover or tap a stage to see what it means.

Once these connect, "the model memorized the data" stops being an explanation and becomes what it always was: a surface description of something with real, learnable structure underneath.