Loss Functions & Risk Minimization
The mathematical framework connecting loss functions, empirical risk, and statistical risk — deriving squared loss from Gaussian noise, cross-entropy from MLE, and establishing PAC-style generalization bounds.
Prerequisites
Table of Contents
- Learning Objectives
- Prerequisites
- Notation
- Core Intuition
- The Decision-Theoretic Framework
- Common Loss Functions
- From Loss to Risk
- Empirical Risk Minimization
- Bayes Optimal Predictor
- Surrogate Loss Functions
- Generalization and Excess Risk
- Common Pitfalls
- Research Perspective
- Summary
- Exercises
Learning Objectives
- Formalize the supervised learning problem in terms of loss, risk, and hypothesis classes.
- Derive squared error loss from the Gaussian likelihood assumption.
- Derive cross-entropy loss from maximum likelihood for Bernoulli/categorical models.
- Distinguish between statistical (population) risk and empirical risk.
- State and interpret the Bayes optimal predictor for squared and 0-1 loss.
- Explain why surrogate losses are necessary for classification.
- Understand the decomposition of excess risk into estimation and approximation error.
Prerequisites
Notation
- — input space, — output space
- — joint distribution over data
- — predictor (hypothesis)
- — hypothesis class
- — loss function
- — statistical (population) risk
- — empirical risk
- — Bayes optimal predictor
- — ERM solution
Core Intuition
Machine learning is fundamentally an optimization problem: we seek a function that predicts well on unseen data. But "predicts well" must be defined precisely. The loss function quantifies the penalty for predicting when the truth is . The risk is the expected loss over the true data distribution. Since we cannot compute the risk (we don't know ), we minimize the empirical risk over training data and hope it generalizes.
Loss Functions Compared
The Decision-Theoretic Framework
Definition (Statistical Learning Problem). Given:
- A joint distribution over (unknown)
- A loss function
- A hypothesis class
- Training data
Find that minimizes the population risk:
The unconstrained minimizer (over all measurable functions) is the Bayes predictor , and is the Bayes risk — the irreducible error.
Common Loss Functions
Squared Error (Regression)
Probabilistic derivation. Assume with . The negative log-likelihood of one observation is:
Minimizing negative log-likelihood minimizing squared loss.
Cross-Entropy (Classification)
For binary classification with and :
Derivation. If , the negative log-likelihood is exactly the cross-entropy.
For -class classification with one-hot and predicted probabilities :
0-1 Loss (Classification)
This is the natural measure of classification error, but is non-convex and non-differentiable.
Absolute Loss
More robust to outliers than squared loss. The optimal predictor under absolute loss is the conditional median .
From Loss to Risk
Definition (Population Risk).
Definition (Empirical Risk). Given iid samples:
By the law of large numbers, for fixed . The challenge is that we are choosing based on the data — so we need uniform convergence over .
Empirical Risk Minimization
ERM Principle. Choose the predictor that minimizes empirical risk:
Theorem (Consistency of ERM). If has finite VC-dimension , then for any , with probability at least :
where is the best-in-class predictor.
Bayes Optimal Predictor
Theorem. For squared loss, the Bayes optimal predictor is the conditional expectation:
Proof. Expand:
The cross term vanishes by the tower property. The second term is irreducible noise. The first is minimized when .
Theorem. For 0-1 loss, the Bayes optimal predictor is:
Surrogate Loss Functions
The 0-1 loss is computationally intractable (NP-hard to minimize over linear classifiers). We use surrogate losses that upper-bound 0-1 loss and are convex:
- Hinge loss (SVM): where
- Logistic loss:
- Exponential loss (AdaBoost):
All satisfy for all , providing classification-calibrated surrogates.
Theorem (Zhang, 2004; Bartlett et al., 2006). A convex surrogate is classification-calibrated if and only if it is differentiable at 0 and . In this case, minimizing the surrogate risk is consistent for 0-1 loss.
Generalization and Excess Risk
The excess risk decomposes as:
- Estimation error: decreases with (more data), increases with complexity of .
- Approximation error: decreases with richer , zero if .
This is the formal counterpart of the bias-variance tradeoff.
Common Pitfalls
Pitfall 1. Choosing loss based on convenience rather than the actual problem. Squared loss is sensitive to outliers; in heavy-tailed settings, Huber loss or absolute loss is more appropriate.
Pitfall 2. Confusing empirical risk with population risk. Low training loss does not guarantee low test loss — the gap depends on the complexity of relative to .
Pitfall 3. Assuming cross-entropy is always correct. Cross-entropy assumes the model outputs calibrated probabilities; if it doesn't (e.g., softmax temperatures), the loss may be misleading.
Research Perspective
The risk-minimization framework dates to Vapnik's statistical learning theory (1960s–90s). Modern deep learning challenges classical bounds (VC-dimension of neural networks is enormous, yet they generalize), leading to new frameworks: PAC-Bayes bounds, compression-based bounds, and the implicit regularization perspective from gradient flow analysis.
Summary
- A loss function quantifies prediction errors; the choice is motivated by probabilistic assumptions.
- Population risk is the expected loss; empirical risk is the training average.
- ERM finds the hypothesis minimizing empirical risk; generalization depends on the complexity of .
- The Bayes predictor achieves irreducible error; excess risk = estimation + approximation error.
- Surrogate losses make 0-1 classification computationally tractable while preserving consistency.
Exercises
Exercise 1. Derive that the Bayes optimal predictor under absolute loss is the conditional median.
Exercise 2. Show that for squared loss, .
Exercise 3. Prove that the hinge loss upper bounds the 0-1 loss: .
Exercise 4. For exponential loss , derive the population minimizer and show it equals .
Exercise 5. Show that ERM with squared loss and the class of linear functions reduces to ordinary least squares.