TL;DR
A classifier family is a set of rules, such as all straight lines in the plane, that each label points as positive or negative. Its VC dimension is the largest number of points that the family can label in every possible way. This number measures how flexible the family is, and it controls how far the error on training examples can drift from the error on new examples. A family with a small VC dimension cannot memorise much, so good training results are more trustworthy.
Builds on: Linear Classifier, Counting Principles · Leads to: Rademacher Complexity, Overfitting
Where it's used
- Choosing how complex a model may be. Before training a Supervised Learning spam filter on a few thousand emails, a team can count the features and ask whether a linear rule over them is flexible enough to memorise the training set. The VC dimension gives a number for that flexibility, so the team can compare it with the size of the dataset.
- Explaining why large models can still generalise. Theory based on VC dimension was one of the first general accounts of why learning from finite samples works. It set the vocabulary, the words "shattering" and "capacity", that later generalisation bounds still use.
- Support vector machines. A Support Vector Machine is a linear classifier with a margin. The margin-based generalisation bounds for it are built on the VC analysis of linear classifiers, whose VC dimension is the number of features plus one.
- Comparing model families on paper. Before running an experiment, a researcher can say that a Feedforward Neural Network with many weights has a VC dimension that grows with its number of weights, so the bound on its gap between train and test error is correspondingly loose.
How it works
We use the simplest family that has a non-trivial answer: threshold classifiers on the number line. A threshold labels a point as positive if and negative otherwise.
- Pick one point. Put on the line. Can a threshold label it positive? Yes, with . Can it label it negative? Yes, with . Both labelings occur, so the family handles this one point in every way. Check: there are labelings for one point, and both are achievable.
- Add a second point. Put to the right, so . The four labelings are (negative, negative), (negative, positive), (positive, positive) and (positive, negative). Try the last one. To make positive and negative we would need , which is impossible when . So three of the four labelings occur. Check: the family handles two points in only three of the four ways.
- Conclude the definition. A set of points is shattered if the family realises every labeling of it. One point is shattered, and no pair is. The VC dimension of thresholds is 1.
- Add the general counting idea. For points, a family can realise at most labelings. The number it realises on a specific set of points is the count from step 2. The largest such count over all sets of points is its growth function. A set is shattered exactly when its count reaches .
- Why it matters. When the growth function stays small as grows, the family cannot fit random labels on many points, so the gap between training and test error shrinks as data grows.
- Check against the definition. Thresholds on a line: one point shattered, two points not, so the VC dimension is 1.
flowchart TD
A[Choose m points] --> B[List every labeling of the m points]
B --> C{Does the family produce every labeling?}
C -- yes --> D[The set is shattered, so the VC dimension is at least m]
C -- no --> E[Try another set of m points]
E --> B
The diagram is the test in step 3: for each candidate set, list the labelings and check whether the family produces all of them. The VC dimension is the largest for which some set passes.
The math
Let be a family of functions . For a finite set , the set of labelings that produces is
Step 3 in symbols: shattering and the VC dimension
is shattered by when . The VC dimension is
Read it as the largest size at which at least one set of points can be labelled every way. One shattered set of size is enough to count, but the VC dimension is the largest for which that happens. So no set of points can be shattered when the VC dimension is .
Step 4 in symbols: the growth function
The growth function is , the most labelings any points can produce. By the counting principle from Counting Principles, it is at most . The Sauer–Shelah lemma says that once exceeds the VC dimension , it grows only polynomially:
The right side is a polynomial in of degree , which is far smaller than when is large.
Beyond thresholds: linear classifiers
A linear classifier in is . Its VC dimension is . In the plane (), lines have VC dimension 3. This matches the examples below.
The generalisation bound, in order of magnitude
Let the family have VC dimension and let the training set hold examples drawn at random. With probability at least over the random draw of the examples (the usual Probability statement), every in the family has test error at most its training error plus a term of order
The constants are omitted here on purpose. The point is the shape: the gap is governed by and shrinks like . The proof uses tail bounds such as Concentration Inequalities. Empirical Risk Minimization trains a model to make the training error small, and this bound controls the rest.
Worked examples
- Family: thresholds if , else .
- One point : labelings and both occur (choose below or above ). Shattered.
- Two points : the labeling would need , impossible. Not shattered.
- So the largest shattered size is 1.
- Interpretation: a threshold rule can only switch once along the line, so it cannot represent an alternating pattern on two points. Its VC dimension is 1.
- Family: all lines in the plane, labeling points on one side and the other side .
- Three points that are not on one line form a triangle. Each of the 8 labelings can be drawn: all positive or all negative by a line far away; one positive point by a line cutting off one corner; two positive points by a line separating that pair from the third. So the triangle is shattered.
- Four points: either one point lies inside the triangle of the other three, or the four form a convex quadrilateral. In the first case, labeling the inner point and the three outer points cannot be done by a line. In the second case, labeling the two diagonal pairs with opposite signs (the XOR pattern) cannot be done by a line.
- So no four points are shattered, and the VC dimension of lines in the plane is 3.
- Interpretation: 3 equals with , matching the formula in the math section.
A linear spam filter uses 10 word-count features, so and its VC dimension is . It is trained on emails.
- The VC dimension is 11, so the flexibility term in the bound scales with .
- The term is of order . With , the numerator is about , and dividing by 1000 and taking the square root gives a term of order 0.3 before the constant.
- Interpretation: the bound on the train-test gap is loose at this sample size, because the constant is large and the guarantee is worst-case over all linear rules. It still tells the team that more emails shrink the gap, and that adding features without more data widens it.
- A practical response is to validate on held-out emails rather than rely on the bound.
Try it: intervals on the line, labelled inside and outside. What is the VC dimension? Answer: 2. Two points can be labelled in all four ways by choosing the interval to contain either, both or neither. For three points , the labeling would need an interval containing and but not , which is impossible. So the largest shattered size is 2.
Common mistakes and tradeoffs
- Thinking VC dimension counts parameters. It is tempting to say a model with 100 weights has VC dimension 100. In fact VC dimension measures the labelings a family can produce, which can be far smaller or larger than the parameter count. Linear classifiers happen to have parameters (weights plus bias) and VC dimension , but that match does not carry over to other families.
- Confusing "some set" with "every set". It is tempting to think a family fails to shatter as soon as one set cannot be shattered. In fact the definition needs only one set of size that is shattered. Four points that are not shattered do not rule out a different set of three that is.
- Assuming a large VC dimension means overfitting. It is tempting to conclude that a high VC dimension always overfits. In fact the bound is worst-case, and a large family can still generalise when the data are well structured and training stops early (see Early Stopping). VC dimension tells you what is possible, not what happens.
- Trusting the bound's numbers. The bound gives a valid guarantee but is often loose enough to be useless for real sample sizes. Use it to compare families and to see how error scales, not to predict test error.
Use VC dimension when you want a worst-case, distribution-free statement about a family of classifiers, or when you want to compare the flexibility of two families. For a number on a specific problem, look to a held-out set (see Train, Validation and Test Sets) or to Cross-Validation, which measure the real error instead of a bound. Look to Rademacher Complexity when you want a data-dependent bound that is often tighter.
History
Vladimir Vapnik and Alexey Chervonenkis introduced the idea in the late 1960s and published their uniform convergence results in 1971. Their work showed that, for many families, the difference between training and test frequencies can be controlled uniformly over the whole family, through the shattering property. The field was slow to take it up in practice, partly because the bounds were loose. In the 1990s, Vapnik's support vector machines brought the ideas into machine learning practice, and his 1998 book on statistical learning theory made the framework standard.
Recap
- A classifier family is a set of rules that each give labels to points.
- A set of points is shattered when the family produces every labeling of it.
- The VC dimension is the largest size at which some set can be shattered.
- Thresholds on a line have VC dimension 1, lines in the plane have 3, and linear classifiers in have .
- The VC dimension controls a bound on the gap between training and test error, of order up to logs.
- Next, read Rademacher Complexity for a data-dependent alternative, and Overfitting for what the gap looks like in practice.
Check yourself
QuestionIn your own words, what does it mean for a set of points to be shattered by a family of classifiers?Show answer
A set is shattered when the family can produce every possible labeling of its points. For points there are labelings, so shattering means the family realises all of them.
QuestionWhat is the VC dimension of intervals on the number line that are labelled positive inside?Show answer
Two points can be shattered, as shown in the Try-it example, and three points cannot, because the labeling that is positive at the ends and negative in the middle needs a non-interval. So the answer is 2.
QuestionWhy does a model with a small VC dimension generalise more reliably from a fixed amount of data?Show answer
A family with a small VC dimension can produce few labelings on any set of points, so it cannot fit random labels well. That keeps the gap between training and test error small, because the bound on the gap grows with the VC dimension and shrinks with the number of examples.
QuestionLines in the plane have VC dimension 3. How many features does a linear classifier need to have VC dimension 11, and why does that matter for a dataset of 50 examples?Show answer
VC dimension needs features. With only 50 examples the bound on the train-test gap is large, because the flexibility term is big compared with the sample size, so training error alone says little about test error.
QuestionGive one reason a high VC dimension does not guarantee overfitting in practice.Show answer
The VC bound is a worst-case statement over all rules in the family. Real training uses a specific algorithm, often with early stopping or regularisation, that picks a rule far from the worst case, so the actual gap can be small.
Sources
- Wikipedia, "Vapnik–Chervonenkis dimension": https://en.wikipedia.org/wiki/Vapnik%E2%80%93Chervonenkis_dimension
- Wikipedia, "Statistical learning theory": https://en.wikipedia.org/wiki/Statistical_learning_theory