Hypothesis Spaces: What a Model Is Allowed to Learn
Understand the set of functions a learning algorithm can choose from, why its size matters, and how it splits model error into parts.
Key takeaways
- The hypothesis space, written H, is the collection of candidate functions, and one choice of parameter values picks out one member.
- A richer space can represent more patterns but generally needs more data or stronger constraints to pick a good member.
- Error splits usefully into what the space cannot express, what limited data gets wrong, and what the search procedure fails to find.
- The functions that training actually reaches depend on the optimizer, regularization and stopping rule as well as the model's formula.
- You choose among spaces with held-out data, since training error alone always favors the larger of two nested spaces.
A hypothesis space is the set of all input-to-output functions your learning method can possibly return. Training does not invent a function from nothing. It searches this set for a member that fits the data well, so anything outside the set is unavailable however much data you collect.
Choosing a model class is therefore a choice about what can be learned at all. Make the set too narrow and no member describes the pattern. Make it very wide and many members fit your examples while disagreeing about new ones.
Functions as the things being searched
Take predicting y from a single number x. Here are three hypothesis spaces:
| Name | Form of each member | Parameters |
|---|---|---|
| Constants | ŷ = b | b |
| Lines | ŷ = wx + b | w, b |
| Quadratics | ŷ = ax² + wx + b | a, w, b |
Each setting of the parameters gives one hypothesis, a single concrete function. The space is every function you can get by varying them. These three are nested: every constant is a line with w = 0, and every line is a quadratic with a = 0.
Consider the data points (0, 1), (1, 3) and (2, 5). Under squared error, the best constant is the mean of the targets, 3. Its errors are −2, 0 and 2, so the mean squared error is 8/3, about 2.67. The best line is ŷ = 2x + 1, which has zero error. The quadratic space also reaches zero, by setting a = 0.
Counting a space that is finite
Discrete problems make the size concrete. With 3 binary inputs there are 2³ = 8 possible input patterns. A function to a yes or no answer assigns one of two outputs to each pattern, giving 2⁸ = 256 distinct functions. With 5 inputs there are 32 patterns and 2³² functions, a little over 4 billion.
Now restrict the space to conjunctions: rules like "x₁ is true and x₃ is false". Each input can be required true, required false or ignored, so with 3 inputs there are 3³ = 27 rules, plus one more if you include the rule that always says no. That is 28 out of 256.
The restriction pays off in learning speed. Every labeled example eliminates the hypotheses that disagree with it, and a small space gets narrowed down quickly. In the unrestricted space, seeing 5 of the 8 patterns leaves 2³ = 8 functions still consistent, split evenly on each unseen pattern. The data alone says nothing about them.
The price is that if the truth is "x₁ or x₂", no conjunction matches it. This is the basic bargain behind the assumptions every learner has to make.
Familiar models and their spaces
| Model family | What its members look like |
|---|---|
| Linear classifier | One flat boundary through feature space |
| Decision tree of depth k | Up to 2ᵏ regions, each cut along feature axes, each with its own output |
| k-nearest neighbors | Functions determined by the stored data and k |
| Neural network of fixed shape | Every function obtainable by setting its weights |
Changing the features changes the space too. A linear model on x alone draws straight lines. The same linear algorithm given the features x and x² produces parabolas. The model is still linear in its parameters while being curved in the original input, which is the idea behind feature expansions and kernel methods.
Three sources of error
Let the risk of a function be its expected loss on new data from the same source. Suppose f* is the best possible predictor, h* is the best member of H, and ĥ is what your training run returns. The excess risk of ĥ over f* can be split as follows:
R(ĥ) − R(f*) = [R(h*) − R(f*)] approximation: limits of H
+ [R(h_n) − R(h*)] estimation: only n examples
+ [R(ĥ) − R(h_n)] optimization: imperfect search
h_n = the member of H with the lowest loss on the n training examples The three terms add up exactly, since the middle quantities cancel. Even f* usually has some error, because the inputs rarely determine the output completely.
Enlarging H shrinks the approximation term or leaves it unchanged. It tends to enlarge the estimation term, since there are more ways to be fooled by chance patterns. This tension appears again as the bias-variance tradeoff. The optimization term depends on how hard the search is, and it explains why a model that can express a solution may still fail to find it.
A worked look at too narrow and too wide
Suppose the truth is a gentle curve, y = x², observed without noise at x = −1, 0 and 1, giving targets 1, 0 and 1.
The best line under squared error is flat: ŷ = 2/3. Its slope is zero because the data are symmetric, and its errors are 1/3, −2/3 and 1/3. The mean squared error is 2/9, about 0.22. More copies of the same three points will not reduce it, because no line can bend. That is approximation error.
The quadratic space contains the truth, and three distinct points determine a quadratic exactly. Now move to polynomials of degree 3. The function x² + c·(x³ − x) passes through all three points for every value of c, since x³ − x is zero at −1, 0 and 1. At x = 2 it predicts 4 + 6c, which can be any number at all.
Nothing in the data prefers one c over another. Something else has to choose: a preference for small coefficients would pick c = 0, and a different preference would pick something else.
The space you search is smaller than the space you wrote
A neural network's formula describes an enormous set of functions. What gradient descent produces from a particular random starting point, with a particular learning rate and number of steps, is a much more restricted selection.
Several tools narrow the effective space on purpose:
- Penalties on large weights make some functions expensive without forbidding them.
- Early stopping halts the search before it can reach more extreme parameter settings.
- Constraints such as sparsity, monotonicity or shared weights remove whole groups of functions.
- Structure, as in convolutional layers, builds an assumption about the input into the form itself.
This is why counting parameters is a rough guide to capacity at best. Two models with the same count can behave very differently, and regularization controls capacity without changing the count at all.
Measuring how big a space is
For finite spaces, the count itself, usually through its logarithm, appears in learning guarantees. Lines have infinitely many members, so theorists use other measures. The best known, the VC dimension, asks for the largest set of points the space can label in every possible way. Straight-line classifiers in the plane can realize all labelings of 3 points in general position but cannot do so for any set of 4, so their VC dimension is 3. See VC dimension and capacity for the argument.
These measures give worst-case bounds that are often loose for large neural networks. They explain trends well and predict specific error rates poorly.
Choosing a space in practice
You normally compare several spaces: tree depths, polynomial degrees, network sizes. The settings that select among them are hyperparameters.
- Start with a simple space that gives a baseline you understand.
- Fit it and compare training error with validation error.
- If both are high, try a richer space or better features.
- If training error is low but validation error is much higher, constrain the space or get more data.
- Pick using validation data, then report once on an untouched test set.
Training error cannot make this choice. In nested spaces, the best achievable training loss never rises as the space grows, so it would always point to the biggest one.
Domain knowledge is the other guide. If output should never fall as input rises, a monotonic constraint removes many wrong answers before you see any data. If the pattern repeats yearly, give the model a way to express periodicity.
Common questions
Is a hypothesis here the same as a statistical hypothesis?
No. In learning theory a hypothesis is a candidate prediction function. In statistical testing it is a claim about a population that data might count against. The shared word causes needless confusion.
Does a bigger space always overfit?
No. A wide space raises the risk when data is limited and nothing constrains the search. With enough representative data, or with a penalty or training procedure that favors well-behaved members, a large space can predict very well. What a large space removes is the protection that comes automatically from having few options, so you have to check on held-out data instead of assuming.
Can the true function lie outside H?
It usually does, and that is acceptable. Theory calls the case where some member of H is exactly right realizable and the general case agnostic. In practice you want a member that is close enough for your purpose and findable with the data you have.