Search

Search papers and lessons

Hypothesis Class

Level 3 · 10 min read

A hypothesis class is the set of candidate rules a learner is allowed to choose from, and choosing that set is the first and most important decision in supervised learning.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • Probability
  • Learning basics
  • Losses & regularization
  • ReadReady to readNot yet

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 xx with a known answer yy. The points are (0,1)(0, 1), (1,3)(1, 3) and (2,5)(2, 5). We will compare two hypothesis classes.

  1. Class A: constant rules. Each candidate is h(x)=ch(x) = c for some number cc. The rule ignores the input and always answers cc.
  2. Class B: straight-line rules. Each candidate is h(x)=ax+bh(x) = a x + b for numbers aa and bb.
  3. Score each candidate. For each training point, measure the error (h(x)−y)2(h(x) - y)^2. Add the three errors. Call the total the training loss.
  4. Search class A. The best constant is c=3c = 3, the average of 11, 33 and 55. Its errors are (1−3)2=4(1-3)^2 = 4, (3−3)2=0(3-3)^2 = 0 and (5−3)2=4(5-3)^2 = 4, so its training loss is 88. Any other constant does worse: c=2c = 2 gives 1+1+9=111 + 1 + 9 = 11.
  5. Search class B. The line h(x)=2x+1h(x) = 2x + 1 passes through all three points exactly. Its training loss is 00.
  6. 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 33 misses two of the three points by 22, while the sloped line hits all three.

−0.500.511.522.50123456xy
  • class B: h(x) = 2x + 1
  • class A: best constant
  • training data
The straight line fits every point. The best constant rule misses the two outer points, and no constant can do better.

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 (x1,y1),…,(xn,yn)(x_1, y_1), \ldots, (x_n, y_n), where each xix_i is an input and yiy_i is its answer. The symbol …\ldots means "and so on up to the last one". It also has a loss function ℓ(y^,y)\ell(\hat{y}, y) that measures how wrong a prediction y^\hat{y} is against the answer yy; for the squared error used above, ℓ(y^,y)=(y^−y)2\ell(\hat{y}, y) = (\hat{y} - y)^2. The loss function is the scoring rule from step 3.

Definition: Hypothesis class

A hypothesis class H\mathcal{H} is a set of functions from the input space X\mathcal{X} to the output space Y\mathcal{Y}. Each element h∈Hh \in \mathcal{H} is a hypothesis, a candidate rule. The symbol ∈\in means "is an element of", and X→Y\mathcal{X} \to \mathcal{Y} is the set of all functions from inputs to outputs.

Step 2 in symbols

The two classes from the example are:

HA={ hc:hc(x)=c,  c∈R },HB={ ha,b:ha,b(x)=ax+b,  a,b∈R }.\mathcal{H}_A = \{\, h_c : h_c(x) = c,\; c \in \mathbb{R} \,\}, \qquad \mathcal{H}_B = \{\, h_{a,b} : h_{a,b}(x) = a x + b,\; a, b \in \mathbb{R} \,\}.

The set R\mathbb{R} is the real numbers. Each class is an infinite set, but it is described by a short rule that generates its members. The notation { ⋅ : ⋅ }\{\, \cdot \,:\, \cdot \,\} reads "the set of all things of this form such that the condition holds".

Step 3 in symbols

The training loss of a hypothesis hh is the total loss over the training set:

R^(h)=∑i=1nℓ(h(xi),yi).\widehat{R}(h) = \sum_{i=1}^{n} \ell\big(h(x_i), y_i\big).

The sum ∑i=1n\sum_{i=1}^{n} adds the terms for i=1i = 1 up to nn. For our three points, n=3n = 3, and for the constant c=3c = 3 the sum is (1−3)2+(3−3)2+(5−3)2=8(1-3)^2 + (3-3)^2 + (5-3)^2 = 8. Dividing by nn 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 ∑i(c−yi)2\sum_{i}(c - y_i)^2 is smallest at c=3c = 3, the mean of the answers. For class B, the line a=2a = 2, b=1b = 1 makes every term zero, so R^=0\widehat{R} = 0.

Step 6 in symbols

Learning chooses the best candidate in the class. This is empirical risk minimisation, written as an argmin⁡\operatorname{argmin}, which returns the input that makes the expression smallest:

h^=argmin⁡h∈HR^(h).\hat{h} = \operatorname*{argmin}_{h \in \mathcal{H}} \widehat{R}(h).

