MoonSay /Tutorials/Machine Learning Interview #5
Contents
  1. 01Introduction
  2. 02Maximum likelihood
  3. 03Where maximum likelihood fails
  4. 04Bayes’ theorem and the MAP estimate
  5. 05The seesaw
  6. 06A prior is a regularizer
  7. 07Side by side
  8. 08Interview questions and model answers
  9. 09Summary
  10. References

05The seesaw: prior versus data

5.1The MAP estimate of a mean

For averages, MAP has a simple physical picture. Let the observations be Gaussian with known noise, x_i\sim\mathcal N(\theta,\sigma^2), and put a Gaussian prior on the mean, \theta\sim\mathcal N(\mu_0,\tau^2). By (8), MAP minimizes the negative log-posterior

\frac{1}{2\sigma^2}\sum_{i=1}^n(x_i-\theta)^2+\frac{1}{2\tau^2}(\theta-\mu_0)^2+\text{const}.

Its derivative, -\frac{1}{\sigma^2}\sum_i(x_i-\theta)+\frac{1}{\tau^2}(\theta-\mu_0), is zero when \theta\big(\frac{n}{\sigma^2}+\frac{1}{\tau^2}\big)=\frac{n\bar x}{\sigma^2}+\frac{\mu_0}{\tau^2}. Multiplying by \sigma^2,

\hat\theta_{\mathrm{MAP}}=\frac{m\,\mu_0+n\,\bar x}{m+n},\qquad m=\frac{\sigma^2}{\tau^2}. \tag{12}

This is a weighted average of the prior mean \mu_0 and the data mean \bar x (the maximum likelihood estimate). It is exactly the balance point of a seesaw that carries a weight m at position \mu_0 and a weight n at position \bar x. The prior is worth m imaginary observations: a confident prior (small \tau) is a heavy weight. Here the posterior is Gaussian, so its mode and its mean coincide, and its variance is \sigma^2/(m+n), which shrinks as data arrive (Bishop, 2006, §2.3.6).

5.2The two restaurants

Model a restaurant’s ratings this way, with a prior mean of \mu_0=4.0 stars (a typical restaurant) worth m=10 imaginary reviews. Restaurant A has n five-star reviews, so \bar x=5.0, and Table 1 shows its MAP rating.

five-star reviews n01101001{,}000
MAP rating (40+5n)/(10+n)4.004.094.504.914.99
Table 1. The MAP rating (12) of restaurant A after n five-star reviews, for a prior mean of 4.0 stars worth m=10 imaginary reviews.

With one review, A’s MAP rating is 4.09. Restaurant B, with 2{,}000 reviews averaging 4.7, gets (40+9400)/2010=4.70, almost exactly its own average. So MAP ranks B above A, as our instinct did, while maximum likelihood (5.0 against 4.7) ranks A first. Figure 4 shows how A’s estimate climbs from the prior toward the data as reviews accumulate, faster for a weak prior and slower for a strong one.

This is not only a textbook device. For many years the Internet Movie Database ranked its Top 250 films with the “weighted rating” \frac{v}{v+m}R+\frac{m}{v+m}C, where R is a film’s average rating, v its number of votes, C the mean vote across all films and m the minimum number of votes required to be listed; in December 2010 the page gave m=3000 and C=6.9 (IMDb, 2010). That is (12) with n=v, \bar x=R and \mu_0=C.

The MAP estimate (12) of restaurant A’s rating as its five-star reviews accumulate, for a prior mean of 4.0 worth m=2, 10 or 50 imaginary reviews. Ratings are illustrative; values computed for this tutorial, with the same numbers as the companion video.
Figure 4. The MAP estimate (12) of restaurant A’s rating as its five-star reviews accumulate, for a prior mean of 4.0 worth m=2, 10 or 50 imaginary reviews. Ratings are illustrative; values computed for this tutorial, with the same numbers as the companion video.
Try itBalance the seesaw

The MAP estimate of a mean is the balance point of a seesaw, \hat\theta=(m\mu_0+n\bar x)/(m+n), equation (12). The prior is a weight of m imaginary reviews at \mu_0; restaurant A's n real reviews are a weight at their average \bar x. Restaurant B (2,000 reviews averaging 4.7) is rated with the same prior.

5.3When the data win

Equation (12) shows the two classic limits at a glance. As n\to\infty with m fixed, the weight on the data, n/(m+n), tends to 1 and MAP tends to maximum likelihood. With a flat prior, \tau\to\infty, so m\to0 and MAP equals maximum likelihood for any n. The prior matters most when the data are scarce, exactly where maximum likelihood fails.

Pause and think. With the prior of the table, how many five-star reviews does restaurant A need before its MAP rating passes restaurant B’s 4.70?

Show the answer

Solve (40+5n)/(10+n)>4.70: 40+5n>47+4.7n, so 0.3n>7 and n>23.3. Twenty-four reviews.