GNGiseldo Neo and Alana NeoBooks
Mathematical Foundations for Machine Learning4 / 8

How Well Do We Learn?

In the previous chapters, we defined learning as the construction of a hypothesis from a finite sample. We also distinguish the error observed in the training data from the expected error in future examples. Now we face the quantitative question: when the observed error provides reliable information about the true error?

Consider a hh hypothesis and an i.i.d. sample.

D={(xi,yi)}i=1N∼PN. D=\{(x_i,y_i)\}_{i=1}^{N} \sim P^N.

For a limited loss, we calculated the empirical risk

R^D(h)=1N∑i=1Nℓ(h(xi),yi), \widehat{R}_D(h) =\frac{1}{N}\sum_{i=1}^{N}\ell(h(x_i),y_i),

but we want to know the expected risk

RP(h)=E(X,Y)∼P[ℓ(h(X),Y)]. R_P(h) =\mathbb{E}_{(X,Y)\sim P} \bigl[\ell(h(X),Y)\bigr].

As PP is unknown, RP(h)R_P(h) cannot be calculated directly. Generalization theory studies the difference

∣R^D(h)−RP(h)∣. \bigl|\widehat{R}_D(h)-R_P(h)\bigr|.

A small difference indicates that the sample estimates the performance of the hypothesis well. A large difference means that the result observed may be a misleading description of the population.

The first difficulty: the sample is random. If we repeat the collection, we will obtain other examples and other empirical risk. We need a probabilistic statement that limits the chance of a large deviation. Hoeffding inequality will fulfill this role for means of independent and limited variables.

The second difficulty: the hypothesis also depends on the sample. Hoeffding directly controls a hypothesis fixed before observing the data. An algorithm, however, examines the data and chooses

h^=A(D). \widehat{h}=A(D).

If we look among many hypotheses, some may seem good only by chance. This effect is similar to throwing many coins and selecting the one that presented the highest proportion of faces: the selection makes the extreme result less surprising.

The third difficulty: many classes are infinite. There are infinite straight, flat and combinations of real weights. We can’t just count all the elements of H\mathcal{H}. We need to measure how many distinct behaviors the class can produce over a finite sample.

The Vapnik–Chervonenkis dimension, or VC dimension, measures this capacity in binary classification. It is the largest size of a set that can be shattered by the class: all its binary labels can be performed by some hypothesis.

For linear classifiers in the plane, the VC dimension is 33:

  • there are three points that can receive any labels and still be separated by a straight line;
  • no set of four points can perform, by straight lines, all possible 242^4 labels.

The four vertices of a square with alternate labels form the known XOR pattern and show a labeling that a line does not separate. To conclude that the dimension is 33, however, we still need to argue that all four-point set fails in some labeling, not just display a particular set.

The script of the chapter. We will develop the analysis in steps:

  1. we will understand the defect of selecting hypotheses using the same sample in which we measured the error;
  2. We will apply Hoeffding’s inequality to a fixed hypothesis and then to finite classes;
  3. We will replace the cardinality of an infinite class with the number of labels it induces in finite samples;
  4. we will define VC dimension and obtain capacity-dependent generalization bounds.

A typical guarantee will have the form

PD(sup⁡h∈H∣R^D(h)−RP(h)∣>ε)≤δ. P_D\left( \sup_{h\in\mathcal{H}} \bigl|\widehat{R}_D(h)-R_P(h)\bigr| >\varepsilon \right) \leq\delta.

The supreme requires that the approach be valid simultaneously for all hypotheses. This allows you to choose a hypothesis after observing the sample without losing the warranty.

3.0.1 Capacity, data and trust

The bounds will reveal three general dependencies:

  • greater accuracy, that is, smaller ε\varepsilon, requires more examples;
  • greater confidence, that is, smaller δ\delta, requires more examples;
  • a more expressive class requires more examples to control selection and overfit.

These relationships do not justify universal rules such as “ten examples per parameter”. The amount required depends on loss, effective capacity, distribution, noise and the type of guarantee. Theoretical bounds of worst case may be conservative, but their structure explains what factors make learning more difficult.

3.0.2 What bounds can and cannot do

A generalization bound does not automatically choose the best representation, does not correct incorrect labels and does not guarantee stability when distribution changes. It answers a conditional question: under certain hypotheses, what is the probability that empirical performance differs greatly from expected?

We must also distinguish:

  • theoretical bound: valid for a family of situations, often conservative;
  • experimental estimate: calculated in validation or test for a concrete model and set.

The theory explains why the procedure can generalize; the evaluation measures how a specific implementation behaved.

A change of perspective

The problem is not just finding a hypothesis with low training error. It is controlling how many opportunities the algorithm had to find an accidental adjustment and demonstrating that the low error contains information about new data.

3.0.3 Motivating example: multiple coins

Suppose MM honest coins, each launched NN times. For a coin fixed before the experiment, the frequency of faces tends to get close to 1/21/2. However, if we choose later the coin with less frequency of faces, the selected value will be more extreme as MM grows.

The selected currency plays the role of the hypothesis chosen by the algorithm. Each individual currency has good concentration, but controlling the selection requires considering all candidates. For a finite set, we will do this with the union bound; for infinite classes, we will use combinatorial capacity.

3.0.4 Preparing questions

  1. Differentiate empirical risk and expected risk.
  2. Why cannot a guarantee for a fixed hypothesis be applied directly to A(D)A(D)?
  3. How does increasing the amount of chances affect the chance to find an accidental fit?
  4. What does it mean to break a set?
  5. Why does the four-point XOR pattern alone not complete the proof that flat lines have VC dimension equal to 33?
  6. Explain why there is no universal rule of examples per parameter.

3.1 Defect

Given a hh hypothesis, we can calculate your empirical risk in the sample,

R^D(h), \widehat{R}_D(h),

But not your exact expected risk,

RP(h), R_P(h),

because the PP distribution is unknown. We will call generalization gap — or, following the historical terminology of this text, defect — the difference

ΔD(h)=RP(h)−R^D(h). \Delta_D(h) = R_P(h)-\widehat{R}_D(h).

Identity

RP(h)=R^D(h)+ΔD(h) R_P(h) = \widehat{R}_D(h)+\Delta_D(h)

shows the two ingredients of a good result: small training error and controlled gap.

3.1.1 Signed gap and absolute gap

ΔD(h)\Delta_D(h) is a signed quantity:

  • ΔD(h)>0\Delta_D(h)>0: training underestimated the true error;
  • ΔD(h)<0\Delta_D(h)<0: training overestimated the true error;
  • ΔD(h)≈0\Delta_D(h)\approx0: the sample estimated the risk well.

For a guarantee that doesn’t depend on the steering, we use

∣RP(h)−R^D(h)∣. \left| R_P(h)-\widehat{R}_D(h) \right|.

So,

RP(h)≤R^D(h)+∣RP(h)−R^D(h)∣. R_P(h) \leq \widehat{R}_D(h) + \left| R_P(h)-\widehat{R}_D(h) \right|.

We do not try to “minimize the gap” directly, because it involves RP(h)R_P(h), which we do not know. We try to demonstrate that it is small with high probability.

3.1.2 Binary classification

For Y={−1,+1}Y=\{-1,+1\} and zero-one loss,

R^D(h)=1N∑i=1N1[h(xi)≠yi] \widehat{R}_D(h) = \frac{1}{N} \sum_{i=1}^{N} \mathbb{1}[h(x_i)\neq y_i]

e