The learner can only return something in H\mathcal{H}. For class B, the minimum training loss is 00, reached by h^(x)=2x+1\hat{h}(x) = 2x + 1. For class A it is 88, reached by the constant 33. 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

Example
1. A finite class of threshold rules

Inputs are the numbers 00, 11, 22 and 33. Let the class contain the four rules ht(x)=1h_t(x) = 1 if x≥tx \ge t and ht(x)=0h_t(x) = 0 otherwise, for t∈{0,1,2,3}t \in \{0, 1, 2, 3\}.

  1. List the rules by their output on each input. For t=0t = 0 the output is 1,1,1,11, 1, 1, 1. For t=1t = 1 it is 0,1,1,10, 1, 1, 1.
  2. Continue with t=2t = 2: 0,0,1,10, 0, 1, 1. Then t=3t = 3: 0,0,0,10, 0, 0, 1.
  3. The class therefore has exactly four members, one per threshold.
  4. Suppose the training inputs are 0,1,2,30, 1, 2, 3 with labels 0,0,1,10, 0, 1, 1. Only the rule with t=2t = 2 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.

Example
2. Lines against data with a clean answer

Use the data from "How it works", and compare the training losses of class A and class B.

  1. Class B contains h(x)=2x+1h(x) = 2x + 1. Its predictions at x=0,1,2x = 0, 1, 2 are 1,3,51, 3, 5.
  2. Compare each prediction with its answer: 1−1=01 - 1 = 0, 3−3=03 - 3 = 0, 5−5=05 - 5 = 0.
  3. The squared errors are all 00, so the training loss is 00.
  4. Class A contains the constant 33. Its predictions are 3,3,33, 3, 3, and its squared errors are 44, 00 and 44.
  5. The total is 88, so the best rule in class A has a training loss of 88.

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.

Example
3. Fitting house prices with a straight-line class

A small training set records floor area in hundreds of square feet, xx, and price in tens of thousands of dollars, yy. The points are (1,2)(1, 2), (2,3)(2, 3), (3,4)(3, 4) and (4,6)(4, 6). The hypothesis class is the straight lines h(x)=ax+bh(x) = a x + b.

  1. Find the best line by least squares. The mean of xx is 2.52.5 and the mean of yy is 3.753.75.
  2. Compute the slope with a=∑(xi−2.5)(yi−3.75)∑(xi−2.5)2a = \dfrac{\sum (x_i - 2.5)(y_i - 3.75)}{\sum (x_i - 2.5)^2}. The numerator is 2.625+0.375+0.125+3.375=6.52.625 + 0.375 + 0.125 + 3.375 = 6.5 and the denominator is 2.25+0.25+0.25+2.25=52.25 + 0.25 + 0.25 + 2.25 = 5, so a=1.3a = 1.3.
  3. The intercept is b=3.75−1.3×2.5=0.5b = 3.75 - 1.3 \times 2.5 = 0.5, so the best line in the class is h(x)=1.3x+0.5h(x) = 1.3x + 0.5.
  4. Predictions at x=1,2,3,4x = 1, 2, 3, 4 are 1.81.8, 3.13.1, 4.44.4 and 5.75.7. The residuals, meaning answer minus prediction, are 0.20.2, −0.1-0.1, −0.4-0.4 and 0.30.3.
  5. The squared errors are 0.040.04, 0.010.01, 0.160.16 and 0.090.09, which add to a training loss of 0.300.30.

Try it: a rival learner uses the class of constant rules and predicts 3.753.75 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 −1.75-1.75, −0.75-0.75, 0.250.25 and 2.252.25, with squares 3.06253.0625, 0.56250.5625, 0.06250.0625 and 5.06255.0625. They add to 8.758.75, far above 0.300.30. 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 h(x)=ch(x) = c. Can it achieve zero training loss on the points (0,1)(0, 1) and (1,2)(1, 2)?Show answer

No. A constant rule predicts the same value for both inputs, so it predicts one cc. To match answers 11 and 22, we would need c=1c = 1 and c=2c = 2 at once, which is impossible. The lowest training loss is reached at c=1.5c = 1.5, where the squared errors are 0.250.25 and 0.250.25, a total of 0.50.5.

QuestionFor the class of rules h(x)=axh(x) = a x, with the single training point (2,6)(2, 6), which value of aa gives zero training loss, and what is the training loss at a=2a = 2?Show answer

Zero loss needs a⋅2=6a \cdot 2 = 6, so a=3a = 3. At a=2a = 2 the prediction is 44, the error is 6−4=26 - 4 = 2, and the squared loss is 44.

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