Instead of a family of functions and a hand-picked loss, we specify a family of conditional probability distributions \(P(y|x, \theta)\) and maximize the likelihood.
The likelihood of the parameters given the training data is
Both have their maximum at the same \(\theta\), because \(\log\) is monotonic. We work with the log for two reasons. Products of small numbers underflow, and sums are easier to differentiate.
Linear regression from this point of view
Take a normal distribution whose mean is a linear function of \(x\) and whose variance is constant,
Taking the log and dropping the terms that do not depend on \(\beta\), maximizing \(\ell\) is the same as minimizing \(\sum_i (y_i - \beta_0 - \beta_1 x_i)^2\).
So the maximum likelihood solution of this model is the least squares solution.
The same twenty points as on the previous page, and three parameters now, because the normal distribution has a width as well as a mean. On the left the mean of the model with bands at one and two standard deviations; on the right the log-likelihood over the two parameters of the mean, light where it is high, with the current position marked. Changing σ alone changes the log-likelihood without moving the line, and it does not move the contours either: σ sets how tall the ridge is, not where it lies. That is the previous page’s loss surface seen from the other side, and its ridge sits on the same ellipses.
Choosing a normal distribution with constant variance is the same as choosing the squared error.
The maximum likelihood estimate of the variance is
We optimize \(\log\sigma\) instead of \(\sigma\), so that \(\sigma\) stays positive.
maximum likelihood: b0 = 1.3779, b1 = 0.7625, sigma = 0.6765
least squares: b0 = 1.3779, b1 = 0.7625
sigma by hand: 0.6765
The two agree to four digits. They are the same estimator.
Why this is useful
Once we think in distributions, the loss follows from the response.
response
distribution
loss
continuous
normal
squared error
two classes
Bernoulli
cross-entropy
\(C\) classes
categorical
cross-entropy
counts
Poisson
Poisson deviance
We do not have to invent a loss. We choose a distribution that fits the response, and the loss comes out of the likelihood. This is the subject of week 3.