RP(h)=P(X,Y)∼P(h(X)≠Y). R_P(h) = P_{(X,Y)\sim P} \bigl(h(X)\neq Y\bigr).

The first is the frequency of errors in NN examples; the second is the probability of error in a new example.

If R^D(h)=0,02\widehat{R}_D(h)=0{,}02 and a bound guarantees

∣RP(h)−R^D(h)∣≤0,03, \left|R_P(h)-\widehat{R}_D(h)\right| \leq0{,}03,

So…

RP(h)≤0,05. R_P(h)\leq0{,}05.

The bound does not say that the risk is exactly 5%5\%; it provides a higher limit.

3.1.3 A hypothesis fixed before the data

Suppose hh is chosen without observing DD. Each variable

Zi=1[h(xi)≠yi] Z_i = \mathbb{1}[h(x_i)\neq y_i]

It’s Bernoulli, average.

E[Zi]=RP(h). \mathbb{E}[Z_i]=R_P(h).

Empirical risk is the average

R^D(h)=1N∑i=1NZi. \widehat{R}_D(h) = \frac{1}{N}\sum_{i=1}^{N}Z_i.

A concentration inequality can then limit the probability of this average moving away from its hope. For a fixed hypothesis, the sample functions as an opinion poll: more observations make large deviations less likely.

3.1.4 The selection defect

An algorithm does not evaluate just a hypothesis fixed in advance. It uses the data to choose

h^∈argmin⁡h∈H  R^D(h). \widehat{h} \in \underset{h\in\mathcal{H}}{\operatorname{argmin}} \;\widehat{R}_D(h).

The hypothesis chosen is a random variable dependent on DD. Apply a guarantee directly to hh fixed to h^=A(D)\widehat{h}=A(D) ignores this dependency.

When comparing many hypotheses, the one selected by the lowest training error may be precisely the one that most benefited from a fluctuation of the sample.

Figure 3.1. When comparing many hypotheses, the one selected by the lowest training error may be precisely the one that most benefited from a fluctuation of the sample.

Even if each empirical risk is individually a reasonable estimator, the lowest among many estimators tends to be optimistic. This phenomenon is called selection bias or multiple comparisons effect.

3.1.5 The coin analogy

Imagine MM honest coins thrown NN times. For each currency jj, be it νj\nu_j the frequency of faces. Each νj\nu_j focuses around 1/21/2.

Now we select

j∗∈argmin⁡1≤j≤M  νj. j^* \in \underset{1\leq j\leq M}{\operatorname{argmin}} \;\nu_j.

νj∗\nu_{j^*} tends to stay below 1/21/2, not because the currency chosen is dishonest, but because we deliberately seek the lowest fluctuation between MM attempts.

The greater the MM, the greater the opportunity to observe an extreme value. In learning, hypotheses play the role of coins and empirical error plays the role of the observed frequency.

3.1.6 Uniform control

To allow data-dependent selection, we seek to control all hypotheses simultaneously:

sup⁡h∈H∣RP(h)−R^D(h)∣. \sup_{h\in\mathcal{H}} \left| R_P(h)-\widehat{R}_D(h) \right|.

If, for a sample, it is valid

sup⁡h∈H∣RP(h)−R^D(h)∣≤ε, \sup_{h\in\mathcal{H}} \left| R_P(h)-\widehat{R}_D(h) \right| \leq\varepsilon,

then inequality is valid for any class hypothesis, including that chosen after observing DD.

This is the reason for a uniform bound. The complexity of H\mathcal{H} appears because controlling more behaviors simultaneously is more difficult.

3.1.7 Decomposition to minimize empirical risk

Whatever.

h^∈argmin⁡h∈HR^D(h) \widehat{h} \in \underset{h\in\mathcal{H}}{\operatorname{argmin}} \widehat{R}_D(h)

and be

h∗∈argmin⁡h∈HRP(h). h^* \in \underset{h\in\mathcal{H}}{\operatorname{argmin}} R_P(h).

Suppose the uniform deviation is maximum ε\varepsilon:

sup⁡h∈H∣RP(h)−R^D(h)∣≤ε. \sup_{h\in\mathcal{H}} \left| R_P(h)-\widehat{R}_D(h) \right| \leq\varepsilon.

So,

RP(h^)≤R^D(h^)+ε≤R^D(h∗)+ε≤RP(h∗)+2ε. \begin{aligned} R_P(\widehat{h}) &\leq \widehat{R}_D(\widehat{h})+\varepsilon\\ &\leq \widehat{R}_D(h^*)+\varepsilon\\ &\leq R_P(h^*)+2\varepsilon. \end{aligned}

The second inequality uses the fact that h^\widehat{h} minimizes empirical risk.

RP(h^)−RP(h∗)≤2ε. R_P(\widehat{h})-R_P(h^*) \leq2\varepsilon.

This derivation shows how uniform convergence transforms empirical minimization into a guarantee of excess risk.

3.1.8 Approximation error and estimation error

Performance can be conceptually separated into:

  • approach error: the best hypothesis of H\mathcal{H} may still be inadequate;
  • estimation error: finite sample can lead the algorithm to choose a worse hypothesis than the best of class;
  • optimization error: the numerical procedure may not find the empirical minimum.

A larger class tends to reduce the approach error, but it can increase the estimation error. More data reduces statistical uncertainty, but does not correct a class that does not represent the pattern.

3.1.9 Overfit as a gap

Overfit occurs when the model takes advantage of specific details of the sample that do not repeat in the population.

R^D(h^)≪RP(h^). \widehat{R}_D(\widehat{h})\ll R_P(\widehat{h}).

The gap can grow when:

  • the class has high capacity;
  • we compared many configurations;
  • the sample is small;
  • the data contain noise;
  • we repeat decisions using the same validation set.

Regularization, independent validation and capacity control reduce accidental adjustment opportunities, but do not replace representative data.

3.1.10 A non-observable estimate

During training we know R^D(h)\widehat{R}_D(h), but not ΔD(h)\Delta_D(h), because it depends on RP(h)R_P(h). A theoretical bound limits the gap under hypotheses. An independent test set provides another empirical estimate:

R^test(h)≈RP(h). \widehat{R}_{\text{test}}(h) \approx R_P(h).

Test and theory address the same risk through different paths, both subject to conditions.

Choose and evaluate in the same set

The more decisions are made by looking at a metric, the less this set can be treated as independent evaluation. Overfit can occur in validation, not just in training.

3.1.11 Numerical example

Consider three hypotheses:

HypothesisTraining errorValidation error
h1h_10,120{,}120,130{,}13
h2h_20,070{,}070,110{,}11
h3h_30,000{,}000,240{,}24

If we choose only by training, h3h_3 wins. Validation suggests that it has adjusted too much. h2h_2 has less validation error, although it does not have the least training error.

We don’t know the real risk of these hypotheses, but independent data helps detect the discrepancy.

3.1.12 Practice exercises

  1. Interpret the ΔD(h)\Delta_D(h) signal.
  2. If R^D(h)=0,08\widehat{R}_D(h)=0{,}08 and the absolute gap is at most 0,040{,}04, what bound do we get for RP(h)R_P(h)?
  3. Why is the hypothesis chosen by empirical minimization not fixed in relation to the sample?
  4. Explain the analogy between many currencies and many hypotheses.
  5. Play the decomposition that leads to RP(h^)≤RP(h∗)+2εR_P(\widehat{h})\leq R_P(h^*)+2\varepsilon.
  6. Differentiate approach error, estimation and optimization.
  7. Give an example of overfitting the validation set.
  8. Why can’t we directly calculate the generalization gap during training?

