Skip to content

Statistical Learning Theory

A model that fits its training data perfectly may know nothing. The central question of learning theory is: when does training performance become test performance? The answer is a theorem with three inputs; the amount of data, the size of the model class, and the quality of the best model in the class - and every generalisation guarantee ever sold for a learning system is an instance of it.

This page proves the two main routes to that theorem. The VC route counts how many dichotomies a class can realise; the Rademacher route measures how well the class correlates with random noise. Both bound the gap between empirical and true risk, and the gap is the entire subject: training loss minus test loss is exactly the quantity a practitioner cannot measure and a theorist bounds.

Fit a straight line to two points: any two points, no matter how they were generated, can be fit perfectly. The fit is meaningless because the model is flexible enough to fit anything. Fit a line to a million points: a perfect fit now means something, because the line had to be right about a million independent draws.

Learning theory quantifies that intuition. The “flexibility” is the class’s capacity; how many different labellings it can produce on nn points; and the theorem says the generalisation gap decays like the square root of capacity over data. Fitting anything with a capacity much larger than your sample size is fitting noise, and the bound will say so.

Definition. Let X\mathcal{X} be an input space, Y={−1,+1}\mathcal{Y} = \{-1, +1\} for classification, and let (X,Y)∼P(X, Y) \sim P be drawn i.i.d. from an unknown distribution PP. A hypothesis is a function h:X→Yh : \mathcal{X} \to \mathcal{Y}; a hypothesis class H\mathcal{H} is the set of candidates. The true risk of hh is

R(h)=P(Y≠h(X))=E[1(h(X)≠Y)],R(h) = P(Y \neq h(X)) = \mathbb{E}[\mathbf{1}(h(X) \neq Y)],

and the empirical risk on a sample S=((x1,y1),…,(xn,yn))S = ((x_1,y_1), \dots, (x_n,y_n)) is

R^S(h)=1n∑i=1n1(h(xi)≠yi).\hat R_S(h) = \frac{1}{n}\sum_{i=1}^{n} \mathbf{1}(h(x_i) \neq y_i).

Definition. Empirical risk minimisation (ERM) returns h^=arg⁡min⁡h∈HR^S(h)\hat h = \arg\min_{h \in \mathcal{H}} \hat R_S(h).

The learner never sees PP; only the sample. The gap R(h^)−R^S(h^)R(\hat h) - \hat R_S(\hat h) is a random variable, because h^\hat h is a function of the random sample, and the entire theory is bounds on that random variable holding uniformly over the class. Uniformity is not decoration: the learner selected h^\hat h using the same data that estimates its risk, so pointwise concentration; page 1’s Hoeffding; must be strengthened to hold for all hh at once. That strengthening is what the two routes below provide.

Definition. H\mathcal{H} is PAC-learnable if there is an algorithm and a function n(ϵ,δ)n(\epsilon, \delta) such that for every distribution PP and every h∗∈Hh^* \in \mathcal{H}, given n≥n(ϵ,δ)n \geq n(\epsilon, \delta) i.i.d. samples labelled by h∗h^*, the algorithm returns h^\hat h with P(R(h^)≤ϵ)≥1−δP(R(\hat h) \leq \epsilon) \geq 1 - \delta.

Probably Approximately Correct: probability ≥1−δ\geq 1 - \delta that the risk is at most ϵ\epsilon. Both parameters are honest; “probably” and “approximately” are what the mathematics delivers, and neither is decorative.

Theorem (finite-class bound). If ∣H∣|\mathcal{H}| is finite, ERM satisfies, for every distribution PP and every h∗∈Hh^* \in \mathcal{H},

P(R(h^)>min⁡h∈HR(h)+ϵ)≤2∣H∣ e−nϵ2/2.P\big(R(\hat h) > \min_{h \in \mathcal{H}} R(h) + \epsilon\big) \leq 2|\mathcal{H}|\, e^{-n\epsilon^2/2}.

Proof. For a fixed hh, the errors 1(h(xi)≠yi)\mathbf{1}(h(x_i) \neq y_i) are i.i.d. Bernoulli with parameter R(h)R(h), so by Hoeffding’s inequality; page 1’s tool, applied to bounded variables -

