January 15, 2026
We’re going to start with a familiar class of learning methods and use these as the building blocks for new stuff
As with most applied statistics, we’re going to start with the workhorse - linear regression
The linear regression model says:
\[ \hat{y} = g(\mathbf x^T \hat{\boldsymbol \beta}) \]
The predictive goal:
Find values of \(\hat{\boldsymbol \beta} \in \mathbb R^P\) that do a good job of predicting \(y\) for any viable feature combination \(\mathbf x\) that could occur
Linear regression methods represent one specific class of potential predictive functions that could be used
\[ \hat{y} = g(\mathbf x^T \boldsymbol \beta^*) \]
Choose \(\boldsymbol \beta^*\) that makes \(\hat{y} \approx y\)
How do we do that?
Without specification of a loss function, we have no meaningful way to judge how good our predictive model is.
Loss function
A function \(L(\cdot)\) that takes in the truth and a prediction
Returns 0 if truth = prediction
Returns larger positive values as predictions move further from the truth.
Our goal, then, is to find the coefficients that minimize the loss!
Empirical (average) loss
For a training set, \(\{ \mathbf X, \mathbf y\}_{i = 1}^N\), the empirical loss can be computed as:
\[ \frac{1}{N} \sum \limits_{i = 1}^N L(y_i , \hat{y}_i) \]
For linear regression:
\[ \hat{\boldsymbol \beta} = \underset{\boldsymbol \beta^*}{\min} \frac{1}{N} \sum \limits_{i = 1}^N L(y_i , \mathbf x_i^T \boldsymbol \beta^*) \]
Conceptual question: Is this the actual loss that we want to minimize when building a good predictive model?
The predictive goal revolves around minimizing the true risk or generalization error
Assume each instance of \(\{ \mathbf x, y\}\) is drawn from the Nature box:
\[ P(X,Y) = \mathcal T \]
The true risk that we want to minimize is:
\[ E_{\mathcal T}[L(y , \mathbf x^T \beta^*)] \]
Can we directly minimize this?
We don’t know the Nature box!
\[ \text{True Risk} = \text{Empirical Risk} + \mathcal{O}\left(\frac{C}{N}\right) \]
For a model with \(N\) training examples and a fixed complexity, the minimum generalization error can be found where the empirical risk is smallest
There exists a balance between empirical risk and complexity (e.g. the Bias/Variance tradeoff)
Larger \(N\) means that the gap between the empirical risk and the true risk is small
\[ \hat{\boldsymbol \beta} = \underset{\boldsymbol \beta^*}{\min} \frac{1}{N} \sum \limits_{i = 1}^N L(y_i , \mathbf x_i^T \boldsymbol \beta^*) \]
Is this the actual loss that we want to minimize when building a good predictive model?
Kinda!
Given a class of models, find the one that minimizes the empirical risk
Use methods to approximate the true risk conditional on the empirical risk
What approaches exist for approximating the true risk?
But, the game is still to minimize the empirical loss based on the training data.
So, the last thing we need to do is specify the loss function
The common choices we make depend on the type of outcome we are trying to predict
If \(y\) is a continuous outcome, the most common choice is mean squared error:
\[ \hat{\boldsymbol \beta} = \underset{\boldsymbol \beta^*}{\min} \frac{1}{N} \sum \limits_{i = 1}^N (y_i - \theta_i^*)^2 \]
\[ \theta_i^* = \mathbf x_i^T \boldsymbol \beta^* \]
This admits the standard ordinary least squares solution:
\[ \hat{\boldsymbol \beta} = (\mathbf X^T \mathbf X)^{-1} \mathbf X^T \mathbf y \]
This isn’t the only choice - we could fit to minimize mean absolute error:
\[ \hat{\boldsymbol \beta} = \underset{\boldsymbol \beta^*}{\min} \frac{1}{N} \sum \limits_{i = 1}^N |y_i - \theta_i^*| \]
\[ \theta_i^* = \mathbf x_i^T \boldsymbol \beta^* \]
Question: What does MAE do that MSE does not? When is this a good loss function to use?
When our outcome is binary (0/1), the most common choice is to use binary cross entropy after transforming the linear predictor via the sigmoid function (e.g. logistic regression):
\[ \hat{\boldsymbol \beta} = \underset{\boldsymbol \beta^*}{\min} -\frac{1}{N} \sum \limits_{i = 1}^N \left[ y_i \log \theta_i + (1 - y_i)\log(1 - \theta_i) \right] \]
\[ P(y_i = 1 | \boldsymbol \beta^*, \mathbf x) = \theta_i^* = \sigma(\mathbf x_i^T \boldsymbol \beta^*) \]
When our outcome is categorical ( \(y_i \in (1,2,...,K)\) ), the most common choice is cross entropy after transforming the predictor via the softmax function (e.g. multinomial logistic regression):
\[ \hat{\mathbf W} = \min_{\mathbf{W}} \mathcal{L}(\mathbf{W}) = - \frac{1}{N} \sum_{i=1}^N \sum_{k=1}^K \mathbb{1}(y_i = k) \log \theta_{ik} \]
\[ P(y_i = k | \mathbf W^*, \mathbf x) = \theta_{ik} = \frac{\exp[z_{ik}]}{\sum \limits_{h = 1}^K \exp[z_{ih}]} \]
\[ z_{ik} = \mathbf x_i^T \mathbf w_k \]
where \(\mathbf W\) is a \(P \times K\) matrix where the \(k^{th}\) column contains coefficients for the \(k^{th}\) class.
More broadly, we can define these loss functions as the minimization targets for any function \(f_{\theta}(\mathbf x)\) that maps the inputs to outputs:
| MSE | \(\frac{1}{N} \sum \limits_{i = 1}^N (y_i - f_{\theta}(\mathbf x_i))^2\) |
| MAE | \(\frac{1}{N} \sum \limits_{i = 1}^N |y_i - f_{\theta}(\mathbf x_i)|\) |
| BCE | \(-\frac{1}{N} \sum \limits_{i = 1}^N y_i \log f_{\theta}(\mathbf x_i) + (1- y_i) \log (1 - f_{\theta}(\mathbf x_i))\) |
| CE | \(\frac{1}{N} \sum \limits_{i = 1}^N \sum \limits_{k = 1}^K \mathbb 1(y_i = k) \log f_{\theta}(\mathbf x_i)\) |
These loss functions are the basis of most discriminative machine learning.
From last class, our goal is to learn something about the Nature box
Where do distributions come in?
It turns out that you’ve been doing it the whole time without even realizing it
Key point:
Your choice of loss function implicitly chooses a conditional distribution for the outcome given the inputs
That distribution has:
Width
Tails
Support (viable set of values)
that dictate how your model handles mistakes
Our \(N\) training instances form an empirical distribution from which we are trying to learn a reasonable functional approximation
The empirical conditional distributions that we learn say that:
\[ P(Y = y_i | X = x_i) = 1 \]
Taken at face value, the data we observe is indicative of what we’ll always see!
\[ y = f_{\theta}(\mathbf x) + \epsilon \]
where \(\epsilon\) is a draw from the noise distribution
Therefore
\[ y \neq f_{\theta}(\mathbf x) \]
and we assume that noise follows some structure
\(E[\text{Noise}] = 0\)
\(V[\text{Noise}] = \sigma^2\)
Right?
It turns out that your choice of loss function also tells us what the distribution of that noise is!
To show this, we’re going to start with an assumption and back our way into the identity
Let’s assume that:
\[ f(\epsilon) \sim \mathcal N(\epsilon | 0, \sigma^2) \]
Since adding a constant to a distribution changes only the expectation:
\[ y = f_{\theta}(\mathbf x) + \epsilon \]
implies
\[ y \sim \mathcal N(y | f(\mathbf x) , \sigma^2) \]
The goal: find the normal distributions that are most likely to have generated the observed outcomes!
Goal: Find a form of the conditional distribution that is most likely to have generated the data
Key Assumption: Each \(y | x\) is an independent and identically distributed draw.
Most likely to generate = max probability/density
\[ P(y | \mathbf X) = \prod \limits_{i = 1}^N P(y_i | \mathbf x) \]
Given a set of \(y\) values and corresponding \(\mathbf x\) values and a choice of function, our goal is to find the conditional distribution type such that:
\[ \underset{\theta}{\max} \prod \limits_{i = 1}^N P(y_i | \mathbf x_i , \boldsymbol \theta) \]
where \(\boldsymbol \theta\) is the set of unknowns that we’re trying to learn
Note: Products of numbers less than 1 get smaller and smaller - don’t do that.
Instead, recognize that logs are 1-to-1 functions that will preserve the max
\[ \underset{\theta}{\max} \sum \limits_{i = 1}^N \log P(y_i | \mathbf x_i , \boldsymbol \theta) \]
This approach to estimating the values of the unknowns is called maximum likelihood estimation
But how does this link to loss?
Back to our normal assumption:
\[ \underset{\{\theta, \sigma^2\}}{\max} \sum \limits_{i = 1}^N \log \mathcal N(y_i | f_{\theta}(\mathbf x_i) , \sigma^2) \]
The normal distribution:
\[ \frac{1}{2 \pi \sigma^2} \exp \left[- \frac{1}{2 \sigma^2} (y_i - f_{\theta}(\mathbf x_i))^2 \right] \]
Taking the log:
\[ - \log 2 \pi \sigma^2 - \frac{1}{2 \sigma^2} (y_i - f_{\theta}(\mathbf x_i))^2 \]
Now the log of the joint:
\[ \sum \limits_{i = 1}^N - \log 2 \pi \sigma^2 - \frac{1}{2 \sigma^2} (y_i - f_{\theta}(\mathbf x_i))^2 \]
Making some simplifications:
\[ - \log 2 \pi \sigma^2 - \frac{1}{2 \sigma^2 N} \sum \limits_{i = 1}^N (y_i - f_{\theta}(\mathbf x_i))^2 \]
Wait - the only part where \(\theta\) comes in is in the summation
\[ \underset{\{\theta\}}{\max} - Z \frac{1}{N} \sum \limits_{i = 1}^N(y_i - f_{\theta}(\mathbf x_i))^2 \]
\[ \underset{\{\theta\}}{\min} \frac{1}{N} \sum \limits_{i = 1}^N(y_i - f_{\theta}(\mathbf x_i))^2 \]
By choosing to minimize the MSE, we’re implicitly choosing values for unknowns that will maximize the probability that they were generated from a normal distribution
And we’re making assumptions about what the noise looks like (and doesn’t look like)
Linear regression via MLE under MSE Loss
\[ \hat{y} = \mathbf x_i^T \boldsymbol \beta \]
\[ y \sim \mathcal N(y | \mathbf x_i^T \boldsymbol \beta , \sigma^2) \]
We’ll skip the derivation here because it’s going to look familiar:
\[ \hat{\boldsymbol \beta} = (\mathbf X^T \mathbf X)^{-1} \mathbf X^T \mathbf y \]
\[ \hat{\sigma^2} = \frac{1}{N} \sum \limits_{i = 1}^N (y_i - \mathbf x_i^T \hat{\boldsymbol \beta})^2 \]
Log-likelihoods reward overlapping the bumps with the empirical spikes
Log-likelihoods punish us for leaving spikes in low-density regions
e.g. Log-likelihoods punish us when our “loss” is big!
It turns out that likelihood is the only strictly proper, local scoring rule for probability distributions
Nerd speak for if the truth is optimal, it is maximized
See Savage (1971) and Dawid (1986)
This distribution to loss relationship runs even deeper…
The Laplace Distribution:
\[ p(y | f(\mathbf{x}), b) = \frac{1}{2b} \exp \left( -\frac{|y - f(\mathbf{x})|}{b} \right) \]
Log-likelihood:
\[ \sum_{i=1}^N \log p(y_i | f(\mathbf{x}_i), b) = \sum \limits_{i=1}^N \left[ -\log(2b) - \frac{|y_i - f(\mathbf{x}_i)|}{b} \right] \]
See a loss function?
For classification, assume \(y | x\) follows a Bernoulli distribution and \(f(\mathbf x)\) is contrained to be between 0 and 1:
\[ P(y_i | \mathbf{x}_i) = f(\mathbf{x}_i)^{y_i} (1 - f(\mathbf{x}_i))^{1 - y_i} \]
Log-likelihood:
\[ \ell(\theta) = \sum_{i=1}^N \left[ y_i \log f_{\theta}(\mathbf{x}_i) + (1 - y_i) \log (1 - f_{\theta}(\mathbf{x}_i)) \right] \]
Negative log-likelihood:
\[ -\ell(\theta) = -\sum_{i=1}^N \left[ y_i \log f_{\theta}(\mathbf{x}_i) + (1 - y_i) \log (1 - f_{\theta}(\mathbf{x}_i)) \right] \]
Familiar?
A note about the Bernoulli/Normal:
MLE estimation under constant variance assumption (or constant functional assumption) makes the variance of the resulting conditional distributions a function of the mean function
Normal: \[ V[X] = \sigma^2 \]
Bernoulli:
\[ V[X] = f(\mathbf x_i) \left[1 - f(\mathbf x_i) \right] \]
This will matter soon!
We’ve established that:
But there’s a deeper question we haven’t answered:
Why is maximum likelihood the “right” thing to do?
We have two distributions:
Empirical Distribution \(\hat{p}(y|x)\)
Model Distribution \(p_{\theta}(y|x)\)
Core Question: How do we measure how “close” these two distributions are?
Goal: Find a principled way to measure distributional “closeness” that:
We’ve been maximizing: \[ \max_{\theta} \sum_{i=1}^N \log p_{\theta}(y_i | x_i) \]
But what are we really doing?
Next: Let’s formalize this and see why MLE emerges naturally from minimizing distributional distance.
The KL divergence from distribution \(Q\) to distribution \(P\) is:
\[ D_{KL}(P \| Q) = \sum_{y} P(y) \log \frac{P(y)}{Q(y)} \]
Or for continuous distributions:
\[ D_{KL}(P \| Q) = \int P(y) \log \frac{P(y)}{Q(y)} \, dy \]
Properties:
\[ D_{KL}(P \| Q) = \mathbb{E}_{y \sim P} \left[ \log \frac{P(y)}{Q(y)} \right] \]
Interpretation:
Expected difference in log-probability between \(P\) and \(Q\)
When \(P(y)\) is high but \(Q(y)\) is low → large penalty
Measures the “information lost” when approximating \(P\) with \(Q\)
Asymmetry matters! We typically minimize \(D_{KL}(\hat{p} \| p_{\theta})\) where \(\hat{p}\) is the true/empirical distribution and \(p_{\theta}\) is our model.
Key Insight: When means differ, P assigns high probability where Q assigns low probability → large penalty!
Key Insight: P (narrower) is more concentrated. Q (wider) under-represents the peak → penalty!
Key Insight: When P ≈ Q, divergence is near zero. Distributions are nearly indistinguishable!
In supervised learning, our empirical distribution is:
\[ \hat{p}(y | x) = \frac{1}{n} \sum_{i=1}^n \delta(\mathbf x - x_i, y - y_i) \]
(A sum of delta spikes at the observed data points)
We want to find \(\theta\) that minimizes:
\[ D_{KL}(\hat{p} \| p_{\theta}) = \sum_{x,y} \hat{p}(y|x) \log \frac{\hat{p}(y|x)}{p_{\theta}(y|x)} \]
\[ D_{KL}(\hat{p} \| p_{\theta}) = \sum_{x,y} \hat{p}(y|x) \log \hat{p}(y|x) - \sum_{x,y} \hat{p}(y|x) \log p_{\theta}(y|x) \]
\[ \min_{\theta} D_{KL}(\hat{p} \| p_{\theta}) \equiv \max_{\theta} \sum_{x,y} \hat{p}(y|x) \log p_{\theta}(y|x) \]
Since \(\hat{p}(y|x) = \frac{1}{n} \sum_{i=1}^n \delta(x - x_i, y - y_i)\):
\[ \max_{\theta} \sum_{x,y} \hat{p}(y|x) \log p_{\theta}(y|x) = \max_{\theta} \frac{1}{n} \sum_{i=1}^n \log p_{\theta}(y_i | x_i) \]
Minimizing KL divergence is equivalent to Maximum Likelihood Estimation!
Bottom line: Maximum Likelihood Estimation is the principled way to fit probabilistic models by minimizing distributional distance.
Three key reasons we need to understand KL divergence:
1. Variational Inference & Approximate Posteriors
2. Generative Models & Distribution Matching
3. Model Comparison & Selection
Coming soon: Bayesian methods, deep generative models, and uncertainty quantification!
Maximizing the log-likelihood introduces a pressure on the model.
Since all we see is the empirical distribution, our goal is to place as much mass as possible at the observed locations
Respecting the assumed conditional distribution structure and the constraint that the mean of the distribution follows the mean function
For regression - \(f_{\theta}(\mathbf x) = \mathbf x^T \boldsymbol \beta\)
One way to increase the flexibility of the linear model is to add polynomial terms.
Question: What’s going to happen to the MLE estimate of \(\sigma^2\) when we add more terms?
\[ \hat{\sigma^2} = \frac{1}{N} \sum \limits_{i = 1}^N (y_i - \mathbf x_i^T \hat{\boldsymbol \beta})^2 \]
Adding more terms always decreases the average residual.
There’s a more unifying way to think about this concept without relying on polynomials alone
As the flexibility of our model increases, the pressure that comes from minimizing the KL divergence with the empirical distribution dominates
Simple models combat the KL divergence pressure by limiting how complex the mean function can be
More complex models allow more complex mean functions meaning that there is more opportunity to place all of the mass of the conditional distributions exactly on the observed data points
Does this sound like a familiar concept?
Finally, a definition of overfitting that makes sense:
Overfitting occurs due to probabilistic mass collapse around the empirical distribution
One thing that is always going to reduce the mass collapse behavior is increasing the size of the training data
Check-in question:
Imagine that our feature space is very high dimensional. What’s going to happen to the number of training examples needed to fill the space to make the empirical distribution \(\approx\) the true distribution?
It goes up!
Curse of dimensionality
I need more examples to represent the space in the box…
For images, there isn’t a \(N\) large enough!
Since there are some cases where getting an appropriate \(N\) is not possible, there are other strategies.
One thing that we can do is add a competing penalty to our loss function that will combat the overfitting problem.
Natural for the MSE - add a Ridge penalty:
\[ \hat{\boldsymbol \beta} = \underset{\boldsymbol \beta}{\min} \frac{1}{N} \|\mathbf y - \mathbf X \boldsymbol \beta \|^2 + \lambda \|\boldsymbol \beta\|^2 \]
With the MSE + Ridge penalty, there is a unique minimizer:
\[ \hat{\boldsymbol \beta} = (\mathbf X^T \mathbf X + \lambda \mathcal I_P)^{-1} \mathbf X^T \mathbf y \]
It turns out that the implied distribution when adding a L2 penalty is still normal! (more next time)
\[ P(y | \mathbf x, \boldsymbol \beta, \lambda) = \mathcal N(y | \mathbf x^T \hat{\boldsymbol \beta}, \hat{\sigma^2}) \]
where \(\hat{\sigma^2}\) is still the MSE.
Regularization works in the probabilistic sense by forcing mass in the conditional distribution away from the observed points.
Question: Which function do you think generated the data?
Why?
Turns out any of them could have generated that data
This is a fundamental problem with attempting to solve inverse problems
Why assume simplicity?
Next time:
Regularization is an assumption about the way the world really works.
Balances prior belief about a “good” solution with what the data says
Fits naturally in our distributional world