3.2 Hoeffding’s inequality

Hoeffding inequality controls the deviation between the average of limited random variables and their hope. It is especially useful in learning because many losses are limited and empirical risk is a sample average.

3.2.1 General statement

be Z1,…,ZNZ_1,\ldots,Z_N independent random variables, with

ai≤Zi≤bi. a_i\leq Z_i\leq b_i.

Set

Z‾=1N∑i=1NZi \overline{Z} =\frac{1}{N}\sum_{i=1}^{N}Z_i

e

μ=E[Z‾]. \mu =\mathbb{E}[\overline{Z}].

So for ε>0\varepsilon>0,

P(∣Z‾−μ∣≥ε)≤2exp⁡(−2N2ε2∑i=1N(bi−ai)2). P\left( |\overline{Z}-\mu|\geq\varepsilon \right) \leq 2\exp\left( -\frac{2N^2\varepsilon^2} {\sum_{i=1}^{N}(b_i-a_i)^2} \right).

When all variables belong to [0,1][0,1], we get the known form:

P(∣Z‾−μ∣≥ε)≤2e−2Nε2. P\left( |\overline{Z}-\mu|\geq\varepsilon \right) \leq 2e^{-2N\varepsilon^2}.

Inequality is distribution free: does not require us to know the form of ZiZ_i distribution. It requires independence and known limits.

As N increases, the sample average focuses around hope and the probability of tails outside \mu\pm\varepsilon decreases.

Figure 3.2. As NN increases, the sample average focuses around hope and the probability of tails outside μ±ε\mu\pm\varepsilon decreases.

3.2.2 Interpretation

The bound drops exponentially in NN and ε2\varepsilon^2:

2e−2Nε2. 2e^{-2N\varepsilon^2}.

That means:

  • more examples make fixed deviations less likely;
  • tolerating a greater deviation makes the warranty easier;
  • reducing the desired deviation by half requires approximately four times more examples.

The bound can be larger than 11 for small NN or very small ε\varepsilon . As a probability never exceeds 11, we can write

P(⋯ )≤min⁡{1,2e−2Nε2}. P(\cdots) \leq \min\{1,2e^{-2N\varepsilon^2}\}.

A bound larger than 11 is valid, but not informative.

3.2.3 Application to a fixed hypothesis

Set a hh hypothesis before observes the sample. In binary classification, set

Zi=1[h(xi)≠yi]. Z_i =\mathbb{1}[h(x_i)\neq y_i].

Each Zi∈{0,1}Z_i\in\{0,1\} and, for i.i.d. examples,

E[Zi]=RP(h). \mathbb{E}[Z_i] =R_P(h).

The average is exactly the empirical risk:

Z‾=R^D(h). \overline{Z} =\widehat{R}_D(h).

So,

PD(∣R^D(h)−RP(h)∣≥ε)≤2e−2Nε2. P_D\left( \left| \widehat{R}_D(h)-R_P(h) \right| \geq\varepsilon \right) \leq 2e^{-2N\varepsilon^2}.

This is a guarantee for a fixed and independent hypothesis of DD. The subscribed DD remembers that randomness is in the sample.

3.2.4 Range form

We want a statement with a probability of failure at most δ\delta:

2e−2Nε2≤δ. 2e^{-2N\varepsilon^2} \leq\delta.

Isolating ε\varepsilon,

ε≥log⁡(2/δ)2N. \varepsilon \geq \sqrt{ \frac{\log(2/\delta)}{2N} }.

Thus, with the probability of at least 1−δ1-\delta,

∣R^D(h)−RP(h)∣≤log⁡(2/δ)2N. \left| \widehat{R}_D(h)-R_P(h) \right| \leq \sqrt{ \frac{\log(2/\delta)}{2N} }.

Equivalently,

RP(h)≤R^D(h)+log⁡(2/δ)2N. R_P(h) \leq \widehat{R}_D(h) + \sqrt{ \frac{\log(2/\delta)}{2N} }.

This is a higher bound for the risk of a previously established hypothesis.

3.2.5 Form of sample complexity

We can also isolate NN. To ensure maximum deviation ε\varepsilon with confidence 1−δ1-\delta, enough

N≥log⁡(2/δ)2ε2. N \geq \frac{\log(2/\delta)}{2\varepsilon^2}.

For example, with

ε=0,05,δ=0,05, \varepsilon=0{,}05, \qquad \delta=0{,}05,

We’ve got

N≥log⁡402(0,05)2≈737,78. N \geq \frac{\log 40}{2(0{,}05)^2} \approx737{,}78.

Therefore, 738738 independent examples are sufficient according to this bound for a fixed hypothesis. It is a guarantee of worse case; it does not say that every application will need exactly that amount.

3.2.6 Numerical example of interval

Suppose a fixed hypothesis evaluated in N=1 000N=1\,000 independent examples, with observed error

R^D(h)=0,12. \widehat{R}_D(h)=0{,}12.

For δ=0,05\delta=0{,}05,

ε=log⁡402 000≈0,0429. \varepsilon = \sqrt{ \frac{\log 40}{2\,000} } \approx0{,}0429.

With confidence of at least 95%95\%, Hoeffding guarantees

RP(h)≤0,12+0,0429=0,1629. R_P(h) \leq0{,}12+0{,}0429 =0{,}1629.

Bilateral bound also provides lower limit, truncated at zero:

RP(h)∈[0,0771,  0,1629]. R_P(h) \in [0{,}0771,\;0{,}1629].

This interval is not necessarily the narrowest for a binomial ratio, but it is simple and does not depend on the unknown value of RP(h)R_P(h).

3.2.7 One-sided bound

If we just need to limit the risk above, a one-sided version provides

PD(RP(h)−R^D(h)≥ε)≤e−2Nε2. P_D\left( R_P(h)-\widehat{R}_D(h) \geq\varepsilon \right) \leq e^{-2N\varepsilon^2}.

With a probability of at least 1−δ1-\delta,

RP(h)≤R^D(h)+log⁡(1/δ)2N. R_P(h) \leq \widehat{R}_D(h) + \sqrt{ \frac{\log(1/\delta)}{2N} }.

The absence of factor 22 slightly improves the bound because we control only one direction of the deviation.

3.2.8 Bounded losses

The application is not restricted to zero-one loss.

0≤ℓ(h(x),y)≤B, 0\leq\ell(h(x),y)\leq B,

We can normalize Zi=ℓ(h(xi),yi)/B∈[0,1]Z_i=\ell(h(x_i),y_i)/B\in[0,1].

PD(∣R^D(h)−RP(h)∣≥ε)≤2exp⁡(−2Nε2B2). P_D\left( \left| \widehat{R}_D(h)-R_P(h) \right| \geq\varepsilon \right) \leq 2\exp\left( -\frac{2N\varepsilon^2}{B^2} \right).

The greater the possible loss interval, the weaker the concentration for the same ε\varepsilon.

Unlimited losses, such as the quadratic without restriction on predictions and targets, require additional hypotheses or other inequalities. We cannot apply Hoeffding directly without a limit almost certain.

3.2.9 The problem of the chosen hypothesis

In learning, we use

h^=A(D), \widehat{h}=A(D),

therefore the hypothesis depends on the same sample. The inequality for a fixed hh cannot be simply rewritten as

PD(∣R^D(A(D))−RP(A(D))∣≥ε)≤2e−2Nε2. P_D\left( \left| \widehat{R}_D(A(D))-R_P(A(D)) \right| \geq\varepsilon \right) \leq 2e^{-2N\varepsilon^2}.

