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.
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:
Training minimizes exactly this quantity: θ* = argmin_θ R̂(θ). But what we actually care about is the loss averaged over the entire population:
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.
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.
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.
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.
07 — decomposition
Bias–Variance Decomposition
For squared error, expected prediction error decomposes cleanly:
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.
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.
10 — the fix
Regularization
Instead of minimizing empirical risk alone, regularization adds an explicit complexity penalty:
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.
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.
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.
13 — measurement
The Generalization Gap
Formally, the generalization gap is the difference between the two risks from section 2:
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.
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.
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.
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:
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.