Generalization
Overfitting occurs when a hypothesis fits the training data too well but performs poorly on the true distribution.
A Perfect Training Score
A hypothesis that makes no mistakes on its training set can look successful. But the training set contains only the instances used to choose the hypothesis. Generalization asks a broader question: how does the hypothesis perform on the true distribution that produces instances? Overfitting occurs when a hypothesis fits the training data too well but performs poorly on that true distribution.
What do you think happens?
If a hypothesis has zero error on its training set, must its true error also be zero?
Reveal answer
Answer: No, because the training set may not represent the full true distribution.
Zero empirical error describes performance on the observed sample. It does not by itself establish performance on new instances from the true distribution.
The Papaya Illustration
The source illustrates the distinction with a papaya prediction problem. The input has two features: softness and color. Instances are distributed uniformly through a gray square. The true labeling rule assigns label 1 to points inside an inner blue square and label 0 to points outside it. The gray square has area 2, while the blue square has area 1.
Zero Training Error, Poor True Performance
Interpret the source's papaya example, in which a predictor has zero training error but true error equal to one half.
Separate the two evaluations: The training evaluation checks the predictor only on the observed papaya examples. The true-distribution evaluation checks its behavior on instances produced by the distribution over the gray square.
Notice the perfect sample fit: The predictor makes no mistakes on the training set, so its empirical error is zero.
Check the broader result: The source states that this same predictor has true error equal to one half. Therefore, its perfect training result does not carry over to the true distribution.
Identify the lesson: The relevant distinction is not simply between a small number and a large number. It is the distinction between performance on observed data and performance on the distribution that produces new data.
A zero training error can coexist with true error equal to one half.
Why ERM Can Overfit
Empirical risk minimization, or ERM, relies on performance on the training set. It therefore prefers a hypothesis with low training error. That preference can select an overfitting hypothesis when a hypothesis fits the observed sample exceptionally well but performs poorly on the true distribution. ERM is using the evidence supplied by the sample; the problem is that sample performance does not guarantee distribution performance.
| Question | Training performance | True-distribution performance |
|---|---|---|
| What is evaluated? | Behavior on the observed training instances | Behavior on instances produced by the true distribution |
| What can zero error tell us? | The hypothesis fits the observed sample | It does not guarantee low true error |
| What is the overfitting warning? | The result is unusually favorable | The hypothesis may perform poorly beyond the sample |
The 1-NN Hypothesis
The 1-nearest-neighbor rule classifies a new point using the closest example in a training sample. In the binary-classification setting described by the source, labels belong to the set containing 0 and 1, the loss is the 0-1 loss, the domain is the unit cube in d dimensions, and closeness is measured with Euclidean distance. Because its prediction depends on the particular training sample, the rule is described as a sample-dependent hypothesis h_S.
The subscript S matters: changing the training sample can change which observed point is nearest and therefore can change the resulting hypothesis. This makes h_S different in kind from a rule defined directly from the underlying distribution.
Bayes as the Distribution Benchmark
The conditional probability function η(x) describes the conditional probability of a label given an input x. The Bayes rule h* is defined from η(x) and serves as the optimal benchmark.
This gives two different sources of a classification rule. The 1-NN hypothesis h_S uses the closest observed example in a particular sample. The Bayes optimal rule h* is defined from the conditional probability function associated with the underlying distribution. One is sample-dependent; the other is distribution-defined.
Smoothness Through Lipschitzness
The c-Lipschitz condition connects distance between inputs with change in their conditional label probabilities. Its role is to restrict how quickly η(x) can change: inputs that are close under Euclidean distance cannot have an unrestricted difference in their conditional probabilities. This smoothness assumption helps the analysis relate a new point to a nearby training example.
The condition is important for 1-NN analysis because 1-NN transfers the label information of a nearby observed example to a new input. A smooth conditional probability function provides a restriction on how different the label probabilities can be at those two nearby locations.
Assumptions Behind the Analysis
- Domain: inputs lie in X = [0, 1]^d.
- Labels: the classification problem is binary, with labels in the set containing 0 and 1.
- Loss: mistakes are measured with the 0-1 loss.
- Distance: Euclidean distance ρ is used to identify the nearest example.
- Sample dependence: the 1-NN hypothesis is written h_S because it depends on the training sample S.
- Conditional probability: η(x) supplies the distribution-based quantity from which the Bayes rule h* is defined.
- Smoothness: the c-Lipschitz condition restricts how quickly η(x) can change.
These assumptions work together rather than independently. The domain and distance describe where inputs are and what nearby means. The binary labels and 0-1 loss describe the prediction task and its mistakes. The sample defines the sample-dependent 1-NN rule. The conditional probability function and its smoothness condition provide the distributional structure used to compare that rule with the Bayes benchmark.
Common Reasoning Errors
Treating zero training error as proof of generalization.
The true distribution includes instances beyond the observed sample, and the source gives an example with zero training error but true error equal to one half.
Fix:
Evaluate training performance and true-distribution performance as separate questions.Assuming ERM directly optimizes true-distribution performance.
ERM relies on training-set performance, so it can select a hypothesis that overfits.
Fix:
Remember that ERM can prefer a sample-fitting hypothesis whose broader performance is poor.Describing 1-NN as a fixed rule independent of the data.
The 1-NN rule is sample-dependent and is denoted h_S.
Fix:
Track the training sample when describing a 1-NN hypothesis.Confusing the Bayes rule with the nearest-neighbor rule.
The Bayes rule is defined from η(x), while 1-NN uses the closest example in a training sample.
Fix:
Identify whether a prediction rule comes from the sample or from the underlying distribution.
Practice the Distinction
A classifier has zero empirical error on its training sample. Explain why this fact alone does not establish that the classifier generalizes. Then identify whether each description refers primarily to 1-NN or to the Bayes rule: a rule that uses the closest observed example, and a rule defined from η(x).
Hints
- Separate the observed sample from the true distribution.
- Look for whether the rule depends on a particular sample.
- The source identifies h* as the rule defined from η(x).
Classifying the Two Rules
Match each description with the appropriate rule.
Description one: A new point receives the label of the closest example in a training sample. This is the 1-nearest-neighbor rule, represented as the sample-dependent hypothesis h_S.
Description two: A rule is defined from the conditional probability function η(x) and serves as the optimal benchmark. This is the Bayes rule h*.
Generalization connection: The first rule depends on the observed sample, while the second is defined from the underlying distribution.
Closest observed example: 1-NN h_S. Rule defined from η(x): Bayes rule h*.
Key Takeaways
- Overfitting means fitting the training data too well while performing poorly on the true distribution.
- Zero empirical error does not guarantee low true error.
- ERM can select an overfitting hypothesis because it relies on training-set performance.
- A 1-NN hypothesis h_S depends on the training sample and predicts from the closest observed example.
- The Bayes rule h* is defined from η(x) and serves as the optimal distribution-based benchmark.
- The c-Lipschitz condition restricts how quickly η(x) can change as inputs vary, supporting the analysis of nearby examples.
Key Takeaways
- Generalization is about performance on the true distribution, not only on the observed training set.
- A hypothesis can have zero training error and still have poor true performance.
- ERM can choose an overfitting hypothesis because it evaluates training-set performance.
- 1-NN is sample-dependent, whereas the Bayes rule is defined from η(x).
- The domain, distance, label, loss, sample, and smoothness assumptions support the analysis of 1-NN error.