Concepts / VC Dimension

VC Dimension

VC dimension measures how many points a hypothesis class can shatter: the largest number for which every possible binary labeling can be produced by some classifier in the class.

  • Programming
Interactive lab

Try it: Shattering and VC Dimension

What it means for a hypothesis class to shatter a set of points: all labelings are checked exactly, each realizable one with a witness hypothesis drawn, until the first labeling no hypothesis can produce — linked to the VC dimensions of thresholds (1), intervals (2), halfspaces in the plane (3) and axis-aligned rectangles (4).

How it works

  1. Pick a hypothesis class and place n points.
  2. Enumerate all labelings of the points with 0 / 1.
  3. For each labeling decide exactly whether some hypothesis produces it (thresholds: every 1 left of every 0; intervals: no 0 between the outer 1s; rectangles: no 0 in the bounding box of the 1s; halfspaces: strict linear separability).
  4. Draw a witness hypothesis for every realizable labeling.
  5. The set is shattered if every labeling is realized; VCdim is the size of the largest shattered set.

Default run (6 steps): 2 points and the class of intervals on a line (VC dimension 2). Check all 2^2 = 4 labelings: is each one produced by some hypothesis? … All 4 labelings are realized: intervals on a line shatter these 2 points, so VCdim >= 2. Theory: VCdim = 2, so no set of 3 points can be shattered.

Simplified: At most 6 points on a 0–10 board. The lab checks one placement at a time: failing to shatter one set of n points does not by itself show VCdim < n — that needs every placement (the lab states the known VC dimension).

Educational simulation

Loading the simulation…

From Samples to Guarantees

A learner sees only a finite labeled sample, but a PAC guarantee concerns performance on the entire underlying distribution. The central question is therefore whether the sample is capable of detecting every hypothesis that disagrees with the target on a sufficiently large part of that distribution. VC dimension supplies the capacity measure, while epsilon-nets supply the coverage argument that turns a sample into a guarantee.

Key point

VC dimension measures how many points a hypothesis class can shatter: the largest number for which every possible binary labeling can be produced by some classifier in the class.

Epsilon-Net Coverage

Definition

An epsilon-net for a class of sets under a distribution is a sample that intersects every set in the class whose probability is at least epsilon. Each set represents a region of the domain, and only sufficiently probable regions are required to be hit. Regions with probability below epsilon are not required to intersect the sample.

The important feature is the universal coverage requirement. The sample is not merely likely to hit one particular high-probability set. It must hit every set in the relevant class that has probability at least epsilon. This is what allows the argument to eliminate an entire collection of bad hypotheses at once.

Distribution Ddomain regionsSet with probabilityat least epsilonsubstantial regionSample Sintersects the setLarge-errorhypothesis detectedsample disagreementdefines probabilityepsilon-net hitsreveals disagreement
How does a finite sample become a coverage guarantee that rules out every hypothesis whose true error is at least epsilon?

Disagreement Class H_c

To apply epsilon-net coverage to classification, fix a target hypothesis c and compare every candidate h with c. For each h in H, form the set of domain points on which h and c disagree. The collection of all such disagreement sets is the class H_c.

Worked example

Turning Error into Set Intersection

Relate the true error of a hypothesis h to its disagreement set with the target c.

  1. 1
    Construct the set

    Take every point on which h and c produce different labels. Those points form the disagreement set associated with h.

  2. 2
    Measure the set

    Under the distribution D, the probability of this disagreement set equals the true error of h.

  3. 3
    Apply epsilon coverage

    If h has true error at least epsilon, its disagreement set has probability at least epsilon, so an epsilon-net must contain a sampled point from that set.

  4. 4
    Interpret the sampled point

    At that sampled point, h disagrees with c and therefore makes an error on a sample labeled according to c.

Result

The classification question has become a set-intersection question: every hypothesis with true error at least epsilon corresponds to a sufficiently probable disagreement set that the sample must hit.

Hcandidate hypothesesh disagrees with cone disagreement setH_call disagreement setsVC dimensionsame as Hctarget hypothesiscompare each hcompare with ccollect setsVCdim(H)VCdim(H_c)
How is H_c constructed from the original hypothesis class, and why does the construction preserve the class's ability to shatter points?

The PAC Proof Trace

Assume the realizable setting: the target c belongs to H, and the sample receives labels according to c. Consider a candidate h whose true error is at least epsilon. Its disagreement set with c therefore has probability at least epsilon. If the sample is an epsilon-net for H_c, the sample intersects that disagreement set, so h makes at least one error on the labeled sample.