This passage would be unjustified: A(D)A(D) was selected precisely for its behavior in DD.

We need to control all the hypotheses that the algorithm could choose.

3.2.10 Finite class and union bound

If

H={h1,…,hM}, \mathcal{H} =\{h_1,\ldots,h_M\},

So the uniform failure event is

{∃h∈H:∣R^D(h)−RP(h)∣≥ε}. \left\{ \exists h\in\mathcal{H}: \left| \widehat{R}_D(h)-R_P(h) \right| \geq\varepsilon \right\}.

For the sake of unity,

PD(∃h∈H:∣R^D(h)−RP(h)∣≥ε)≤∑h∈HPD(∣R^D(h)−RP(h)∣≥ε)≤2Me−2Nε2. \begin{aligned} &P_D\left( \exists h\in\mathcal{H}: \left| \widehat{R}_D(h)-R_P(h) \right| \geq\varepsilon \right)\\ &\quad\leq \sum_{h\in\mathcal{H}} P_D\left( \left| \widehat{R}_D(h)-R_P(h) \right| \geq\varepsilon \right)\\ &\quad\leq 2M e^{-2N\varepsilon^2}. \end{aligned}

In the complementary event, all hypotheses satisfy the bound. Therefore, any A(D)∈HA(D)\in\mathcal{H} also satisfies.

Note that within the union, each hh is fixed. The event should not be written with h(D)h(D) for each plot.

3.2.11 Uniform bound in the form of an interval

Imposing

2Me−2Nε2≤δ, 2M e^{-2N\varepsilon^2} \leq\delta,

We get it

ε≥log⁡(2M/δ)2N. \varepsilon \geq \sqrt{ \frac{\log(2M/\delta)}{2N} }.

With a probability of at least 1−δ1-\delta,

sup⁡h∈H∣R^D(h)−RP(h)∣≤log⁡(2M/δ)2N. \sup_{h\in\mathcal{H}} \left| \widehat{R}_D(h)-R_P(h) \right| \leq \sqrt{ \frac{\log(2M/\delta)}{2N} }.

For the selected hypothesis,

RP(A(D))≤R^D(A(D))+log⁡(2M/δ)2N. R_P(A(D)) \leq \widehat{R}_D(A(D)) + \sqrt{ \frac{\log(2M/\delta)}{2N} }.

The price of examining MM hypotheses appears as log⁡M\log M after we isolate ε\varepsilon.

3.2.12 Sample complexity for finite class

Isolating NN,

N≥log⁡(2M/δ)2ε2 N \geq \frac{ \log(2M/\delta) }{ 2\varepsilon^2 }

is sufficient for uniform deviation at most ε\varepsilon.

If M=1M=1, we recover the bound for a fixed hypothesis. If we multiply the number of hypotheses by a thousand, we add log⁡1 000\log 1\,000 to the numerator, not a thousand factor to the required size.

3.2.13 Example with selection

Consider M=100M=100 hypotheses, N=2 000N=2\,000 and δ=0,05\delta=0{,}05. The uniform width is

ε=log⁡(2⋅100/0,05)2⋅2 000=log⁡4 0004 000≈0,0455. \varepsilon = \sqrt{ \frac{\log(2\cdot100/0{,}05)}{2\cdot2\,000} } = \sqrt{ \frac{\log 4\,000}{4\,000} } \approx0{,}0455.

If the selected hypothesis has empirical error 0,080{,}08, then

RP(A(D))≤0,1255 R_P(A(D)) \leq0{,}1255

with confidence of at least 95%95\% under the conditions of inequality.

3.2.14 The balance between adjustment and capacity

A larger class may contain a hypothesis with lower empirical error, but increases the complexity penalty:

R^D(h)+log⁡(2M/δ)2N. \widehat{R}_D(h) + \sqrt{ \frac{\log(2M/\delta)}{2N} }.

This suggests an idea of structural risk minimization: compare not only the adjustment, but adjust another capacity penalty.

There is no absolute opposition between “empirical error” and “true error”. The goal is to choose a class expressive enough to represent patterns, but controlled enough to generalize with the available data.

3.2.15 Limitations

Hoeffding doesn’t solve all the problems:

  • requires independence;
  • requires limited variables;
  • the bound may be conservative;
  • direct union does not help when H\mathcal{H} is infinite;
  • does not treat change of distribution;
  • does not correct selection made outside the accounted class.

For infinite classes, we will replace MM with a measure of the number of relevant behaviors on finite samples. This path leads to growth function and VC dimension.

3.2.16 Computing example

from math import log, sqrt


def radius_hoeffding(n, delta, number_hypothesis=1):
    return sqrt(log(2 * number_hypotheses / delta) / (2 *n))


print(radio_hoeffding(1000, 0.05))
print(radio_hoeffding(2000, 0.05, number_hypotheses=100))

The calculation assumes loss in [0,1][0,1]. For loss in [0,B][0,B], multiply the radius by BB.

3.2.17 Practice exercises

  1. Enunciate the conditions of Hoeffding’s inequality.
  2. Calculate the bilateral bound for N=500N=500 and ε=0,1\varepsilon=0{,}1.
  3. Isolate ε\varepsilon on 2e−2Nε2≤δ2e^{-2N\varepsilon^2}\leq\delta.
  4. How many examples are enough for ε=0,02\varepsilon=0{,}02 and δ=0,01\delta=0{,}01 in a fixed hypothesis?
  5. Why does Hoeffding not apply directly to A(D)A(D)?
  6. Draw the 2Me−2Nε22M e^{-2N\varepsilon^2} bound using the union.
  7. For M=50M=50, N=1 000N=1\,000 and δ=0,05\delta=0{,}05, calculate the uniform radius.
  8. Explain why dependence on MM becomes logarithmic when isolating ε\varepsilon.
  9. Give an example of non-limited loss to which Hoeffding cannot be applied directly.
  10. Compare bilateral and unilateral forms.

3.3 The dimension of Vapnik–Chervonenkis

For a finite class, the uniform Hoeffding bound contains log⁡∣H∣\log|\mathcal{H}|. Important classes, however, have infinite hypotheses: there are infinite straight in the plane and infinite choices of real weights.

The infinite cardinality overestimates the number of relevant behaviors in a finite sample. Two different straight lines can classify the same NN points exactly the same way. For generalization, it is interesting to count the distinct labels that the class can produce on finite sets.

3.3.1 Restrictions and dichotomy

Be a class of binary classifiers

H⊆{−1,+1}X \mathcal{H}\subseteq\{-1,+1\}^{X}

and a set of distinct points

S={x1,…,xN}⊆X. S=\{x_1,\ldots,x_N\}\subseteq X.

The hh restriction to SS is the vector

h∣S=(h(x1),…,h(xN))∈{−1,+1}N. h|_S = \bigl(h(x_1),\ldots,h(x_N)\bigr) \in\{-1,+1\}^{N}.

The set of dichotomies performed by H\mathcal{H} in SS is

H∣S={(h(x1),…,h(xN))∣h∈H}. \mathcal{H}|_S = \left\{ \bigl(h(x_1),\ldots,h(x_N)\bigr) \mid h\in\mathcal{H} \right\}.

Although H\mathcal{H} may be infinite,

∣H∣S∣≤2N, |\mathcal{H}|_S| \leq2^N,

because there are only 2N2^N binary labels of the NN points.

Two hypotheses that differ outside SS, but coincide at all points of SS, count as a single dichotomy on this set.