P(R^S(h)>R(h)+ϵ/2)≤e−nϵ2/2.P\big(\hat R_S(h) > R(h) + \epsilon/2\big) \leq e^{-n\epsilon^2/2}.

Call hh “bad” if R(h)>R(h∗)+ϵR(h) > R(h^*) + \epsilon; for bad hh, R^S(h)>R(h∗)+ϵ/2\hat R_S(h) > R(h^*) + \epsilon/2 must hold for h^=h\hat h = h to be the ERM choice, since R^S(h∗)≤R(h∗)+ϵ/2\hat R_S(h^*) \leq R(h^*) + \epsilon/2 also holds with probability 1−e−nϵ2/21 - e^{-n\epsilon^2/2}. Union-bound over the ∣H∣|\mathcal{H}| hypotheses:

P(∃ bad h with R^S(h)≤R(h∗)+ϵ/2)≤∣H∣ e−nϵ2/2,P(\exists\ \text{bad } h \text{ with } \hat R_S(h) \leq R(h^*) + \epsilon/2) \leq |\mathcal{H}|\, e^{-n\epsilon^2/2},

and on the complement, ERM’s choice satisfies R(h^)≤R(h∗)+ϵR(\hat h) \leq R(h^*) + \epsilon. Doubling the exponent for the second Hoeffding application gives the display. ■\blacksquare

Read the bound’s shape. Sample size scales as n=O(ϵ−2log⁡(∣H∣/δ))n = O(\epsilon^{-2}\log(|\mathcal{H}|/\delta)); squared in the accuracy (ε appears squared in the exponent), logarithmic in the confidence (δ inside a log), and linear in the class size. The linear dependence is what the infinite case must replace, and replacing a class size by a combinatorial quantity is the VC theory’s contribution.

Definition. A set of points {x1,…,xm}\{x_1, \dots, x_m\} is shattered by H\mathcal{H} if H\mathcal{H} realises all 2m2^m labellings of them. The VC dimension VC(H)\mathrm{VC}(\mathcal{H}) is the largest mm for which some mm-point set is shattered.

Examples. Intervals on the real line: VC dimension 2 (two points can be shattered; label the outer pair positive, inner pair negative; three cannot - the outer two positive, middle negative is unrealisable). Linear classifiers in Rn\mathbb{R}^n: VC dimension n+1n + 1. Axis-aligned boxes in Rn\mathbb{R}^n: 2n2n.

Theorem (Sauer’s lemma). Let ΠH(m)\Pi_{\mathcal{H}}(m) be the maximum number of dichotomies H\mathcal{H} realises on any mm points. Then for m≥VC(H)m \geq \mathrm{VC}(\mathcal{H}) and m≥1m \geq 1:

ΠH(m)≤(e md)d,d=VC(H).\Pi_{\mathcal{H}}(m) \leq \Big(\frac{e\,m}{d}\Big)^{d}, \qquad d = \mathrm{VC}(\mathcal{H}).

Proof. By induction on the pair (d,m)(d, m), ordered lexicographically. For d=0d = 0 the class contains one function and Π(1)=1=(em/0)0\Pi(1) = 1 = (em/0)^0 interpreted as 1.

For the step, fix a set SS of mm points shattered to the maximum and let Π(m)\Pi(m) count dichotomies on it. Call a dichotomy’s restriction to S′=S∖{xm}S' = S \setminus \{x_m\} ambiguous if both extensions to xmx_m occur among the dichotomies of SS. The dichotomies on SS are: ambiguous ones (each counting twice) plus unambiguous ones. The ambiguous restrictions are shattered by H\mathcal{H} on S′S' in the strong sense; both labels achievable on xmx_m means both labels achievable everywhere; so their count is at most ΠH(m−1)\Pi_{\mathcal{H}}(m - 1). The unambiguous restrictions, projecting SS onto S′S' injectively, are at most Π(m−1)\Pi(m-1)-style counted on S′S' with the same dd… and the cleanest route to the standard bound is the two-part recursion

Π(m)≤Π(m−1,d)+Π(m−1,d−1),\Pi(m) \leq \Pi(m - 1, d) + \Pi(m - 1, d - 1),

splitting by whether the restriction set is shattered on dd or needs a new dimension. Applying the inductive hypothesis to both terms and simplifying with the binomial identity (m−1k)+(m−1k−1)=(mk)\binom{m-1}{k} + \binom{m-1}{k-1} = \binom{m}{k} gives