VC dimension of Hcapacity measureVC dimension of H_csame complexitySample size mTheorem 28.3Epsilon-net coverageall large disagreement setsERM hypothesisconsistent with sampleTrue error at mostepsilonprobability at least 1minus deltapreserved by H_ccontrols required mprovides coverageexcludes large-error hrealizable PAC result
How does VC dimension control the relevant set class and lead from sample coverage to a PAC guarantee?

Because c is consistent with the sample, a hypothesis that makes a sampled error cannot be an empirical-risk minimizer. Therefore, once the sample intersects every disagreement set of probability at least epsilon, every hypothesis with true error at least epsilon is excluded from being an ERM hypothesis.

Definition

The realizable PAC guarantee stated in Theorem 28.4 is that, with probability at least 1 minus delta over the choice of m independent and identically distributed instances labeled according to c, any ERM hypothesis has true error at most epsilon. The sample size m is the one specified by Theorem 28.3.

Capacity Through Shattering

A classification class is more expressive when it can realize more different labelings of data points. VC dimension measures this capacity by asking for the largest number of points that can be shattered. A set of points is shattered when every possible binary labeling of those points can be produced by some classifier in the class.

In the PAC argument, VC dimension controls the complexity of the relevant hypothesis or disagreement class. The equality between the VC dimensions of H and H_c allows the complexity of H to be carried into the epsilon-net analysis. Thus, VC dimension connects the number of distinguishable labelings to the sample size needed for a high-probability learning guarantee.

Homogeneous Halfspaces

For homogeneous halfspaces in Rd, the separating boundary is required to pass through the origin. Their VC dimension is exactly d.

Worked example

The Lower Bound for Homogeneous Halfspaces

Show why homogeneous halfspaces can shatter d points in Rd.

  1. 1
    Choose points

    Use the d standard basis vectors e1 through ed. Each basis vector has a 1 in one coordinate and 0 in all other coordinates.

  2. 2
    Choose the weight vector

    For a desired binary labeling, use the desired labels as the coordinates of the weight vector w.

  3. 3
    Evaluate the dot products

    The dot product of w with the basis vector ei selects the i-th coordinate of w, so it equals the desired label associated with ei.

  4. 4
    Conclude shattering

    Because every binary labeling can be obtained by choosing the coordinates of w appropriately, the d basis vectors are shattered.

Result

Homogeneous halfspaces can shatter at least d points.

For the upper bound, take any d+1 vectors in Rd. They are linearly dependent, so there are real coefficients, not all zero, whose weighted combination is the zero vector. Separate the indices with positive coefficients from those with negative coefficients. If both groups are nonempty, a weight vector that assigns the required opposite signs would create incompatible sign conditions when applied to the dependence relation. If one group is empty, the corresponding side becomes an equality and the contradiction still follows. Therefore, no d+1 vectors can be shattered by homogeneous halfspaces.

Key point

The lower bound comes from explicitly shattering d basis vectors. The upper bound comes from the linear dependence that every collection of d+1 vectors in Rd must satisfy. Together, these establish VC dimension d.

Bias Adds One Degree

Non-homogeneous halfspaces in Rd include a bias term, so their separating boundary is not required to pass through the origin. Their VC dimension is exactly d+1.

Homogeneoushalfspaceweight vector wd shattered pointsstandard basis vectorsVC dimension dboundary through originNon-homogeneoushalfspaceweight vector w and biasd+1 shattered pointszero vector and basisvectorsVC dimension d+1bias shifts boundaryshattersupper and lower boundsshatterslower and upper bounds
What changes in the shattering argument when a halfspace gains a bias term, and why does the VC dimension increase from d to d+1?

For the lower bound, use the zero vector together with the d standard basis vectors. The source proof states that this set of d+1 vectors is shattered by non-homogeneous halfspaces, paralleling the homogeneous construction for the basis vectors.

For the upper bound, suppose d+2 vectors in Rd could be shattered by non-homogeneous halfspaces. The standard reduction described in the source converts this into d+2 vectors in Rd+1 shattered by homogeneous halfspaces. That contradicts the homogeneous result, because homogeneous halfspaces in Rd+1 have VC dimension d+1 and cannot shatter d+2 vectors. Hence the non-homogeneous VC dimension is d+1.

