skip to content

What does the VC dimension of a classifier class measure, and why is a line in the plane 3?

level: middleimportance: nice to knowfreq 30%

answer

  1. counting labelings you can realise
  2. all 2^m assignments, not just one
  3. some set of that size, not every set
  4. three corners yes, any four no

basics

~20 s

VC dimension is the largest number of points a classifier class can label in every possible way. Some 3 non-collinear points admit all 8 labelings by a line, but no 4 points do, so the answer is 3.

solid answer

~50 s

A class **shatters** a set of m points if, for each of the 2^m ways of labelling those points positive or negative, some member of the class realises that labelling exactly. The VC dimension is the size of the largest set the class can shatter - a distribution-free measure of how expressive the class is. For a linear classifier in the plane, take any 3 points not on a line: all 8 labelings are separable by some line, so 3 is achieved. No set of 4 points works - either one point sits inside the triangle of the others, or the four are in convex position and the two-diagonal labelling cannot be split by a line. Hence VC dimension 3, and in d dimensions a linear separator has VC dimension d+1. Note the quantifiers: *some* set of size h is shattered, not every set.

go deeper

for a junior

Recognise the term and know it is a formal way of measuring how flexible a model class is. Being able to say that a straight line in the plane scores 3 is enough at this level.

for a middle

Define shattering in terms of realising all 2^m labelings, get the quantifiers right, and give both halves of the line-in-the-plane argument: a triangle works, no four points do.

for a senior

Show that you know where the concept stops being practical - bounds that hold for all distributions are far too loose to size a real model - and use it mainly as the counterexample to counting parameters.

for a principal

Be able to place learning theory correctly in a team's toolkit: valuable as shared vocabulary for capacity and for shutting down parameter-counting arguments, not as a substitute for empirical held-out evaluation.

## Shattering Start with the definition that everything else hangs on. Take a set of m points in the input space and a class of binary classifiers. There are 2^m ways to assign positive/negative labels to those m points. The class **shatters** the set if for *every one* of those 2^m assignments there exists a member of the class that produces exactly that assignment. Shattering is a strong requirement. It is not enough to classify the points well, or to get one particular labelling right; the class must be able to produce all of them, including the perverse ones. ## The definition The **VC dimension** (Vapnik-Chervonenkis dimension) of a class is the size of the largest set of points it can shatter. Write it h. If the class can shatter arbitrarily large sets, its VC dimension is infinite. The quantifiers matter and are the most common place candidates slip: - **h is achieved by some set**, not by every set. To show h >= 3, you exhibit *one* set of 3 points that is shattered. - **h is bounded by every set**, not by some set. To show h < 4, you must argue that *no* set of 4 points can be shattered. ## Why a line in the plane has VC dimension 3 The class is all linear classifiers in two dimensions: pick a straight line, call one side positive and the other negative. **Lower bound - 3 is achieved.** Place 3 points at the corners of a triangle (any 3 non-collinear points). There are 8 labelings: all positive, all negative, and six with one or two points on the minority side. Every one of them can be produced by some line, because a single corner or a single edge can always be cut off from the rest. So a set of size 3 is shattered. Note that this needs the right set. Three points on a straight line, with the middle one labelled differently from the outer two, cannot be separated by any line. That does not lower the VC dimension - existence of one shatterable set is what the definition asks for. **Upper bound - 4 is impossible.** Take any 4 points in the plane. Two cases exhaust the possibilities. If one point lies inside the triangle formed by the other three, label the inner point negative and the outer three positive: no line can isolate an interior point. If the four are in convex position - the corners of a quadrilateral - label the two ends of one diagonal positive and the two ends of the other negative: the two diagonals cross, so no line can separate the pairs. Since every configuration of 4 points falls into one of these cases, no 4-point set is shattered. Combining the two, h = 3. The general result is that a linear separator in d dimensions has VC dimension d+1 - a line in the plane is the d=2 case. ## Another worked class Axis-aligned rectangles in the plane, labelling everything inside the rectangle positive, have VC dimension 4. Four points arranged as the extreme top, bottom, left and right of a diamond can be shattered: for any subset you want positive, take the tightest axis-aligned rectangle around those points, and it excludes the others. No set of 5 points can be shattered, because for any 5 points at least one is not extreme in any of the four directions, and any rectangle containing the other four must also contain it. ## Capacity is not parameter count It is tempting to read VC dimension as a synonym for "number of free parameters", and for the two classes above it happens to be close. It is not a rule. The one-parameter family of classifiers of the form sign(sin(a*x)), with a single real parameter a, has infinite VC dimension: by tuning the frequency you can realise any labelling of arbitrarily many suitably placed points. One parameter, unbounded capacity. This is the cleanest argument against measuring flexibility by counting parameters - and the reason a formal measure was wanted in the first place. ## What it is for, and its limits VC dimension appears in generalization bounds that have the shape: with high probability, true error is at most training error plus a term that grows with h and shrinks as the sample size n grows, roughly like the square root of h/n up to logarithmic factors. Two readings follow. Qualitatively it says exactly what the capacity story says: for a fixed sample, more capacity buys a looser guarantee, and for a fixed class, more data tightens it. Quantitatively, the bounds are usually far too loose to use as numbers. They hold for *every* data distribution, which is a very pessimistic requirement, and many useful classes have infinite or unknown VC dimension. So treat VC dimension as a conceptual tool that makes "capacity" precise and distribution-free, not as something you compute to size a model. In an interview it is fair game as a definition and as the source of the parameter-count counterexample; claiming you tuned a model with a VC bound is not credible.

  • Why is the definition 'some set of size h', rather than 'every set of size h'?
    Because degenerate configurations would otherwise drag the measure to nothing. Three collinear points cannot be shattered by a line, yet a line is clearly more expressive than a class that shatters nothing. The definition asks for the best case at each size, which makes the measure about the class rather than about unlucky point placements.
  • Do more parameters always mean a higher VC dimension?
    No. The one-parameter family sign(sin(a*x)) has infinite VC dimension, because tuning the frequency can realise any labelling of arbitrarily many well-placed points. Parameter count is a rough intuition for flexibility, not a measure of it, which is precisely why a definition based on realisable labelings was introduced.
  • What is the VC dimension of a linear classifier in d dimensions?
    d+1, counting the offset. A line in the plane is the d=2 case and gives 3; a plane in three dimensions gives 4. This is one of the few classes where the answer is both clean and matches the free-parameter count, which is part of why it is the standard example.
  • Are VC generalization bounds useful for picking a model in practice?
    Rarely as numbers. They hold for every data distribution, so they are extremely conservative, and the resulting error bounds are often above one for realistic sample sizes. Their value is qualitative: they formalise why error on unseen data degrades with capacity and improves with sample size. Held-out estimates do the practical work.

saying these in an interview costs you the question

  • Says VC dimension equals the parameter count
  • Claims every 3 points are shattered by a line
  • Thinks shattering means classifying the points correctly once
  • Treats a VC bound as a usable error estimate
  • Assumes infinite VC dimension makes a class useless

context