Simple Algorithm
Machine Learning · Convergence · 26 min

No Free Lunch & Inductive Bias

Why every learner must assume something about the world.

Average over every way the world could label the examples you have not seen, and every learning algorithm, from a deep network to a coin flip, has exactly the same expected error. This lesson proves that uncomfortable fact in three forms (Wolpert's off-training-set theorem, the PAC theorem of Shalev-Shwartz and Ben-David, and the theorem for optimization), then shows what it does and does not mean: learning works because learners commit to assumptions, and Occam's razor is one assumption that can be turned into a theorem.

What you’ll learn

  • Prove that, averaged uniformly over target functions, every learner has expected off-training-set error exactly 1/21/2, and state Wolpert's no-free-lunch theorem.
  • State and prove the PAC no-free-lunch theorem: for every learner and every m<∣X∣/2m<\abs{\mathcal X}/2, some realizable distribution makes it err by at least 1/81/8 with probability at least 1/71/7.
  • State the no-free-lunch theorem for optimization and explain what it does and does not imply about real problems.
  • Define inductive bias, and derive an Occam bound from a weighted union bound over a prefix code.

Generalization needs an assumption

Let X\mathcal X be finite and labels binary. A training set fixes the labels of the inputs it contains and says nothing, logically, about the rest. The off-training-set (OTS) error, the error measured only on inputs outside the training set, isolates exactly the part of the problem that is generalization.

DerivationProof
  1. P(f(x)=1∣f(x1),…,f(xm))=12for every x∉{x1,…,xm}P\big(f(x)=1\mid f(x_1),\dots,f(x_m)\big)=\tfrac12\qquad\text{for every }x\notin\{x_1,\dots,x_m\}

    Under the uniform distribution on functions, the values f(x)f(x) at different inputs are independent fair coins. An unseen value is independent of everything the learner sees:

  2. P(h^(x)≠f(x))=E[P(h^(x)≠f(x)∣D,h^)]=12P\big(\hat h(x)\ne f(x)\big)=\E\Big[P\big(\hat h(x)\ne f(x)\mid\data,\hat h\big)\Big]=\tfrac12

    h^(x)\hat h(x) depends only on the training data and the learner's own randomness, both independent of the coin f(x)f(x). A guess independent of a fair coin matches it with probability 1/21/2:

  3. Ef[OTS error of A]=12for every learner A\E_f\big[\text{OTS error of }A\big]=\tfrac12\qquad\text{for every learner }A

    Average over the unseen inputs with any weights.

Wolpert (1996) proved the general form. For the 0–1 loss and off-training-set error, any two learning algorithms have the same expected error averaged uniformly over targets: there are as many targets on which AA beats BB as the reverse. He also drew the sharp corollary: without an assumption about the target, no combination of low training error, small VC dimension and a large training set guarantees small OTS error.

The PAC no-free-lunch theorem

Averages over targets can feel artificial. The PAC version needs no prior: it says that for every learner there is one bad distribution, and it keeps the labels noiseless so that the failure cannot be blamed on noise. Write RD(h)R_{\mathcal D}(h) for the 0–1 risk under a distribution D\mathcal D on X×{0,1}\mathcal X\times\{0,1\}.

DerivationProof
  1. max⁡i≤T ES∼Dim[RDi(A(S))] ≥ 14\max_{i\le T}\ \E_{S\sim\mathcal D_i^m}\big[R_{\mathcal D_i}(A(S))\big]\ \ge\ \tfrac14

    Take C⊆XC\subseteq\mathcal X with ∣C∣=2m\abs C=2m. There are T=22mT=2^{2m} functions f1,…,fT:C→{0,1}f_1,\dots,f_T:C\to\{0,1\}; let Di\mathcal D_i be uniform on CC with labels given by fif_i, so each Di\mathcal D_i is realizable. It suffices to show that the worst of them forces a large expected error:

  2. max⁡i1k∑j=1kRDi(A(Sji)) ≥ 1T∑i=1T1k∑j=1kRDi(A(Sji)) ≥ min⁡j1T∑i=1TRDi(A(Sji))\max_i\frac1k\sum_{j=1}^kR_{\mathcal D_i}\big(A(S_j^i)\big)\ \ge\ \frac1T\sum_{i=1}^T\frac1k\sum_{j=1}^kR_{\mathcal D_i}\big(A(S_j^i)\big)\ \ge\ \min_j\frac1T\sum_{i=1}^TR_{\mathcal D_i}\big(A(S_j^i)\big)

    There are k=(2m)mk=(2m)^m sequences of mm inputs from CC; write SjiS_j^i for sequence jj labeled by fif_i. A maximum is at least an average, and an average over jj is at least the minimum over jj:

  3. RDi(h) ≥ 12m∑r=1p1{h(vr)≠fi(vr)} ≥ 12⋅1p∑r=1p1{h(vr)≠fi(vr)}R_{\mathcal D_i}(h)\ \ge\ \frac1{2m}\sum_{r=1}^p\mathbf 1\{h(v_r)\ne f_i(v_r)\}\ \ge\ \frac12\cdot\frac1p\sum_{r=1}^p\mathbf 1\{h(v_r)\ne f_i(v_r)\}

    Fix jj. At least p≥mp\ge m points v1,…,vpv_1,\dots,v_p of CC are missing from sequence jj. Count errors only there; each point has probability 1/(2m)≥1/(2p)1/(2m)\ge1/(2p):

  4. 1T∑i=1TRDi(A(Sji)) ≥ 12⋅1p∑r=1p1T∑i=1T1{A(Sji)(vr)≠fi(vr)}=12⋅12=14\frac1T\sum_{i=1}^TR_{\mathcal D_i}\big(A(S_j^i)\big)\ \ge\ \frac12\cdot\frac1p\sum_{r=1}^p\frac1T\sum_{i=1}^T\mathbf 1\big\{A(S_j^i)(v_r)\ne f_i(v_r)\big\}=\frac12\cdot\frac12=\frac14

    Pair each fif_i with the function fi′f_{i'} that differs from it only at vrv_r. Both produce the same labeled sample, Sji=Sji′S_j^i=S_j^{i'}, so AA returns the same hh, and exactly one of the two is wrong at vrv_r. Averaged over ii, the error indicator at each vrv_r is exactly 1/21/2:

  5. P(θ>18) ≥ 1/4−1/81−1/8=17P\big(\theta>\tfrac18\big)\ \ge\ \frac{1/4-1/8}{1-1/8}=\frac17

    Finally, a reverse Markov inequality. For the worst ii, let θ=RDi(A(S))∈[0,1]\theta=R_{\mathcal D_i}(A(S))\in[0,1], with Eθ≥1/4\E\theta\ge1/4. Since Eθ≤P(θ>18)+18(1−P(θ>18))\E\theta\le P(\theta>\tfrac18)+\tfrac18\big(1-P(\theta>\tfrac18)\big):

Predict before you look

The last step generalizes: if θ∈[0,1]\theta\in[0,1] and Eθ≥μ\E\theta\ge\mu, then P(θ>a)≥(μ−a)/(1−a)P(\theta>a)\ge(\mu-a)/(1-a) for a<μa<\mu. Suppose a learner's error θ\theta has mean at least 0.40.4. What is the smallest possible value of P(θ>0.2)P(\theta>0.2), in percent?

Show the answer

25 %

(0.4−0.2)/(1−0.2)=0.25(0.4-0.2)/(1-0.2)=0.25. The bound is tight: let θ=1\theta=1 with probability 0.250.25 and θ=0.2\theta=0.2 otherwise. Then Eθ=0.25+0.15=0.4\E\theta=0.25+0.15=0.4 and P(θ>0.2)=0.25P(\theta>0.2)=0.25. A large mean error forces large errors to be reasonably likely, because the error cannot exceed 1.

Two corollaries follow at once. The class of all functions on an infinite domain is not PAC learnable, since the theorem applies at every sample size. And any class that contains all labelings of arbitrarily large sets, that is, any class of infinite VC dimension, is not PAC learnable: this is the lower-bound half of the fundamental theorem in the lesson VC Dimension & the Fundamental Theorem. Restricting the class is exactly the inductive bias that escapes the theorem: if the target is known to lie in a class of VC dimension dd, on the order of (d+ln⁡(1/δ))/ε(d+\ln(1/\delta))/\varepsilon examples suffice for the best learners (plain ERM may need (dln⁡(1/ε)+ln⁡(1/δ))/ε(d\ln(1/\varepsilon)+\ln(1/\delta))/\varepsilon).

No free lunch for optimization

DerivationWhy
  1. P(f(xt+1)=y∣f(x1),…,f(xt))=1∣Y∣(xt+1∉{x1,…,xt})P\big(f(x_{t+1})=y\mid f(x_1),\dots,f(x_t)\big)=\frac1{\abs{\mathcal Y}}\qquad(x_{t+1}\notin\{x_1,\dots,x_t\})

    For ff uniform over all functions X→Y\mathcal X\to\mathcal Y, the values at distinct points are independent and uniform on Y\mathcal Y:

  2. P(dmy∣m,a)=∣Y∣−mfor every algorithm aP\big(d_m^y\mid m,a\big)=\abs{\mathcal Y}^{-m}\qquad\text{for every algorithm }a

    The algorithm chooses xt+1x_{t+1} from what it has seen, but never a repeat, so the next value is again a fresh uniform draw. By induction on mm, the observed sequence is mm independent uniform values, whatever the algorithm:

  3. Multiplying by the number of functions, ∣Y∣∣X∣\abs{\mathcal Y}^{\abs{\mathcal X}}, turns this average into the sum in the theorem, the same for every algorithm.

Notice what is being averaged: all functions, almost all of which are incompressible noise with no exploitable structure. The objectives people actually optimize (training losses, physical systems, engineered designs) are very special: smooth, structured, compressible. On such classes algorithms differ greatly, which is why gradient descent beats random search on a convex loss. The lesson is that an algorithm's advantage always comes from assumptions about the problem class, stated or not; it is not that all algorithms are equally good in practice.

Even the formal statement is fragile outside its setting. For continuous search spaces, under the formalization studied by Auger and Teytaud (2010), the analogous theorem fails; their title says it plainly: "continuous lunches are free."

Check your understanding

Which reading of the no-free-lunch theorem for optimization is correct?

  1. Gradient descent is no better than random search on convex problems
  2. Random search is the best general-purpose optimizer
  3. Averaged uniformly over all functions on a finite domain, every non-repeating algorithm sees the same distribution of values, so an advantage on some functions is paid for on others
  4. Optimization without derivatives is impossible
Show the answer

C. Averaged uniformly over all functions on a finite domain, every non-repeating algorithm sees the same distribution of values, so an advantage on some functions is paid for on others

The theorem is an identity about uniform averages over all functions. Convex losses form a tiny, highly structured class, and on it gradient methods win decisively; the theorem only says that this advantage is balanced by losses elsewhere, on functions nobody needs to optimize.

Inductive bias and Occam's razor

If every learner must assume something, the useful question is which assumptions to make, and how to state them so that they can be checked. Biases come in two flavors, often called restriction and preference biases: restrict the hypothesis class (linear functions, trees of depth 3), or keep a large class and prefer some members (small norm, few nonzero weights, short descriptions).

AssumptionFormalized asWhere it appears
Smoothnessa bound on a Lipschitz constant or a kernel normkk-NN, kernel methods, Gaussian processes
Linearityh(x)=w⊤x+bh(\mathbf x)=\mathbf w^\top\mathbf x+blinear and logistic regression
Sparsityfew nonzero weights, an ℓ1\ell_1 penaltythe lasso
Invariance and equivarianceh(gx)=h(x)h(g\mathbf x)=h(\mathbf x) or h(gx)=g h(x)h(g\mathbf x)=g\,h(\mathbf x) for a group of transformations ggconvolutional and graph networks
Simplicitya prior weight 2−∣h∣2^{-\abs h} on a hypothesis described in ∣h∣\abs h bitsOccam bounds, minimum description length, PAC-Bayes

Occam's razor (prefer the simplest hypothesis consistent with the data) becomes a theorem once "simple" is fixed before the data arrive. Encode each hypothesis in a prefix-free binary code, with ∣h∣\abs h the length of the code word for hh. Kraft's inequality guarantees ∑h2−∣h∣≤1\sum_h2^{-\abs h}\le1.

DerivationProof: a weighted union bound
  1. P(∣R(h)−R^n(h)∣>ln⁡(2/δh)2n)≤δhP\Big(\abs{R(h)-\hat R_n(h)}>\sqrt{\tfrac{\ln(2/\delta_h)}{2n}}\Big)\le\delta_h

    Hoeffding's inequality for one fixed hh, at its own confidence level δh=δ 2−∣h∣\delta_h=\delta\,2^{-\abs h}:

  2. ∑h∈Hδh=δ∑h∈H2−∣h∣≤δ\sum_{h\in\mathcal H}\delta_h=\delta\sum_{h\in\mathcal H}2^{-\abs h}\le\delta

    Take a union bound over all of H\mathcal H. Kraft's inequality keeps the total failure probability below δ\delta, however many hypotheses there are:

  3. R(h)≤R^n(h)+∣h∣ln⁡2+ln⁡(2/δ)2nfor all h∈HR(h)\le\hat R_n(h)+\sqrt{\frac{\abs h\ln2+\ln(2/\delta)}{2n}}\qquad\text{for all }h\in\mathcal H

    Outside that event every hh obeys its own bound, and ln⁡(2/δh)=∣h∣ln⁡2+ln⁡(2/δ)\ln(2/\delta_h)=\abs h\ln2+\ln(2/\delta). Shorter code words buy tighter bounds; minimizing the right-hand side over hh is the minimum description length principle in its simplest form (Shalev-Shwartz & Ben-David, 2014, §7.3).

Blumer, Ehrenfeucht, Haussler and Warmuth (1987) proved an algorithmic version for the noise-free case: a learner that always outputs a hypothesis consistent with the data, whose description length grows sublinearly in the number of examples (an Occam algorithm), is a PAC learner. If you can compress the labels of a sample into a short consistent rule, you have learned.

Key takeaways

  • Averaged uniformly over all targets, every learner has expected off-training-set error exactly 1/21/2 (Wolpert, 1996): data alone never decide an unseen label.
  • PAC no-free-lunch: for any learner and m<∣X∣/2m<\abs{\mathcal X}/2, some realizable distribution makes it err by at least 1/81/8 with probability at least 1/71/7. Hence classes of infinite VC dimension are not PAC learnable.
  • For optimization (Wolpert & Macready, 1997), averaged over all functions on a finite domain, every non-repeating black-box algorithm sees the same distribution of values. Advantages come from assumptions about the problem class.
  • An inductive bias is "any basis for choosing one generalization over another, other than strict consistency with the observed training instances" (Mitchell, 1980), and it is unavoidable. Occam's razor becomes a theorem for a code fixed in advance: R(h)≤R^n(h)+(∣h∣ln⁡2+ln⁡(2/δ))/(2n)R(h)\le\hat R_n(h)+\sqrt{(\abs h\ln2+\ln(2/\delta))/(2n)} for all hh at once.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Targets are drawn uniformly from all Boolean functions on a finite X\mathcal X, and a learner sees the correct labels on half of X\mathcal X. What is its expected error on the other half?

  1. Lower for a well-regularized learner
  2. Exactly 1/21/2, for every learner
  3. Lower whenever its training error is zero
  4. It depends on the VC dimension of the learner's hypothesis class
Show the answer

B. Exactly 1/21/2, for every learner

Under the uniform prior each unseen label is a fair coin independent of the training data, so every prediction is right with probability 1/21/2, whatever the learner does.

Question 2

What does the PAC no-free-lunch theorem imply about the class of all functions on an infinite domain X\mathcal X?

  1. It is PAC learnable given enough data
  2. It is learnable by ERM but not by other algorithms
  3. It is not PAC learnable: at every sample size, some realizable distribution defeats any learner
  4. It is learnable in the agnostic model only
Show the answer

C. It is not PAC learnable: at every sample size, some realizable distribution defeats any learner

For any mm, pick 2m2m points of the infinite domain and apply the theorem: some distribution, realizable by a function in the class, forces error at least 1/81/8 with probability at least 1/71/7. No sample size works for every distribution.

Question 3

Two hypotheses have zero training error on n=10,000n=10{,}000 examples. One is described in 20 bits, the other in 2,000 bits, in a code fixed in advance. With δ=0.05\delta=0.05, what does the Occam bound say?

  1. Their risks are at most about 0.030.03 and about 0.260.26 respectively
  2. Both bounds are equal, because both training errors are zero
  3. The 2,000-bit hypothesis is safer, because it is more expressive
  4. The 20-bit hypothesis has a lower true risk
Show the answer

A. Their risks are at most about 0.030.03 and about 0.260.26 respectively

(20ln⁡2+ln⁡40)/20,000≈17.5/20,000≈0.030\sqrt{(20\ln2+\ln40)/20{,}000}\approx\sqrt{17.5/20{,}000}\approx0.030 and (2,000ln⁡2+ln⁡40)/20,000≈1,390/20,000≈0.26\sqrt{(2{,}000\ln2+\ln40)/20{,}000}\approx\sqrt{1{,}390/20{,}000}\approx0.26. The bounds differ; the true risks may not.

Question 4

An engineer says the no-free-lunch theorem proves that her carefully tuned optimizer cannot beat random search on her company's design problems. What is wrong with the argument?

  1. Nothing: the theorem applies to every optimization problem
  2. The theorem applies only to continuous domains
  3. The theorem is about learning, not optimization
  4. The theorem averages uniformly over all functions on a finite domain; on a structured class of problems, like hers, algorithms can differ greatly
Show the answer

D. The theorem averages uniformly over all functions on a finite domain; on a structured class of problems, like hers, algorithms can differ greatly

The equality holds for the uniform average over all objectives. Her design problems are a tiny, structured subset, and an optimizer whose assumptions fit that structure can beat random search there; the theorem only says the advantage is repaid on functions she will never meet.

Further reading

  • D. H. Wolpert, "The lack of a priori distinctions between learning algorithms," Neural Computation 8(7), 1341–1390 (1996).
  • D. H. Wolpert & W. G. Macready, "No free lunch theorems for optimization," IEEE Transactions on Evolutionary Computation 1(1), 67–82 (1997).
  • T. M. Mitchell, "The need for biases in learning generalizations," Technical Report CBM-TR-117, Rutgers University (1980).
  • A. Blumer, A. Ehrenfeucht, D. Haussler & M. K. Warmuth, "Occam's razor," Information Processing Letters 24(6), 377–380 (1987).
  • S. Shalev-Shwartz & S. Ben-David, Understanding Machine Learning: From Theory to Algorithms (Cambridge University Press, 2014), chapters 5 and 7.