vrishank

← Blog

Lecture 9: Approximation/Estimation Error and ERM

Stanford CS229 lecture 9 notes: Approximation/Estimation Error and ERM.

· 2 min read

  • cs229
  • machine-learning
  • course-notes
On this page

This is the learning theory lecture. The question: can we say anything provable about when learning works?

Setting up#

  • Data (x(i),y(i))(x^{(i)}, y^{(i)}) is drawn i.i.d. from some distribution DD.
  • The training error (empirical risk): ε^(h)=1m∑i1{h(x(i))≠y(i)}\hat{\varepsilon}(h) = \frac{1}{m}\sum_i 1\{h(x^{(i)}) \neq y^{(i)}\}
  • The generalization error (true risk): ε(h)=P(x,y)∼D(h(x)≠y)\varepsilon(h) = P_{(x,y)\sim D}(h(x) \neq y)

We care about generalization error, but we can only measure training error.

Empirical Risk Minimization (ERM)#

Pick a hypothesis class H\mathcal{H} (e.g., all linear classifiers). ERM chooses the hypothesis with the lowest training error:

h^=arg⁡min⁡h∈Hε^(h)\hat{h} = \arg\min_{h \in \mathcal{H}} \hat{\varepsilon}(h)

Logistic regression, SVMs, and so on are all approximations of this (since minimizing 0-1 loss directly is hard).

Approximation vs Estimation error#

Define:

  • gg = the best possible hypothesis overall (the "Bayes optimal" one)
  • h∗h^* = the best hypothesis in our class H\mathcal{H}
  • h^\hat{h} = what ERM actually gives us from the finite data

Then we can break down the error:

ε(h^)=ε(g)⏟irreducible error+ε(h∗)−ε(g)⏟approximation error+ε(h^)−ε(h∗)⏟estimation error\varepsilon(\hat{h}) = \underbrace{\varepsilon(g)}_{\text{irreducible error}} + \underbrace{\varepsilon(h^*) - \varepsilon(g)}_{\text{approximation error}} + \underbrace{\varepsilon(\hat{h}) - \varepsilon(h^*)}_{\text{estimation error}}
  • Approximation error: the penalty for restricting ourselves to H\mathcal{H}. Bigger class means smaller approximation error.
  • Estimation error: the penalty for having only finite data. Bigger class means larger estimation error.

This lines up with what we saw before: approximation error is bias, estimation error is variance.

Two tools: Union bound and Hoeffding#

Union bound: P(A1∪⋯∪Ak)≤∑iP(Ai)P(A_1 \cup \dots \cup A_k) \leq \sum_i P(A_i)

Hoeffding inequality: if ϕ^\hat{\phi} is the average of mm i.i.d. Bernoulli(ϕ\phi) variables, then

P(∣ϕ−ϕ^∣>γ)≤2exp⁡(−2γ2m)P(|\phi - \hat{\phi}| > \gamma) \leq 2\exp(-2\gamma^2 m)

In plain words, the more samples you have, the exponentially less likely it is that your estimate is far off.

Uniform convergence (finite H\mathcal{H})#

Suppose H\mathcal{H} has kk hypotheses. For one fixed hh, Hoeffding says its training error is close to its true error. Using the union bound over all kk hypotheses:

P(∃h∈H:∣ε(h)−ε^(h)∣>γ)≤2kexp⁡(−2γ2m)P\left(\exists h \in \mathcal{H}: |\varepsilon(h) - \hat{\varepsilon}(h)| > \gamma\right) \leq 2k\exp(-2\gamma^2 m)

So with probability at least 1−δ1-\delta, all hypotheses have training error within γ\gamma of true error, as long as:

m≥12γ2log⁡2kδm \geq \frac{1}{2\gamma^2}\log\frac{2k}{\delta}

This is the sample complexity: how much data you need. The cool part is that it grows only with log⁡k\log k.

And then the ERM guarantee: with probability 1−δ1-\delta,

ε(h^)≤ε(h∗)+2γ\varepsilon(\hat{h}) \leq \varepsilon(h^*) + 2\gamma

meaning ERM is within 2γ2\gamma of the best hypothesis in the class.

Infinite classes and VC dimension#

Linear classifiers have infinitely many hypotheses, so log⁡k\log k is useless. But a dd-parameter model can be treated as having effectively k≈k \approx (some finite number) when computed on a computer with finite precision, which gives a sample complexity that's roughly linear in the number of parameters dd.

The proper tool is the VC dimension: the size of the largest set of points that the class can shatter (label in every possible way). For linear classifiers in Rn\mathbb{R}^n, VC dimension is n+1n + 1. The takeaway is that the number of examples you need scales roughly linearly with VC dimension.