3.3.2 Growth function

The growth function is the largest number of dichotomies that the class can perform in any set of NN points:

mH(N)=max⁡S⊆X∣S∣=N∣H∣S∣. m_{\mathcal{H}}(N) = \max_{\substack{S\subseteq X\\|S|=N}} |\mathcal{H}|_S|.

It is also common to use the ΠH(N)\Pi_{\mathcal{H}}(N) notation. Always goes

1≤mH(N)≤2N. 1\leq m_{\mathcal{H}}(N)\leq2^N.

The maximum is taken over the position of the dots. A particular set may admit few labels even when another set of the same size admits all.

3.3.3 Shattering

We say H\mathcal{H} shatters SS when it performs all possible labels:

∣H∣S∣=2∣S∣. |\mathcal{H}|_S|=2^{|S|}.

Equivalently,

∀y∈{−1,+1}∣S∣,∃h∈Hsuch thath∣S=y. \forall\mathbf{y}\in\{-1,+1\}^{|S|}, \quad \exists h\in\mathcal{H} \quad\text{such that}\quad h|_S=\mathbf{y}.

The order of quantifiers is essential: we set a single set SS and demand that for each labeling, there may be a different hypothesis.

If the class shatters any set of NN points, then

mH(N)=2N. m_{\mathcal{H}}(N)=2^N.

If no set of NN points is shattered, then

mH(N)<2N. m_{\mathcal{H}}(N)<2^N.

3.3.4 VC dimension

The Vapnik–Chervonenkis dimension is the largest size of a shattered set:

dVC(H)=sup⁡{N∈N∣mH(N)=2N}. d_{\mathrm{VC}}(\mathcal{H}) = \sup \left\{ N\in\mathbb{N} \mid m_{\mathcal{H}}(N)=2^N \right\}.

If arbitrarily large sets can be shattered, we define

dVC(H)=∞. d_{\mathrm{VC}}(\mathcal{H})=\infty.

If kk is the smallest integer to which

mH(k)<2k, m_{\mathcal{H}}(k)<2^k,

it is called breakpoint. When it exists,

dVC(H)=k−1. d_{\mathrm{VC}}(\mathcal{H})=k-1.

To prove dVC(H)=dd_{\mathrm{VC}}(\mathcal{H})=d, we need two parts:

  1. bottom bound: display a set of dd points that is shattered;
  2. top bound: prove that no set of d+1d+1 points can be shattered.

Finding an impossible labeling in a particular set provides information about that set, but does not alone prove the top bound for all sets.

3.3.5 Example 1: Thresholds on the straight line

Consider

