§5.2–5.2.1Capacity, Overfitting and Underfitting · The No Free Lunch Theorem

Part I DL pp. 110–117 · ~4 min read

  • generalization
  • iid assumptions
  • underfitting
  • overfitting
  • capacity
  • hypothesis space
  • bayes error
  • no free lunch theorem

§5.2 The central challenge: generalization

Machine learning’s defining problem: perform well on new, previously unseen inputs generalization . Reducing training error is just optimization; machine learning begins when we also demand low generalization (test) error, the expected error on fresh draws from the input distribution, estimated on a held-out test set.

How can the training set tell us anything about the test set? Only under assumptions. The i.i.d. assumptions : examples are independent, and train and test are identically distributed — both generated by the same data-generating distribution pdatap_{\mathrm{data}}. Then for a fixed model the expected training and test errors coincide; but since we choose the parameters using the training set and only then sample the test set, expected test error ≥ expected training error. Everything reduces to two abilities:

  1. make the training error small — failing this is underfitting ;
  2. make the gap between training and test error small — failing this is overfitting .

Capacity — the knob between the two failures

We steer between them with capacity : a model’s ability to fit a wide variety of functions. One way to set it is the hypothesis space — which functions the learner may pick. Linear regression’s space is all linear functions; adding features x2,x3,x^2, x^3, \dots admits polynomials (y^=b+i=19wixi\hat{y} = b + \sum_{i=1}^9 w_i x^i for degree 9) — still linear in the parameters, so the normal equations keep working. Fig 5.2, live:

Figs 5.2 + 5.3 (interactive) — the true function is quadratic; slide the degree and watch the U-curve form
degree-1 fit blue: train pointserror vs capacity — the U-curve123456789testtrainpolynomial degree (capacity)

train 0.411 · test 0.526

underfitting

Degree 1 cannot capture the curvature (underfits); degree 2 matches the true structure and generalizes; degree 9 — with more parameters than training examples — threads every training point yet swings wildly between them: infinitely many wildly different solutions fit the data exactly, and we have little chance of picking one that generalizes. The right pane is fig 5.3’s U-curve: training error falls monotonically with capacity, generalization error falls then rises; between them the generalization gap widens past the optimal capacity.

Two refinements. Representational vs effective capacity: the model family defines what could be expressed, but imperfect optimization means the learner’s effective capacity may be less than the family’s representational capacity. And capacity isn’t only about how many functions — the identity of the functions matters (linear functions are great when the truth is near-linear, useless for sin(x)\sin(x)).

Aside — Occam, Vapnik, and why theory is quiet in DL

Occam’s razor (choose the simplest hypothesis that fits) was formalized by statistical learning theory: the VC dimension measures a binary classifier’s capacity as the largest m for which some m points can be labeled arbitrarily. The key theorems bound the train-test discrepancy by a quantity that grows with capacity and shrinks with m — intellectual justification that ML works at all. But the bounds are loose, and the effective capacity of deep models (tangled with non-convex optimization) is hard to pin down — so these tools are rarely used in deep learning practice.

Non-parametric models push capacity arbitrarily high: instead of a fixed-size parameter vector, their complexity grows with the data. Nearest-neighbor regression just stores the training set and answers with yiy_i for the closest stored Xi,:\boldsymbol{X}_{i,:} — with tie-averaging, it achieves the minimum possible training error on any dataset. The ideal model — an oracle knowing the true p(x,y)p(\boldsymbol{x}, y)still errs when the mapping is inherently stochastic or yy depends on unobserved variables: that floor is the Bayes error .

What more data does (fig 5.4)

As m grows: test error can only fall (in expectation); a fixed-capacity model’s training error RISES (bigger sets are harder to fit — and can dip below the Bayes error only by memorization); the optimal capacity grows, then plateaus once the task is solvable. Non-parametric models ride m all the way to the Bayes error; any fixed parametric model with less-than-optimal capacity asymptotes above it. And a large gap at optimal capacity is itself curable by more data.

§5.2.1 The no free lunch theorem

Inductive reasoning — inferring general rules from finitely many examples — is not logically valid; ML escapes by promising only probably correct rules about most members. Even so, the no free lunch theorem (Wolpert, 1996) bites: averaged over all possible data-generating distributions, every classification algorithm has the same error rate on unseen points. The most sophisticated algorithm conceivable ties, on average, with predicting one constant class.

The escape is the point: the results hold only for the average over all distributions. Real-world distributions are special, and the goal of ML research is not a universal best algorithm but understanding which distributions the real world serves up — and which algorithms do well on those. That reframing motivates the entire next section: regularization, the art of building the right preferences in.

Check yourself — capacity and free lunches

1.What separates machine learning from plain optimization?

2.In CapacityLab at degree 9, training error ≈ 0 but test error explodes. Why?

3.Why can a learner's EFFECTIVE capacity be less than its representational capacity?

4.What is the Bayes error?

5.The no free lunch theorem says all classifiers tie on average. Why doesn't this make ML pointless?

5 questions