Fig. 1 in words
Why a training score can be trusted, and when it cannot · same data as code 05
1 The price of choosing · 70 examples · 95% confidence
- bound ε = √(ln(2|H|/δ) / 2n) · median gap, best of |H| noise rules
- training-to-true gap, 0.0 to 0.4, against number of rules tried, |H| (log scale), 1 to 1 000 000
- bound: 0.162 for 1 rule · 142 cuts: 0.248 · ② · bound 0.354 at 1 000 000
- ① noise gap 0.286
2 Sprint 26 · width > 1.6
- error rate, 0.0 to 0.3: 0.043 train · 0.100 test ④ · 0.291 bound ③
- true error ≤ 0.291 at 95%, if the flowers are independent draws
- ε = 0.05 needs 1 729 flowers
01 One Fixed Rule Hoeffding
- For one rule fixed in advance, training error misses true error by ε or more with chance ≤ 2e⁻²ⁿᵋ² (Hoeffding 1963)
- More data shrinks ε like 1/√n
The rule must be fixed before the data arrive. ERM chooses after seeing them, so one rule is not the whole story.
02 The Price of Choice Union
- ERM picks among |H| rules, so all of them must stay close at once
- Then ε = √(ln(2|H|/δ) / 2n) (Shalev-Shwartz & Ben-David, Cor. 4.6)
- A million rules cost 2.2× the ε of one
Each rule I try is one more chance to fit noise.
03 Infinite Classes VC · PAC
- VC dimension counts how many points a class can label in every way (Vapnik & Chervonenkis 1971)
- PAC: probably (1 − δ) approximately (ε) correct (Valiant 1984)
“x > c means yes” has VC dimension 1: it cannot say yes to a low point and no to a higher one.
04 The Open Puzzle Frontier
- Large networks fit random labels perfectly, yet generalise on real ones (Zhang et al. 2017)
- Past the point of fitting every example, test error can fall again: “double descent” (Belkin et al. 2019)
The bounds stay true; for such models they are loose. This theory is still being written.
05 Try It Yourself PYTHON 3.13.15
sprint30_statistical_learning_theory.py
import numpy as np
from math import ceil, log, sqrt
from scipy.stats import binom
from sklearn.datasets import load_iris
n, delta = 70, 0.05 # 70 examples, 95% confidence
eps = lambda H: sqrt(log(2 * H / delta) / (2 * n))
# 1) pure noise: best of H coin-flip rules, 70 labels
for H in [1, 10**2, 10**4, 10**6]:
k = np.arange(n + 1) # errors
cdf = 1 - binom.sf(k, n, 0.5) ** H # P(best<=k)
best = np.searchsorted(cdf, 0.5) / n # median
print(f"{H:>7} best {best:.3f}",
f"gap {0.5 - best:.3f} bound {eps(H):.3f}")
# 2) Sprint 26 with 142 cuts fixed before the data
X, y = load_iris(return_X_y=True)
X, y = X[y > 0][:, 2:], y[y > 0] - 1
i = np.random.default_rng(26).permutation(100)
tr, te = i[:70], i[70:]
cuts = [(f, k / 10) for f in (0, 1) for k in range(71)]
err = lambda f, c, j: ((X[j, f] > c) != y[j]).mean()
f, c = min(cuts, key=lambda fc: err(*fc, tr))
lo, e = err(f, c, tr), eps(len(cuts))
print(len(cuts), "cuts:", ["length", "width"][f], ">", c)
print(f"train {lo:.3f} + {e:.3f} = {lo + e:.3f},",
f"test {err(f, c, te):.3f}")
need = log(2 * len(cuts) / delta) / (2 * 0.05 ** 2)
print("for eps = 0.05 the bound needs n =", ceil(need))
Output, as printed on the image
1 best 0.500 gap 0.000 bound 0.162
100 best 0.357 gap 0.143 bound 0.243
10000 best 0.271 gap 0.229 bound 0.304
1000000 best 0.214 gap 0.286 bound 0.354
142 cuts: width > 1.6
train 0.043 + 0.248 = 0.291, test 0.100
for eps = 0.05 the bound needs n = 1729
Run it. sprint30_statistical_learning_theory.py · versions, data and steps
Check: 0.500 − 0.214 = 0.286 · 0.354 ÷ 0.162 = 2.18 · ln(2·142/0.05) ÷ (2 · 0.05²) = 1 728.9 → 1 729. scipy 1.18.1 · scikit-learn 1.9.1
06 General Notes Practice
- A guarantee holds only under its assumptions: independent draws, one distribution
- Count every rule tried, the discarded ones too
- A loose bound still ranks choices: fewer rules, more data
Sprint 26 drew its 42 cuts from the training values. A grid fixed in advance keeps the count honest.
07 Mini Project Hands-on
- Simulate 70 random labels and 1 000 random rules
- Plot ε against n for |H| = 142
- Find the n that gives ε = 0.02
- Shatter 3 points with lines; try 4
ε = 0.02 needs 10 806 flowers. Lines can shatter 3 points in the plane, never 4.
R Trusted Sources
- Hoeffding (1963). Probability Inequalities for Sums of Bounded Random Variables. JASA 58(301), 13–30
- Vapnik & Chervonenkis (1971). On the Uniform Convergence of Relative Frequencies of Events to Their Probabilities. Theory Probab. Appl. 16(2), 264–280
- Valiant (1984). A Theory of the Learnable. Commun. ACM 27(11), 1134–1142
- Shalev-Shwartz & Ben-David (2014). Understanding Machine Learning: From Theory to Algorithms, ch. 4–6. CUP
- Zhang, Bengio, Hardt, Recht & Vinyals (2017). Understanding Deep Learning Requires Rethinking Generalization. ICLR
- Belkin, Hsu, Ma & Mandal (2019). Reconciling Modern Machine-Learning Practice and the Classical Bias–Variance Trade-Off. PNAS 116(32), 15849–15854
