Skip to main content

MAP, ML & the Cancer Example

Source: Unit 3 §5

Bayes' theorem for hypotheses

P(hD)=P(Dh)P(h)P(D)P(h \mid D) = \frac{P(D \mid h) \cdot P(h)}{P(D)}
TermNameMeaning
P(h|D)Posteriorprobability of the hypothesis after seeing the data - this is what we want
P(h)Priorprobability of the hypothesis before any data
P(D|h)Likelihoodprobability of the data given the hypothesis
P(D)Evidenceprior probability of the data, a normalising constant

MAP: maximum a posteriori

Find the most probable hypothesis given the data:

hMAP=argmaxhHP(hD)=argmaxhHP(Dh)P(h)h_{\text{MAP}} = \arg\max_{h \in H} P(h \mid D) = \arg\max_{h \in H} P(D \mid h) \cdot P(h)

P(D)P(D) is dropped because it is a constant independent of hh, and a constant cannot change which hh wins the argmax.

Best hypothesis means most probable hypothesis. The whole goal of Bayesian learning is to locate the hypothesis that best explains the observed data. Linear and logistic regression can both be framed as MAP estimation.

ML: maximum likelihood

If every hypothesis is equally probable a priori, so that P(hi)=P(hj)P(h_i) = P(h_j) for all i,ji, j, the prior factors out of the argmax and MAP collapses to:

hML=argmaxhHP(Dh)h_{\text{ML}} = \arg\max_{h \in H} P(D \mid h)
Exam cueThe one-line relationship

If the prior is uniform, then hMAP=hMLh_{\text{MAP}} = h_{\text{ML}}. ML is not a different philosophy, it is MAP with the prior switched off.

Worked example: does the patient have cancer?

NumbersThe setup
  • P(cancer)=0.008P(\text{cancer}) = 0.008, so P(¬cancer)=0.992P(\neg\text{cancer}) = 0.992.
  • Test accuracy given cancer: P(+cancer)=0.98P(+ \mid \text{cancer}) = 0.98, P(cancer)=0.02P(- \mid \text{cancer}) = 0.02.
  • Test accuracy given no cancer: P(+¬cancer)=0.03P(+ \mid \neg\text{cancer}) = 0.03, P(¬cancer)=0.97P(- \mid \neg\text{cancer}) = 0.97.
Test \ ActualCancer¬Cancer
+0.980.03
0.020.97

A patient tests positive. Cancer or not? Compare the two unnormalised posteriors, which is all MAP needs.

StepsWorking the posterior
  1. Hypothesis cancer: P(+cancer)P(cancer)=0.98×0.008=0.00784P(+ \mid \text{cancer}) \cdot P(\text{cancer}) = 0.98 \times 0.008 = \mathbf{0.00784}.
  2. Hypothesis ¬cancer: P(+¬cancer)P(¬cancer)=0.03×0.992=0.02976P(+ \mid \neg\text{cancer}) \cdot P(\neg\text{cancer}) = 0.03 \times 0.992 = \mathbf{0.02976}.
  3. Since 0.02976>0.007840.02976 > 0.00784, the winner is hMAP=¬cancerh_{\text{MAP}} = \neg\text{cancer}. The patient most likely does not have cancer.
  4. Normalise to recover real probabilities. The sum is 0.00784+0.02976=0.03760.00784 + 0.02976 = 0.0376.
  5. P(cancer+)=0.00784/0.0376=0.21P(\text{cancer} \mid +) = 0.00784 / 0.0376 = \mathbf{0.21}.
  6. P(¬cancer+)=0.02976/0.0376=0.79P(\neg\text{cancer} \mid +) = 0.02976 / 0.0376 = \mathbf{0.79}.
UNNORMALISED POSTERIOR P(+ | h) · P(h)h = cancer0.98 × 0.0080.00784h = ¬cancer0.03 × 0.9920.02976AFTER NORMALISING BY 0.03760.210.79P(cancer | +)P(¬cancer | +)
The test is excellent and the patient tested positive, yet the no-cancer bar is still nearly four times longer. The prior of 0.008 is doing all the work.
GotchaA test that catches 98% of cancers, and a positive still means 21%

Even after a positive test, cancer is only 21% likely, because the prior is only 0.008. There are simply far more healthy people generating false positives than sick people generating true positives. Bayesian inference depends strongly on the priors, and this example exists to make that impossible to forget.