Contents
08Interview questions and model answers
Q1What is the difference between MLE and MAP?
Both estimate a model’s parameters from data. Maximum likelihood picks the \theta that makes the observed data most likely, \arg\max_\theta p(D\mid\theta). MAP picks the most probable \theta given the data and a prior, \arg\max_\theta p(D\mid\theta)\,p(\theta). In log form MAP is the maximum likelihood objective plus \log p(\theta). MLE trusts the data; MAP trusts the data plus a prior.
Q2Write down Bayes’ theorem and explain each term. Why can MAP ignore the denominator?
p(\theta\mid D)=p(D\mid\theta)\,p(\theta)/p(D): posterior equals likelihood times prior over evidence. The prior is the belief before the data, the likelihood measures how well \theta explains the data, the evidence p(D)=\int p(D\mid\theta)p(\theta)\,d\theta normalizes, and the posterior is the belief after the data. The evidence does not depend on \theta, so it does not change where the posterior peaks.
Q3Derive the MLE and the MAP estimate for a coin.
\ell(\theta)=h\log\theta+(n-h)\log(1-\theta); setting h/\theta-(n-h)/(1-\theta)=0 gives h/n. With a \mathrm{Beta}(\alpha,\beta) prior the posterior is \mathrm{Beta}(h+\alpha,n-h+\beta) and its mode is (h+\alpha-1)/(n+\alpha+\beta-2): the prior adds \alpha-1 imaginary heads and \beta-1 imaginary tails. Three heads in three flips: MLE 1, MAP with \mathrm{Beta}(2,2) 0.8.
Q4When do MLE and MAP give the same answer?
With a flat prior, because then \log p(\theta) is a constant; and asymptotically, as n\to\infty, because the log-likelihood grows with n while the log-prior stays fixed. For a Gaussian mean, MAP is (m\mu_0+n\bar x)/(m+n), which tends to \bar x.
Q5How are L2 and L1 regularization related to MAP?
With Gaussian noise, a Gaussian prior \mathcal N(0,\tau^2) on the weights makes MAP equal to ridge regression with \lambda=\sigma^2/\tau^2; a Laplace prior with scale b gives the lasso with \lambda=2\sigma^2/b. The penalty is the negative log-prior. The Laplace prior’s sharp peak at zero is why the lasso gives exact zeros.
Q6Which common loss functions are maximum likelihood?
Mean squared error is the negative log-likelihood of a Gaussian noise model (up to constants), so least squares is maximum likelihood. Binary cross-entropy is the negative log-likelihood of a Bernoulli label, and categorical cross-entropy of a categorical label. Maximizing likelihood also minimizes the KL divergence from the data distribution to the model.
Q7Is the maximum likelihood estimator unbiased?
Not always. The maximum likelihood variance of a Gaussian, \frac1n\sum_i(x_i-\bar x)^2, has expectation \frac{n-1}{n}\sigma^2; dividing by n-1 removes the bias. Maximum likelihood estimators are consistent under mild conditions, and the bias vanishes as n grows.
Q8What is add-one (Laplace) smoothing, and how does it relate to MAP?
Adding one to every count so that no event gets probability zero, for example (n_w+1)/(N+2) for a word that appears in n_w of N documents. It is the MAP estimate under a \mathrm{Beta}(2,2) prior (a Dirichlet prior for multinomial counts), equivalently the posterior mean under a flat prior. It fixes the zero-count problem of Naive Bayes.
Q9Why do we maximize the log-likelihood instead of the likelihood?
The logarithm is increasing, so the maximizer is the same. It turns the product over data points into a sum, which avoids numerical underflow and is easy to differentiate; and for exponential-family models such as the Gaussian and the Bernoulli it gives simple, often concave, objectives.
Q10What are the limitations of MAP compared with a fully Bayesian approach?
MAP is a single point: it gives no uncertainty, its mode can be untypical of a skewed posterior, and it depends on the parameterization because densities change under a change of variables (with a flat prior and 7 heads in 10, MAP is 0.7 in \theta but 0.667 in log-odds). A fully Bayesian approach keeps the posterior and averages predictions over it, at a higher computational cost.