Hlimiar={ha(x)={−1,x<a,+1,x≥a  |  a∈R}. \mathcal{H}_{\mathrm{limiar}} = \left\{ h_a(x)= \begin{cases} -1, & x<a,\\ +1, & x\geq a \end{cases} \;\middle|\; a\in\mathbb{R} \right\}.

For NN ordered points,

x1<x2<⋯<xN, x_1<x_2<\cdots<x_N,

the threshold can be placed before everyone, between two consecutive points or after all. There are N+1N+1 dichotomies:

mHlimiar(N)=N+1. m_{\mathcal{H}_{\mathrm{limiar}}}(N)=N+1.

One point is shattered because we can classify it as −1-1 or +1+1. Two points are not shattered: the (+1,−1)(+1,-1) labeling contradicts the monotonicity of the threshold.

dVC(Hlimiar)=1. d_{\mathrm{VC}}(\mathcal{H}_{\mathrm{limiar}})=1.

If we allowed both the threshold guidelines, the class would be different and the count would need to be remade.

3.3.6 Example 2: ranges on the straight line

Now consider positive classifiers within a range:

ha,b(x)={+1,a≤x≤b,−1,otherwise. h_{a,b}(x) = \begin{cases} +1, & a\leq x\leq b,\\ -1, & \text{otherwise}. \end{cases}

About NN ordered points, the positives form a consecutive block.

N(N+1)2 \frac{N(N+1)}{2}

non-empty blocks and a non-positive labeling.

mHint(N)=N(N+1)2+1. m_{\mathcal{H}_{\mathrm{int}}}(N) = \frac{N(N+1)}{2}+1.

Two points can receive any of the four labels. Three points cannot perform (+1,−1,+1)(+1,-1,+1), because an interval containing the extremes also contains the central point.

dVC(Hint)=2. d_{\mathrm{VC}}(\mathcal{H}_{\mathrm{int}})=2.

3.3.7 Example 3: Lines in the plane

Consider similar semiplanes in R2\mathbb{R}^2:

Hreta={sign⁡(wTx+b)∣w∈R2,  b∈R}. \mathcal{H}_{\mathrm{reta}} = \left\{ \operatorname{sign} (\mathbf{w}^{\mathsf T}\mathbf{x}+b) \mid \mathbf{w}\in\mathbb{R}^2,\; b\in\mathbb{R} \right\}.

For any labeling, a line separates the positive from the negative.

Rects perform all eight non-collinear three-point labels; XOR labeling in four vertices is a non-separable example.

Figure 3.3. Rects perform all eight non-collinear three-point labels; XOR labeling in four vertices is a non-separable example.

For the top bound, consider any set of four points.

  • If one point is inside the triangle formed by the other three, label the internal point as positive and the others as negative. No semiplane separates it.
  • If the four points are in convex position, label alternate vertices as positive. The XOR pattern arises, which is not linearly separable.
  • Collinear degenerations do not increase capacity.

So no four-point set is shattered and

dVC(Hreta)=3. d_{\mathrm{VC}}(\mathcal{H}_{\mathrm{reta}})=3.

For four points in general position, straights perform 1414 of the 1616 labels: the two XOR labels with opposite diagonals are missing.

3.3.8 Example 4: Rd\mathbb{R}^d semiplanes

For similar classifiers

hw,b(x)=sign⁡(wTx+b) h_{\mathbf{w},b}(\mathbf{x}) = \operatorname{sign} (\mathbf{w}^{\mathsf T}\mathbf{x}+b)

in Rd\mathbb{R}^d,

dVC=d+1. d_{\mathrm{VC}}=d+1.

The bottom bound can be demonstrated using d+1d+1 points affin-independent. The top bound results from the dependency in order to any set with d+2d+2 points and a separation argument.

When incorporating a constant co-ordinate,

x~=(1,x), \widetilde{\mathbf{x}}=(1,\mathbf{x}),

bb bias becomes part of a vector of d+1d+1 weights. This helps to understand the value d+1d+1, but counting parameters is just an intuition, not a general proof of VC dimension.

3.3.9 Example 5: Convex sets in the plane

Consider the class of all R2\mathbb{R}^2 convex subsets with positive label within the set.

For any NN, choose NN points on a circumference. Given a labeling, take the convex closure of the positive points. No negative point of the circumference belongs to that clasp, because each point is an extreme vertex of the configuration. Cases of all positive or none positive are also feasible.

Therefore, the class shatters sets of any size:

dVC(Hconv)=∞. d_{\mathrm{VC}}(\mathcal{H}_{\mathrm{conv}})=\infty.

This example shows that a simple geometric description in words can have unlimited capacity.

3.3.10 Comparison of examples

ClassGrowth functionVC dimension
R\mathbb{R} oriented thresholdN+1N+111
R\mathbb{R} intervalN(N+1)2+1\frac{N(N+1)}{2}+122
Semi-plan in R2\mathbb{R}^22N2^N to N=3N=3; m(4)=14m(4)=1433
Semi-plan in Rd\mathbb{R}^dpolynomial growth after d+1d+1d+1d+1
Convex sets in R2\mathbb{R}^22N2^N for all NN∞\infty

The growth function contains more information than a single number. The VC dimension identifies the point from which growth is no longer maximum; the next result will show that, after that point, growth is limited by a polynomial in NN.

3.3.11 VC dimension is not just number of parameters

In some linear models, VC dimension and amount of parameters have the same order. This is not a universal law. Algebraic restrictions, redundant parameters, numerical precision and computational structure change capacity.

In addition, VC dimension measures possible labels, no optimization difficulty, training speed or representation quality.

3.3.12 How to calculate a VC dimension

A practical script is:

  1. choose candidates for small sets in a favourable position;
  2. prove that all labels of a dd size set are feasible;
  3. consider an arbitrary configuration of d+1d+1 points;
  4. construct, for each possible geometric configuration, at least one impossible labeling;
  5. complete the lower and upper bounds.

Diagrams help you figure out the answer, but each quantifier needs to appear in the test.

3.3.13 Practice exercises

  1. List the dichotomies of three ordered points produced by oriented thresholds.
  2. Check the growth function formula of ranges for N=3N=3.
  3. Explicitly show how three non-collinear points perform all eight straight labels.
  4. Explain why the XOR pattern is not linearly separable.
  5. Complete the top bound argument for four points when one of them is inside the other’s triangle.
  6. Why points on a circumference can be shattered by convex sets?
  7. Differentiate growth function, breakpoint and VC dimension.
  8. Give an example of the statement in which counting parameters would only be heuristic.

3.3.14 Bound of the actual number of hypotheses on a sample

The growth function always satisfies

mH(N)≤2N. m_{\mathcal{H}}(N)\leq2^N.

This bound is accurate when the class shatters some set of NN points, but it is useless to demonstrate capacity control: replace MM with 2N2^N in a union bound introduces a linear term in NN in the exponent and can prevent desired convergence.

The finite VC dimension produces a decisive change. After the first interruption point, the growth function cannot continue exponential; it becomes limited by a polynomial.

With finite VC dimension, the growth function ceases to accompany 2^N after the break point and is limited by a polynomial sum.

Figure 3.4. With finite VC dimension, the growth function ceases to accompany 2N2^N after the break point and is limited by a polynomial sum.

3.3.15 Sauer–Shelah Lemma

If

d=dVC(H)<∞, d=d_{\mathrm{VC}}(\mathcal{H})<\infty,

then, for all NN,

mH(N)≤∑i=0d(Ni). m_{\mathcal{H}}(N) \leq \sum_{i=0}^{d} \binom{N}{i}.

We’ve adopted. (Ni)=0\binom{N}{i}=0 when i>Ni>N- Stop. N≤dN\leq d, the sum

∑i=0N(Ni)=2N, \sum_{i=0}^{N}\binom{N}{i}=2^N,

compatible with the possibility of shattering. For N>dN>d, the sum contains only the terms up to dd and grows as a grade dd polynomial .

If k=d+1k=d+1 is the smallest breakpoint, the same bound can be written

mH(N)≤∑i=0k−1(Ni). m_{\mathcal{H}}(N) \leq \sum_{i=0}^{k-1} \binom{N}{i}.

3.3.16 Examples of bound

For d=1d=1,

mH(N)≤(N0)+(N1)=1+N. m_{\mathcal{H}}(N) \leq \binom{N}{0}+\binom{N}{1} =1+N.

The class of oriented thresholds reaches exactly this value.

For d=2d=2,

mH(N)≤1+N+N(N−1)2. m_{\mathcal{H}}(N) \leq 1+N+\frac{N(N-1)}{2}.

The range class has

mint(N)=1+N(N+1)2, m_{\mathrm{int}}(N) = 1+\frac{N(N+1)}{2},

which is greater than Sauer expression with d=2d=2? Let’s compare carefully:

1+N+N(N−1)2=1+N(N+1)2. 1+N+\frac{N(N-1)}{2} = 1+\frac{N(N+1)}{2}.

The expressions are the same. Therefore, intervals also reach Sauer’s bound.

For semi-planes in the plane, d=3d=3:

mH(N)≤1+N+(N2)+(N3). m_{\mathcal{H}}(N) \leq 1+N+\binom{N}{2}+\binom{N}{3}.

In N=4N=4,

mH(4)≤1+4+6+4=15. m_{\mathcal{H}}(4) \leq 1+4+6+4=15.

The real growth function of related semiplanes in general position is 1414, so the bound is valid but not exact at that point.

3.3.17 Combinatory idea of the proof

Set M(N,d)M(N,d) as the largest number of dichotomies possible in NN points for a VC dimension class at most dd. The proof uses recurrence

M(N,d)≤M(N−1,d)+M(N−1,d−1). M(N,d) \leq M(N-1,d)+M(N-1,d-1).

To understand recurrence, separate the last point xNx_N. By restricting dichotomies to the first points N−1N-1 , there are two types:

  1. standards that allow only one extension to xNx_N;
  2. standards that admit the two extensions, −1-1 and +1+1.

The first group contributes maximum M(N−1,d)M(N-1,d). In the second group, if it was possible to shatter dd points between the first N−1N-1, add xNx_N would produce a set of d+1d+1 shattered points. Therefore, the pattern class with two extensions has maximum size d−1d-1 and contributes maximum M(N−1,d−1)M(N-1,d-1).

Border values are:

M(N,0)=1 M(N,0)=1

e

M(0,d)=1. M(0,d)=1.

Applying recurrence repeatedly and using Pascal’s identity,

(Ni)=(N−1i)+(N−1i−1), \binom{N}{i} = \binom{N-1}{i} + \binom{N-1}{i-1},

We get it

M(N,d)≤∑i=0d(Ni). M(N,d) \leq \sum_{i=0}^{d}\binom{N}{i}.

This is the central structure of Sauer–Shelah’s test.

3.3.18 Simplified bound

For 1≤d≤N1\leq d\leq N, it is worth the standard bound

∑i=0d(Ni)≤(eNd)d. \sum_{i=0}^{d}\binom{N}{i} \leq \left(\frac{eN}{d}\right)^d.

Soon,

mH(N)≤(eNd)d. m_{\mathcal{H}}(N) \leq \left(\frac{eN}{d}\right)^d.

Taking logarithms,

log⁡mH(N)≤dlog⁡(eNd). \log m_{\mathcal{H}}(N) \leq d\log\left(\frac{eN}{d}\right).

This form will be useful in the generalization bound, because the penalty depends on the logarithm of the effective number of dichotomies.

For fixed dd ,

mH(N)=O(Nd), m_{\mathcal{H}}(N)=O(N^d),

while

2N 2^N

the difference between polynomial and exponential growth is the reason why finite VC dimension allows uniform learning.

3.3.19 An even simpler bound

We can also use, for N≥1N\geq1 and d≥1d\geq1, a rough estimate as

mH(N)≤(d+1)Nd. m_{\mathcal{H}}(N) \leq (d+1)N^d.

It loses constants and refined dependence in dd, but shows the polynomial degree. (eN/d)d\left(eN/d\right)^d expression is usually preferred in quantitative derivations.

3.3.20 Breakpoint and domino effect

The motto contains a strong combinatorial message: it is enough that the class fails to shatter all sets of some finite size so that the entire future growth is controlled.

Can’t have

mH(k)<2k m_{\mathcal{H}}(k)<2^k

and then return to maximum growth

mH(N)=2N m_{\mathcal{H}}(N)=2^N

for some N>kN>k. If a larger set were shattered, any subset of size kk would also be shattered, contradicting the breakpoint.

3.3.21 Numerical calculation

Consider d=3d=3 and N=20N=20. Sauer–Shelah provides

mH(20)≤(200)+(201)+(202)+(203). m_{\mathcal{H}}(20) \leq \binom{20}{0} +\binom{20}{1} +\binom{20}{2} +\binom{20}{3}.

Calculating,

mH(20)≤1+20+190+1 140=1 351. m_{\mathcal{H}}(20) \leq 1+20+190+1\,140 =1\,351.

Without using capacity, the trivial bound would be

220=1 048 576. 2^{20}=1\,048\,576.

The reduction in the effective number of behaviors is enormous.

Simplified bound gives

(20e3)3≈5 950, \left(\frac{20e}{3}\right)^3 \approx5\,950,

less accurate than 1 3511\,351, but still much smaller than 2202^{20}.

3.3.22 Relationship with compression of patterns

The sum

∑i=0d(Ni) \sum_{i=0}^{d}\binom{N}{i}

subset account of up to dd elements. This suggests that a VC dd dimension class cannot make independent decisions in all NN positions; its patterns are determined by a dd order combinatorial structure.

This interpretation does not mean that every VC class automatically admits a simple compression scheme with exactly dd examples. The formal relationship between VC dimension and sample compression is more delicate. The binomial sum is, first of all, a combinatorial bound.

3.3.23 What the lemma does not say

Sauer–Shelah limits the number of dichotomies, but not:

  • finds the hypothesis excellent;
  • ensures that the algorithm is efficient;
  • measures approach error;
  • treats continuous regression directly;
  • It alone provides a probability of generalization.

To obtain a bound of error, we will combine the growth function with a concentration inequality and a standardization argument.

3.3.24 Computing example

from math import comb


def quota_sauer(n, d):
    return sum(n, i) for i in range(min(d, n) + 1)


print(quota_sauer(20, 3)) #1351
print(2 ** 20) # 1048576

3.3.25 Practice exercises

  1. Calculate Sauer’s bound for N=6N=6 and d=2d=2.
  2. Check that the formula for d=1d=1 matches the threshold growth function.
  3. Show algebraically that 1+N+(N2)=1+N(N+1)/21+N+\binom{N}{2}=1+N(N+1)/2.
  4. Explain the recurrence M(N,d)≤M(N−1,d)+M(N−1,d−1)M(N,d)\leq M(N-1,d)+M(N-1,d-1).
  5. Use Pascal’s identity to verify that the binomial sum satisfies the same recurrence.
  6. Compare 2N2^N numerically and Sauer’s bound for N=10N=10, d=3d=3.
  7. Why can’t a class reshape larger sets after a breakpoint?
  8. Differentiate the exact bound by the binomial sum of the (eN/d)d(eN/d)^d approach.
  9. Explain why Sauer–Shelah’s motto is not yet a bound of generalization on its own.

3.3.26 Error bound

So far, the VC dimension and growth function have measured how many ** different ways a class of hypotheses can produce on a sample**. There is a need to transform this combinatorial measure into a statement statistics: how close the error observed in the data is to the error that the will you have a chance in future examples?

Whatever.

ΔD(h)=Eout(h)−Ein(h), \Delta_D(h)=E_{\mathrm{out}}(h)-E_{\mathrm{in}}(h),

where EinE_{\mathrm{in}} is the error in the training sample DD and EoutE_{\mathrm{out}} is the expected error in the distribution that generates the data. The ∣ΔD(h)∣|\Delta_D(h)| module is called generalization gap.

The VC dimension limits the growth function, which allows simultaneously to control the gap of all hypotheses.

Figure 3.5. The VC dimension limits the growth function, which allows simultaneously to control the gap of all hypotheses.

A uniform bound

A classic form of Vapnik-Chervonenkis inequality states that, for any ϵ>0\epsilon>0,

Pr⁡ ⁣[sup⁡h∈H∣Eout(h)−Ein(h)∣>ϵ]≤4 mH(2N)exp⁡ ⁣(−Nϵ28).(3.1) \Pr\!\left[ \sup_{h\in\mathcal H} |E_{\mathrm{out}}(h)-E_{\mathrm{in}}(h)|>\epsilon \right] \leq 4\,m_{\mathcal H}(2N) \exp\!\left(-\frac{N\epsilon^2}{8}\right). \tag{3.1}

Constants may vary between versions of the theorem, but the structure is always the same: a portion measures the complexity of H\mathcal H and the exponential measures the beneficial effect of the NN number of examples.

The supreme is essential. Inequality does not control just one hypothesis fixed before observing the data; it controls all ** simultaneously the class** hypotheses. Therefore, it remains valid for the hypothesis g=A(D)g=A(D) chosen by algorithm after examining sample. precisely the step that a direct application of inequality of the Hoeffding can’t justify it.

Setting a probability of δ∈(0,1)\delta\in(0,1) failure and isolating ϵ\epsilon in (3.1), we get, with at least probability 1−δ1-\delta,

sup⁡h∈H∣Eout(h)−Ein(h)∣≤8Nln⁡ ⁣(4mH(2N)δ).(3.2) \sup_{h\in\mathcal H} |E_{\mathrm{out}}(h)-E_{\mathrm{in}}(h)| \leq \sqrt{\frac{8}{N} \ln\!\left(\frac{4m_{\mathcal H}(2N)}{\delta}\right)}. \tag{3.2}

In particular, the hypothesis returned by the algorithm satisfies

Eout(g)≤Ein(g)+8Nln⁡ ⁣(4mH(2N)δ). E_{\mathrm{out}}(g) \leq E_{\mathrm{in}}(g) +\sqrt{\frac{8}{N} \ln\!\left(\frac{4m_{\mathcal H}(2N)}{\delta}\right)}.

Thus, the bound separates two objectives: the algorithm seeks to reduce Ein(g)E_{\mathrm{in}}(g), while the theory limits the distance between this value and Eout(g)E_{\mathrm{out}}(g).

Inserting VC dimension

If d=dVC(H)<∞d=d_{\mathrm{VC}}(\mathcal H)<\infty, Sauer–Shelah’s motto provides

mH(2N)≤∑i=0d(2Ni)≤(2eNd)d,2N≥d. m_{\mathcal H}(2N) \leq \sum_{i=0}^{d}\binom{2N}{i} \leq \left(\frac{2eN}{d}\right)^d, \qquad 2N\geq d.

Replacing this estimate in (3.2), we arrived at the bound

∣Eout(g)−Ein(g)∣≤8N[dln⁡ ⁣(2eNd)+ln⁡ ⁣(4δ)].(3.3) |E_{\mathrm{out}}(g)-E_{\mathrm{in}}(g)| \leq \sqrt{\frac{8}{N} \left[ d\ln\!\left(\frac{2eN}{d}\right) +\ln\!\left(\frac{4}{\delta}\right) \right]}. \tag{3.3}

This expression explains three important relationships:

  • increase NN tends to narrow the bound;
  • increase dd makes the class more flexible and widens the bound;
  • reducing δ\delta increases confidence, but also makes the warranty more conservative.

For fixed dd , the right side has approximate order

O ⁣(dln⁡N+ln⁡(1/δ)N), O\!\left(\sqrt{\frac{d\ln N+\ln(1/\delta)}{N}}\right),

which converges to zero when N→∞N\to\infty. Convergence occurs because the growth function is polynomial. if it remained equal to 22N2^{2N}, its logarithm would be proportional to NN and the bound would not It would disappear.

How many examples are needed?

To require a gap of maximum ϵ\epsilon, just look for NN such that

N≥8ϵ2[dln⁡ ⁣(2eNd)+ln⁡ ⁣(4δ)].(3.4) N\geq \frac{8}{\epsilon^2} \left[ d\ln\!\left(\frac{2eN}{d}\right) +\ln\!\left(\frac{4}{\delta}\right) \right]. \tag{3.4}

The inequality is implicit, as NN also appears within the logarithm. In a program, we can find the smallest integer that the satisfies by incremental or binary search. A fixed point iteration also provides a quick estimate:

import math

def amostras_vc(d, epsilon, delta, n_inicial=1):
    n = max(n_inicial, math.ceil(d / 2))
    while True:
        rhs = (8 / epsilon**2) * (
            d * math.log(2 * math.e * n / d)
            + math.log(4 / delta)
        )
        novo_n = math.ceil(rhs)
        if novo_n <= n:
            return n
        n = novo_n

print(amostras_vc(d=3, epsilon=0.1, delta=0.1))

The result should be interpreted as a sufficient condition, no as the exact number of examples that every problem will need. VC bounds they are independent of distribution and algorithm; for covering up to more unfavorable cases are often conservative.

VC dimension is not just number of parameters

In some linear models, the VC dimension is close to the number of free parameters. This does not constitute a universal rule. architecture, margin, regularization and even the form of parameterization can The relevant mathematical object is the class of performable functions, not just the size of the parameter vector.

From generalization to PAC learning

Suppose the algorithm finds gg with small training error. If the class has finite VC dimension and NN satisfies (3.4), then with high probability, the error was out The sample will also be small. perfect hypothesis in the class and the algorithm finds Ein(g)=0E_{\mathrm{in}}(g)=0, (3.3) directly provides a warranty for Eout(g)E_{\mathrm{out}}(g).

In the case of non-realisable, it is useful to decompose performance into two parts:

Eout(g)=Ein(g)⏟goodness of fit+(Eout(g)−Ein(g))⏟generalization gap. E_{\mathrm{out}}(g) = \underbrace{E_{\mathrm{in}}(g)}_{\text{goodness of fit}} + \underbrace{\bigl(E_{\mathrm{out}}(g)-E_{\mathrm{in}}(g)\bigr)} _{\text{generalization gap}}.

The VC theory controls the second part; optimization and model choice A narrow bound does not compensate for a model that adjusts data as well as zero training error does not guarantee alone Good generalization.

Example of bound reading

Consider two classes trained with the same sample. H1\mathcal H_1 has d=5d=5 and the H2\mathcal H_2 class has d=500d=500. If both achieve the same training error, the bound favors H1\mathcal H_1, because it offers less ways to accidentally adapt to noise. However, if H1\mathcal H_1 presents very high training error, H2\mathcal H_2 can produce the best sum between adjustment and complexity. This tension is a mathematical formulation of the compromise between underfit and overfit.

Review

  1. The inequality VC evenly controls all the hypotheses of H\mathcal H.
  2. Sauer–Shelah’s motto converts finite VC dimension into growth polynomial.
  3. The guaranteed gap decreases approximately as (dln⁡N+ln⁡(1/δ))/N\sqrt{(d\ln N+\ln(1/\delta))/N}.
  4. Sample complexity grows with dd capacity, with precision desired 1/ϵ1/\epsilon and with desired confidence 1−δ1-\delta.
  5. The bound is a guarantee of worse case; it guides reasoning, but it does not replaces empirical validation.

Exercises

  1. Explain why the supreme over h∈Hh\in\mathcal H allows you to apply the quotes the hypothesis chosen after observing the data.
  2. Keeping dd and δ\delta fixed, what happens approximately with the bound when NN is quadrupled?
  3. Implement the amostras_vc function and compare the results to d∈{5,50,500}d\in\{5,50,500\}.
  4. Show that, for dd fixed, (dln⁡N)/N→0(d\ln N)/N\to0.
  5. Give an example in which to choose the smaller VC class provokes Underfit.

3.4 Multiple choice exercises

Each question has a single correct answer. Try to relate the alternative chosen to the definitions and bounds studied in the chapter.

  1. The absolute generalization gap of a hh hypothesis is:

    1. ∣Eout(h)−Ein(h)∣|E_{\mathrm{out}}(h)-E_{\mathrm{in}}(h)|.
    2. Eout(h)+Ein(h)E_{\mathrm{out}}(h)+E_{\mathrm{in}}(h).
    3. Ein(h)2E_{\mathrm{in}}(h)^2.
    4. the number of parameters of hh.
  2. Because a bound for a pre-data hypothesis is not enough for the hypothesis selected by training?

    1. Because the training chooses the hypothesis based on the same sample.
    2. Because trained hypotheses have no mistake.
    3. Because the sample no longer contains random variables.
    4. Because Hoeffding applies only to regression.
  3. The Hoeffding inequality, in the studied form, requires variables:

    1. independent and limited.
    2. always Gaussian and negative.
    3. deterministic and unlimited.
    4. necessarily vectorial.
  4. When quadrupling NN, maintaining the other fixed terms , a proportional bound the 1/N1/\sqrt{N} is approximately:

    1. duplicate.
    2. reduced to half.
    3. quadrupled.
    4. unchanged.
  5. For a finite class with MM hypotheses, the union bound typically introduces What dependence on complexity?

    1. ln⁡M\ln M.
    2. 1/M21/M^2.
    3. 2M2^M within the error.
    4. No dependency on MM.
  6. A set is shattered by H\mathcal H when:

    1. only a labeling can be produced.
    2. all binary labels of their points can be performed by chances of H\mathcal H.
    3. all points must be labelled as the same.
    4. his cardinality is infinite.
  7. The VC dimension of the threshold class in a straight line is:

    1. Infinite.
  8. The VC dimension of the range class in a straight line is:

    1. Infinite.
  9. Sauer–Shelah’s motto shows that when dVCd_{VC} is finite, the function of growth for large samples is limited by a growth:

    1. polynomial in NN.
    2. necessarily constant.
    3. greater than all exponentials.
    4. independent of NN.
  10. What statement correctly interprets a VC bound?

    1. It predicts exactly the test error of any experiment.
    2. It is a guarantee of worse case and does not replace empirical validation.
    3. It proves that simpler models are always better.
    4. It eliminates the error of approach.

Answer key with explanations

  1. a. The absolute value measures the size of the difference without depending on its signal.
  2. a. Selection adapts hh to sample fluctuations, requiring control Simultaneous over the whole class.
  3. a. Independence and limitation are central conditions of the presented form.
  4. b. 1/4N=1/(2N)1/\sqrt{4N}=1/(2\sqrt{N}).
  5. a. The application of the union to MM hypotheses appears as ln⁡M\ln M by isolating the tolerance.
  6. b. Shrapnel means performing the possible 2N2^N dichotomies on that set.
  7. b. One point may receive both labels, but two points do not admit all dichotomy with a single oriented threshold.
  8. b. Ranges shatter two points; three alternate points cannot be positive-negative-positive labelled for one interval only.
  9. a. For N>dVCN>d_{VC}, the effective number of dichotomies ceases to grow as 2N2^N and receives a polynomial bound.
  10. b. The bound explains dependencies and offers probabilistic warranty but can be conservative in a concrete application.