Contents
06A prior is a regularizer: ridge, lasso and smoothing
6.1From priors to penalties
The connection interviewers love: regularization is a prior, written as a penalty. Take linear regression with Gaussian noise, y=Xw+\varepsilon with \varepsilon\sim\mathcal N(0,\sigma^2I), so that by (4) maximum likelihood is least squares. Now put a prior on the weights.
Gaussian prior. If the weights are independent \mathcal N(0,\tau^2), then -\log p(w)=\|w\|_2^2/(2\tau^2)+\text{const}, and by (8)
Multiplying by 2\sigma^2 does not move the minimum, so
which is ridge regression (Hoerl and Kennard, 1970). A stronger belief that the weights are small (smaller \tau) means a bigger \lambda, and noisier data (bigger \sigma) also mean a bigger \lambda: trust the prior more when the data say less (Bishop, 2006, §1.2.5, §3.3).
Laplace prior. If the weights are independent with density p(w_j)=\frac{1}{2b}e^{-|w_j|/b}, then -\log p(w)=\|w\|_1/b+\text{const} and the same steps give
the lasso (Tibshirani, 1996). Figure 5 shows the two priors and their negative logarithms. The Gaussian prior is a smooth hill whose penalty is a bowl; the Laplace prior has a sharp peak at zero whose penalty is a V, and that corner is what sets some weights exactly to zero (Hastie et al., 2009, §3.4).
6.2On real data
Figure 6 uses the classic diabetes data of Efron et al. (2004): 442 patients, ten baseline measurements (age, sex, body mass index, blood pressure and six blood serum measurements s_1,\dots,s_6) and a measure of disease progression one year later, all standardized. Least squares (maximum likelihood) gives large weights of opposite sign to the strongly correlated cholesterol measurements s_1 and s_2 (-0.489 and 0.294), which largely cancel. Ridge with \lambda=100 (a Gaussian prior) shrinks all the weights; their length \|w\|_2 falls from 0.851 to 0.451. The lasso (a Laplace prior; scikit-learn’s alpha =0.06, which is \lambda=2n\alpha=53.04 in (14)) sets five weights exactly to zero (age, s_1, s_2, s_4, s_6) and keeps sex, body mass index, blood pressure, s_3 and s_5 (Pedregosa et al., 2011).
6.3Add-one smoothing is a prior
Back to the spam filter of Section 3. Each word’s probability of appearing in a spam e-mail is a coin: it appears in n_w of the N spam e-mails. Maximum likelihood gives n_w/N, and zero for an unseen word. Put the prior \mathrm{Beta}(2,2) on each word’s probability, one imaginary spam e-mail with the word and one without, and (10) gives
add-one, or Laplace, smoothing. For our words: “free” 31/62=0.500, “money” 13/62=0.210, “meeting” 1/62=0.016, and the e-mail now gets 0.500\times0.210\times0.016\approx0.0017 instead of 0. It is the same formula as the coin in Example 4. For word counts in a multinomial model the smoothed estimate is (T_{w}+1)/(\sum_{w'}T_{w'}+V) with V the vocabulary size, the MAP estimate under a Dirichlet prior (Manning et al., 2008, §13.2).
Pause and think. Doubling the noise standard deviation \sigma while keeping the prior fixed: what happens to the ridge parameter \lambda, and why does that make sense?
Show the answer
\lambda=\sigma^2/\tau^2 grows four times. Noisier data are weaker evidence, so the estimate should lean more on the prior.