Weight vector wd coordinatesOrigin-constrainedboundaryVC dimension dBias termadditional parameterShifted boundaryVC dimension d+1determines separationworks with biasadds freedom
How do the d coordinates of the weight vector and the additional bias parameter affect the set of labelings that can be realized?

Common Reasoning Errors

  • Common mistake

    Treating an epsilon-net as a guarantee about only one selected set.

    What it looks like

    Checking that the sample intersects one high-probability region and concluding that it is an epsilon-net.

    Why it fails

    An epsilon-net must intersect every set in the relevant class whose probability is at least epsilon.

    Do this instead

    Keep the universal requirement in view: the same sample must cover all sufficiently probable sets in the class.

  • Common mistake

    Using the original hypotheses directly without constructing the disagreement class.

    What it looks like

    Arguing that a hypothesis with large error is excluded without identifying the set of points where it disagrees with c.

    Why it fails

    The epsilon-net argument operates on sets, while classification error is a property of hypotheses.

    Do this instead

    Associate each h with its disagreement set with c, then use the equality between true error and the distribution probability of that set.

  • Common mistake

    Assuming that a large true error automatically prevents ERM selection.

    What it looks like

    Saying that every inaccurate hypothesis is rejected by ERM even when its errors are not present in the sample.

    Why it fails

    ERM minimizes empirical risk, so the proof must show that a large-error hypothesis makes at least one sampled error.

    Do this instead

    Use epsilon-net coverage to force the sample to intersect the hypothesis's disagreement set.

  • Common mistake

    Forgetting the realizability condition.

    What it looks like

    Applying the stated ERM guarantee without requiring that the target c is in H and labels are generated according to c.

    Why it fails

    The argument relies on c being consistent with the sample, which makes a sampled-error hypothesis unable to minimize empirical risk.

    Do this instead

    State that the guarantee is for the realizable setting and for samples labeled according to c.

  • Common mistake

    Giving both kinds of halfspaces the same VC dimension.

    What it looks like

    Claiming that adding a bias term does not change the shattering result.

    Why it fails

    Homogeneous halfspaces in Rd have VC dimension d, while non-homogeneous halfspaces have VC dimension d+1.

    Do this instead

    Track whether the boundary must pass through the origin and whether a bias parameter is available.

Check Your Understanding

MEDIUM

Explain the complete elimination argument in your own words. Start with a hypothesis h whose true error is at least epsilon. Identify its disagreement set with c, explain why the set has probability at least epsilon, state what the epsilon-net guarantees, and finish by explaining why h cannot be an ERM hypothesis in the realizable setting.

Hints
  • Translate true error into the probability of a disagreement set.
  • Use the coverage property of an epsilon-net for H_c.
  • Remember that c is consistent with the labeled sample.
HARD

Compare the two halfspace classes. Explain why the standard basis vectors establish the lower bound d for homogeneous halfspaces, why linear dependence establishes the upper bound, and how the zero vector and bias term lead to d+1 for non-homogeneous halfspaces.

Hints
  • For homogeneous halfspaces, use the d standard basis vectors.
  • For the upper bound, consider d+1 vectors in Rd.
  • For non-homogeneous halfspaces, include the zero vector and use the reduction to one higher dimension.

Key Takeaways

  1. 1
    An epsilon-net intersects every set in the relevant class whose probability is at least epsilon.
  2. 2
    The disagreement class H_c converts the true classification error of h into the probability of a set.
  3. 3
    If the sample is an epsilon-net for H_c, every hypothesis with true error at least epsilon makes a sampled error and cannot be an ERM hypothesis in the realizable setting.
  4. 4
    VC dimension measures the largest number of points that a class can shatter and carries from H to H_c in the source argument.
  5. 5
    Homogeneous halfspaces in Rd have VC dimension d, while non-homogeneous halfspaces have VC dimension d+1 because the bias term adds one parameter of freedom.

At a glance

  • An epsilon-net turns finite sampling into coverage of every sufficiently probable set.
  • The disagreement class H_c links hypothesis error to set probability and preserves VC dimension according to the source argument.
  • In the realizable PAC setting, epsilon-net coverage excludes all hypotheses with true error at least epsilon from being ERM hypotheses.
  • VC dimension is the largest number of points a class can shatter.
  • Homogeneous halfspaces in Rd have VC dimension d, whereas non-homogeneous halfspaces have VC dimension d+1.

Related concepts

More concepts starting with V