Π(m)≤∑k=0d(mk),\Pi(m) \leq \sum_{k=0}^{d} \binom{m}{k},

and for m≥dm \geq d the sum is bounded by (em/d)d(em/d)^d by the standard exponential bound on the binomial partial sum. ■\blacksquare

The growth is polynomial in mm of degree dd; not the exponential 2m2^m of an unconstrained class. That is the entire content: a class of finite VC dimension, however infinite as a set, grows only polynomially, and polynomial growth is slow enough for uniform concentration.

Theorem (VC generalisation bound). With probability 1−δ1 - \delta, every h∈Hh \in \mathcal{H} satisfies

R(h)≤R^S(h)+8n(dln⁡2end+ln⁡4δ).R(h) \leq \hat R_S(h) + \sqrt{\frac{8}{n}\Big(d \ln\frac{2en}{d} + \ln\frac{4}{\delta}\Big)}.

Proof sketch. The gap R(h)−R^S(h)R(h) - \hat R_S(h) is bounded by a symmetrisation argument: introduce a ghost sample S′S' and symmetrise so the supremum runs over a finite set of 2m2m points, on which the union bound plus Hoeffding applies with ΠH(2m)\Pi_{\mathcal{H}}(2m) replacing ∣H∣|\mathcal{H}|; Sauer’s lemma converts ΠH(2m)\Pi_{\mathcal{H}}(2m) into the polynomial bound, and solving for nn gives the display. The symmetrisation is the step that replaces “all hh” by “all dichotomies on 2n2n points”, and it is the same move as page 4’s fixed-alternative reduction. ■\blacksquare

VC counts dichotomies; Rademacher complexity measures something finer; the class’s ability to correlate with noise on the actual sample.

Definition. The empirical Rademacher complexity of H\mathcal{H} on SS is

R^S(H)=Eσ[sup⁡h∈H1n∑i=1nσi h(xi)],\hat{\mathfrak{R}}_S(\mathcal{H}) = \mathbb{E}_\sigma\left[ \sup_{h \in \mathcal{H}} \frac{1}{n}\sum_{i=1}^{n} \sigma_i\, h(x_i) \right],

where σ1,…,σn\sigma_1, \dots, \sigma_n are i.i.d. uniform ±1\pm 1.

It is the expected best achievable correlation with random labels. A class that can fit any labelling has complexity near 1; a singleton class has complexity 0.

Theorem (Rademacher generalisation). With probability 1−δ1 - \delta, for all h∈Hh \in \mathcal{H}:

R(h)≤R^S(h)+2 R^S(H)+3ln⁡(2/δ)2n.R(h) \leq \hat R_S(h) + 2\,\hat{\mathfrak{R}}_S(\mathcal{H}) + 3\sqrt{\frac{\ln(2/\delta)}{2n}}.

Proof sketch. Symmetrise with a ghost sample, introducing the Rademacher variables; apply McDiarmid’s bounded-difference inequality; the boundedness of the loss means changing one sample changes the supremum by at most 2/n2/n; to concentrate the data-dependent part around its expectation; and contract by Massart’s finite-class lemma to move the supremum inside. Each step is a named inequality with hypotheses that hold for bounded losses. ■\blacksquare

The two routes differ in what they measure and therefore what they predict. VC is a property of the class alone; data-independent, worst-case over distributions, and loose for classes that are only flexibly-shaped on the data distribution. Rademacher is data-dependent: on easy data, a rich class has low complexity, and the bound tightens accordingly. The price is that Rademacher complexity is an expectation that must be estimated, while VC dimension is a combinatorial fact.

5. Regularisation as constrained optimisation

Section titled “5. Regularisation as constrained optimisation”

The generalisation bound suggests a recipe: bound the capacity. For linear classes, capacity is controlled by the norm of the weight vector; and adding a norm penalty to the empirical risk is mathematically identical to constraining the norm:

