TL;DR
A prior distribution is what you believe about an unknown quantity before you have seen any data. You write that belief as a probability distribution over the values the quantity could take. When data arrives, Bayes' rule combines the prior with how well each value explains the data, and the result is the updated belief, called the posterior.
Not being sure is still a belief. A prior can be sharp, saying the answer is almost certainly near one value, or flat, saying every value is equally plausible.
Where you'll see it: estimating the chance that a coin lands heads, choosing a penalty that keeps a regression from fitting noise, and any model that reports how uncertain its answer is.
Intuition
Start from a question you already know
Someone hands you a coin and asks: what is the chance it lands heads? Before flipping it, most people say "about one half." You have a belief, even though you have no data yet. You also would not be shocked if it were a trick coin with a heavier side, so your belief has some spread around one half.
Flip it ten times and see seven heads. Your belief should move towards "more likely heads than tails," but not all the way to certainty, because ten flips is a small sample. The prior is the starting point for that move. It says how far the data has to push before your answer changes.
Why we need it at all
The data alone can mislead. Ten flips, seven heads, suggests a chance of 0.7. But if you flipped a coin twice and got two heads, the same reasoning would suggest a chance of 1.0, which almost nobody believes. The prior keeps small samples from producing extreme answers. Combined with the data it gives a sensible answer that improves as the data grows. The usual estimate that uses no prior at all is covered in Maximum Likelihood Estimation, and the gap between the two is the subject of this lesson.
Two sources of information
Bayesian reasoning splits the work into two parts.
- The prior is what you knew before the data, written as a distribution over the unknown.
- The likelihood is how probable the observed data is for each possible value of the unknown.
Multiply the two, rescale so the total is one, and you have the posterior. Nothing else is needed.
- prior: flat
- after one head
- after three heads, one tail
The math
Let stand for the unknown quantity, here the chance of heads. Let stand for the observed data.
The prior is a probability density over the possible values of , written before the data is seen. Its values are non-negative, and its integral over all possible is .
Bayes' rule gives the posterior:
Here is the likelihood: the chance of seeing data if the unknown were (a conditional probability). The denominator is a normalising constant. It makes the posterior integrate to one, and it can be computed as the sum or integral of the numerator over all . Because does not depend on , the posterior is proportional to likelihood times prior:
That proportionality is the working rule. Compute the product, then rescale.
Discrete hypotheses
When the unknown takes a few values, the prior is a list of numbers, one per hypothesis. The same rule applies with sums in place of integrals. If and are two hypotheses with priors and , then
The uniform prior
A prior that gives every value of on the same density is the uniform prior, on that interval (see Uniform Distribution). It says you have no preference. It is common in teaching because the arithmetic is simple, although it is not automatically the "neutral" choice, as the tradeoffs section explains.
The MAP estimate
The posterior is a full distribution, but a single answer is often wanted. The most probable value of under the posterior is the maximum a posteriori (MAP) estimate, covered in Maximum a Posteriori (MAP) Estimation. Maximising is the same as maximising the likelihood when the prior is flat, and it adds the prior's preference when it is not.
Worked examples
A box is either type A or type B. Before drawing, your prior says A is more likely: and . A ball drawn from A is red with chance . A ball drawn from B is red with chance . You draw one ball and it is red. Which box is it more likely to be?
- Likelihood of red under each box: and .
- Multiply each likelihood by its prior: for A, ; for B, .
- Total: . This is .
- Posterior for A: . Posterior for B: .
Interpretation: the prior favoured A, but the red ball is three times more likely from B than from A. The evidence overturned the prior, though not by much, because the prior was not extreme.
Let be the chance of heads. Use a uniform prior, on . Flip the coin and get three heads and one tail. The likelihood of one specific sequence with heads and tails is .
- Likelihood: .
- Multiply by the prior, which is : the unnormalised posterior is .
- Normalising constant: .
- Posterior density: . Check: it integrates to .
- Posterior mean: .
- For comparison, the most likely single value, the maximum likelihood estimate, is .
Interpretation: the posterior mean sits between the prior's centre, , and the data's . The prior pulls the estimate back towards one half, which is most useful when the data is scarce.
A common use of a prior is to stop a fitted coefficient from growing too large. Suppose you fit a line through the origin, (a tiny Linear Regression), and observe two points and . Noise is Gaussian with variance (see Gaussian (Normal) Distribution). Put a Gaussian prior on the slope with mean and variance .
- The negative log of the posterior is, up to a constant, . Maximising the posterior means minimising this.
- With , minimise .
- Take the Derivative with respect to and set it to zero: , which gives , so .
- Without the prior (maximum likelihood), .
Interpretation: the prior shrinks the slope from to . The penalty term is exactly the L2 penalty used in practice to fight Overfitting, and the amount of shrinkage depends on the ratio . A tighter prior, with smaller , pulls harder.
Tradeoffs and failure modes
A prior is a choice, and a choice can be wrong. The table lists situations you will meet.
| Situation | Problem | Better choice |
|---|---|---|
| Little data and a strong prior | The answer mostly reflects the prior | Check the prior's influence, and collect more data if it dominates |
| "Flat" prior on a quantity with a natural scale | Flat in one parameterisation (for example versus ) is not flat in another | Pick the prior on the scale where you have knowledge, or use a standard reference prior chosen for that purpose |
| Prior ruled out the true value | No amount of data recovers it | Give the prior some spread across plausible values |
| Only the most probable value is needed | A full posterior is more work than needed | Use Maximum a Posteriori (MAP) Estimation |
| Prior is unknown and must be learned | Hyperparameters (the settings of the prior itself, such as ) can overfit the data | Put a prior on them too (a hierarchical model) or Bayesian Model Averaging |
The most common objection is that priors are subjective. That is true, and it is also a feature: the assumptions are stated where anyone can criticise them, and they can be tested by checking how much the answer changes when the prior changes. A flat prior is not automatically objective either, since uniform in one scale is not uniform in another.
History
The idea goes back to Thomas Bayes, an English minister whose essay on the problem of inverse probability was published in 1763, two years after his death, through the efforts of Richard Price. Pierre-Simon Laplace developed the approach in the 1770s and applied it widely in astronomy and population studies, using a flat prior when nothing else was known. The term "prior" and the broad programme of updating beliefs with data became the basis of Bayesian statistics. The approach was for a long time overshadowed by frequentist methods, and the spread of computing in the late twentieth century, which made posteriors feasible to compute, brought it back into wide use.
Recap
A prior is the belief you hold before the data. Bayes' rule multiplies it by the likelihood and rescales, which gives the posterior. A flat prior produces simple arithmetic, and a shaped prior encodes real knowledge. On a regression, a Gaussian prior on each coefficient becomes a penalty, which is why it reappears as shrinkage. The next step is to pick one answer from the posterior with Maximum a Posteriori (MAP) Estimation, or to average over models with Bayesian Model Averaging.
Check yourself
QuestionIn one sentence, what is the difference between the prior and the posterior?Show answer
The prior is the belief about the unknown before the data, and the posterior is the belief after combining the prior with the likelihood of the data. The prior is an input to Bayes' rule, and the posterior is its output.
QuestionA prior gives probability 0.5 to hypothesis A and 0.5 to B. The data is three times more likely under A than under B. What is the posterior probability of A?Show answer
Let the likelihood of the data under B be , so under A it is . Multiply by the priors: A gives , and B gives . The total is . So .
QuestionWhy does a prior prevent a conclusion from two heads in two flips that the coin always lands heads?Show answer
The likelihood alone would favour a chance of one, because that makes two heads most probable. A prior that puts little weight near one, such as a flat or a centred prior, keeps the posterior spread out and away from the extreme. The data is weak, so the prior's pull towards the centre dominates. With more flips the likelihood would overpower the prior.
QuestionYou want a single estimate of a coefficient with a Gaussian prior centred on zero. Name the estimate and say what the prior does to it compared with no prior.Show answer
The estimate is the maximum a posteriori (MAP) value. The prior pulls the estimate towards zero, shrinking it relative to the maximum likelihood estimate. The amount of shrinkage grows as the prior becomes tighter relative to the noise.