TL;DR
A hypothesis class is the set of candidate rules that a learning algorithm is allowed to pick from. A supervised learner looks at labelled examples and returns one rule from this set, so the class fixes what the learner can ever express. It matters because a class that is too small cannot fit the data, and a class that is too large can fit noise and fail on new inputs.
Builds on: Supervised Learning, Function · Leads to: Empirical Risk Minimization, VC Dimension
Where it's used
Spam filters. A filter that uses a linear rule scores each email as a weighted sum of word counts and labels it spam when the score is high. The hypothesis class is the set of all weight choices. A filter built on decision trees has a different class, the set of all trees up to some depth. Choosing the class decides what kinds of patterns the filter can notice at all.
House price models. A real-estate company predicts a house price from its floor area. If it restricts itself to straight lines, its hypothesis class is "price equals a times area plus b", with two numbers to choose. If it allows curves of degree three, the class is larger and contains every straight line as a special case. The company's data and budget decide which class is sensible.
Image classifiers. A deep neural network with a fixed architecture defines a hypothesis class: every setting of its millions of weights gives one candidate rule. Training searches that class. The architecture, not only the training data, determines which rules are reachable.
How it works
Take three training examples, each an input with a known answer . The points are , and . We will compare two hypothesis classes.
- Class A: constant rules. Each candidate is for some number . The rule ignores the input and always answers .
- Class B: straight-line rules. Each candidate is for numbers and .
- Score each candidate. For each training point, measure the error . Add the three errors. Call the total the training loss.
- Search class A. The best constant is , the average of , and . Its errors are , and , so its training loss is . Any other constant does worse: gives .
- Search class B. The line passes through all three points exactly. Its training loss is .
- Compare. Class B contains a rule with zero training loss, and class A does not. The class decided what the learner could possibly reach, before any learning happened.
The picture shows the same comparison. The flat line at height misses two of the three points by , while the sloped line hits all three.
- class B: h(x) = 2x + 1
- class A: best constant
- training data
The learning process has the same shape every time. The class is fixed first, and the learner then picks one member of it:
flowchart LR D[labelled examples] --> P[choose a hypothesis class H] P --> L[score each rule in H on the examples] L --> R[return the best rule]
The math
A supervised learner receives training pairs , where each is an input and is its answer. The symbol means "and so on up to the last one". It also has a loss function that measures how wrong a prediction is against the answer ; for the squared error used above, . The loss function is the scoring rule from step 3.
A hypothesis class is a set of functions from the input space to the output space . Each element is a hypothesis, a candidate rule. The symbol means "is an element of", and is the set of all functions from inputs to outputs.
Step 2 in symbols
The two classes from the example are:
The set is the real numbers. Each class is an infinite set, but it is described by a short rule that generates its members. The notation reads "the set of all things of this form such that the condition holds".
Step 3 in symbols
The training loss of a hypothesis is the total loss over the training set:
The sum adds the terms for up to . For our three points, , and for the constant the sum is . Dividing by gives an average, which is common in practice, but it does not change which rule is best, so this lesson uses the total.
Steps 4 and 5 in symbols: searching each class
For class A, the sum is smallest at , the mean of the answers. For class B, the line , makes every term zero, so .
Step 6 in symbols
Learning chooses the best candidate in the class. This is empirical risk minimisation, written as an , which returns the input that makes the expression smallest:
The learner can only return something in . For class B, the minimum training loss is , reached by . For class A it is , reached by the constant . The minimum over a smaller set can never be smaller than the minimum over a larger set that contains it, which is why a bigger class always fits the training data at least as well.
Worked examples
Inputs are the numbers , , and . Let the class contain the four rules if and otherwise, for .
- List the rules by their output on each input. For the output is . For it is .
- Continue with : . Then : .
- The class therefore has exactly four members, one per threshold.
- Suppose the training inputs are with labels . Only the rule with matches all four labels, so training loss zero is possible.
Interpretation: a finite class is the easiest case to count. Here the learner chooses among four rules, and the size of the class is four.
Use the data from "How it works", and compare the training losses of class A and class B.
- Class B contains . Its predictions at are .
- Compare each prediction with its answer: , , .
- The squared errors are all , so the training loss is .
- Class A contains the constant . Its predictions are , and its squared errors are , and .
- The total is , so the best rule in class A has a training loss of .
Interpretation: the class with the better fit is the class that contains the true pattern. If the data came from a straight line, class B is the right choice; class A cannot represent a rising pattern at all.
A small training set records floor area in hundreds of square feet, , and price in tens of thousands of dollars, . The points are , , and . The hypothesis class is the straight lines .
- Find the best line by least squares. The mean of is and the mean of is .
- Compute the slope with . The numerator is and the denominator is , so .
- The intercept is , so the best line in the class is .
- Predictions at are , , and . The residuals, meaning answer minus prediction, are , , and .
- The squared errors are , , and , which add to a training loss of .
Try it: a rival learner uses the class of constant rules and predicts for every house. Compute the training loss of that constant rule, using the same four points and the same squared error. Answer: the residuals are , , and , with squares , , and . They add to , far above . The straight-line class wins on the training data, and the question left open is whether it also wins on new houses.
Common mistakes and tradeoffs
"The hypothesis class is the learned model." It is tempting to say that a linear model is the class and the fitted line is the class too. In fact the class is the set of all lines the learner could have returned, and the fitted line is one member of it. Changing the data changes the member, not the class.
"A bigger class is always better." It is tempting to pick the largest class available, since it contains more rules and so fits the training data better. In fact a bigger class can fit the random noise in the training set, which is called Overfitting. The training loss falls while the error on new inputs rises. A class with a larger VC dimension needs more data before its training error can be trusted.
"Any class will do if we have enough data." More data does help, but the class still sets a floor on the error. If the true pattern is curved and the class contains only straight lines, the learner cannot reach low error however much data it sees. This gap is the bias part of the bias-variance tradeoff.
When to use a simple class. A small class such as straight lines is the right choice when data is limited, when the relation is close to linear, or when the model must be explained to a person. It is easy to fit and hard to overfit. A rich class such as deep networks is the right choice when data is plentiful and the pattern is complicated, and then regularisation and validation sets are needed to control overfitting.
Alternatives. Instead of changing the class, many methods keep a large class and add a penalty that pushes the learner toward simpler members. The class is still large, but the choice inside it is restricted. The Inductive Bias of a learner is the combined effect of the class and this preference.
History
The idea that learning means choosing a rule from a fixed set of candidates goes back at least to Ronald Fisher's linear discriminant of 1936, and to the pattern-recognition work of the late 1950s, such as Rosenblatt's perceptron, which chose its rule from the family of linear threshold rules. In 1984, Leslie Valiant's PAC framework made the question precise: how much data is needed to choose a good rule from a given class.
Vladimir Vapnik and Alexey Chervonenkis showed in the 1960s and 1970s that the complexity of a class, which later became the VC dimension, controls how far the training error can be trusted. This result explained why bigger classes need more data. It caught on because it turned a vague worry about overfitting into a number that can be compared across models.
Recap
- A learner is given labelled examples and a hypothesis class, which is a set of candidate rules.
- The class fixes what can be learned at all: a class without the true pattern cannot reach low error.
- Training loss scores each candidate on the examples, and empirical risk minimisation returns the best candidate in the class.
- A larger class always reaches a training loss at least as low, but it can overfit, so the class must match the amount of data.
- Next, read Empirical Risk Minimization for the selection step in detail, and VC Dimension for how the size of a class is measured. The class is also what Inductive Bias describes.
Check yourself
QuestionA hypothesis class contains only the constant rules . Can it achieve zero training loss on the points and ?Show answer
No. A constant rule predicts the same value for both inputs, so it predicts one . To match answers and , we would need and at once, which is impossible. The lowest training loss is reached at , where the squared errors are and , a total of .
QuestionFor the class of rules , with the single training point , which value of gives zero training loss, and what is the training loss at ?Show answer
Zero loss needs , so . At the prediction is , the error is , and the squared loss is .
QuestionWhy does adding more and more rules to a hypothesis class eventually stop reducing error on new data, even while the training loss keeps falling?Show answer
A larger class lets the learner fit random details of the training set, not only the true pattern. Those details do not repeat in new data, so the learned rule makes mistakes there even though it fits the training examples well. This is overfitting, and it is why the class must be matched to the amount of data.
QuestionA hospital trains a model to predict a risk score from 20 measurements per patient, using only 30 patients. It considers a class of very high-degree polynomial rules. Why is this a poor choice, and what would you change?Show answer
With 30 patients and a class that can bend in many ways, the model can pass through nearly every training point while learning noise, so its training loss looks excellent and its predictions for new patients are unreliable. A better choice is a smaller class, such as linear rules with a penalty on their weights, and a held-out validation set to test the choice. This is educational only, and a real clinical model needs expert review.
Sources
- Shalev-Shwartz and Ben-David, Understanding Machine Learning: From Theory to Algorithms: https://www.cs.huji.ac.il/~shais/UnderstandingMachineLearning/
- Supervised learning, Wikipedia: https://en.wikipedia.org/wiki/Supervised_learning
- Bishop, Pattern Recognition and Machine Learning: https://www.microsoft.com/en-us/research/publication/pattern-recognition-machine-learning/