min⁡w1n∑iℓ(w,xi,yi)+λ∥w∥2⟺min⁡w1n∑iℓ(w,xi,yi) s.t. ∥w∥≤Bλ,\min_w \frac{1}{n}\sum_i \ell(w, x_i, y_i) + \lambda \|w\|^2 \quad\Longleftrightarrow\quad \min_w \frac{1}{n}\sum_i \ell(w, x_i, y_i) \ \text{s.t.}\ \|w\| \leq B_\lambda,

for a monotone correspondence between λ\lambda and BλB_\lambda (the constraint form’s Lagrangian). Ridge regression’s ∥w∥2\|w\|^2 penalty, lasso’s ∥w∥1\|w\|_1, and early stopping are all capacity control; the theory’s one recipe, expressed in the language of three different algorithms.

That is also the honest account of what “regularisation” is in deep learning. Norm penalties and early stopping fit the framework; dropout and data augmentation do not fit it cleanly, and the learning theory of deep networks is an open research area; which is where the course’s final page goes.

6. The code: VC dimension, and the gap measured

Section titled “6. The code: VC dimension, and the gap measured”

Python; shattering, and the VC dimension of intervals, empirically.

import numpy as np
from itertools import product
rng = np.random.default_rng(2026)
def shatterable(points, labeller):
"""Can this labelling family produce all 2**m dichotomies of `points`?"""
m = len(points)
for bits in product([False, True], repeat=m):
# `labeller` must realise this dichotomy for SOME parameter choice.
if not any(np.array_equal(labeller(points, p), bits) for p in candidates(m)):
return False
return True
def candidates(m):
return [a for a in np.linspace(0, 1, 201)]
def interval_labeller(points, a):
# An interval model: positive inside [a0, a1]. Search both endpoints
# coarsely -- this is the shattering search, exponential in m by nature.
for a0 in np.linspace(0, 1, 101):
for a1 in np.linspace(a0, 1, 101):
if all((a0 <= x <= a1) == y for x, y in zip(points, a)):
return True
return False
# Scan for the largest shatterable set: VC dimension of intervals on R is 2.
for m in (1, 2, 3):
pts = np.linspace(0.1, 0.9, m)
ok = any(shatterable(pts, interval_labeller) for _ in [0])
print(f"m = {m}: shatterable = {ok}")
# Expected: m = 1 True, m = 2 True, m = 3 False -- the class cannot label
# (positive, negative, positive), so VC dimension is exactly 2.

The exponential search is the point: shattering is a combinatorial property, checked by trying all dichotomies against all parameter settings, and its cost is why VC dimension is a theory tool; computed for parametric families in closed form, not searched for in practice.

Python; the generalisation gap, measured on a real split.

from sklearn.datasets import make_classification
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
X, y = make_classification(n_samples=4000, n_features=20,
n_informative=6, random_state=2026)
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.5, random_state=0)
for depth in [1, 3, 6, None]: # None = unlimited depth
clf = DecisionTreeClassifier(max_depth=depth).fit(Xtr, ytr)
tr, te = clf.score(Xtr, ytr), clf.score(Xte, yte)
print(f"depth={str(depth):5s} train acc {tr:.3f} test acc {te:.3f} "
f"gap {tr - te:+.3f}")
# Expected: the gap grows with depth -- capacity outrunning data -- until the
# unlimited tree interpolates the training set and its gap is largest.
  • Quoting a generalisation bound for the selected model. The bounds hold uniformly over the class; they do not license “my test error is within ε” for a model chosen after looking at test performance. Test-set reuse invalidates the guarantee, and the fix is a held-out set touched once.
  • Reading VC dimension as “number of parameters”. It is a combinatorial property and can be infinite for a one-parameter family, finite for a many-parameter one. The connection to parameter counting holds only in specific parametric families.
  • Expecting the bound to be tight. VC bounds are worst-case over distributions and notoriously loose; a factor of nn can sit unused. Their content is qualitative: capacity must be smaller than data, scaling as claimed. Rademacher bounds tighten this; both remain bounds.
  • Concluding “deep learning contradicts VC”. Overparameterised networks interpolate training data and still generalise; outside classical VC bounds, yes, and inside newer analyses (implicit regularisation of gradient descent, norm-based capacity) partially. That tension is the research frontier, not a refutation.
  • Using the test set for model selection. Each comparison against the test set is a hypothesis test at that set’s level; twenty comparisons at 5% expect one false winner. Nested cross-validation or a third held-out set is the repair.