liveBook · Manning

Posterior probability

As explained in Grokking Machine Learning

A posterior probability is the probability assigned to an event or hypothesis after incorporating observed evidence.

Suppose you want to know whether it will rain. Before checking your surroundings, you have a rough estimate; after learning that you are in the Amazon rain forest, you can update it. That updated estimate is the posterior probability: the probability assigned to an event or hypothesis after incorporating observed evidence. The prior is the initial probability, the event supplies information, and the posterior is the resulting estimate. section 8.1

Bayes’ theorem makes the update concrete:

  • Start with a prior: among 100 emails, 20 are spam, so the initial spam probability is 0.2. section 8.2
  • Treat observed information as the event: the email contains the word “lottery.” section 8.2
  • Restrict attention to emails containing that word: 15 are spam and 5 are ham, producing a posterior of 15/20 = 0.75. section 8.2

From words to a spam prediction

A real email dataset estimates spam and ham priors, counts each word in both classes, and combines the resulting evidence with the naive Bayes algorithm. The model returns 0.99997 for “buy cheap lottery easy money now,” 0.0000696 for “meet me at the lobby of the hotel at nine am,” and the spam prior, 0.2388, for an unknown word such as “asdfgh.” section 8.3

How Grokking Machine Learning covers it

How deep it goes
Defines prior, event, and posterior, then works through counts and a naive Bayes implementation without deriving Bayes’ theorem formally.
Examples
Uses rain in the Amazon, medical testing, lottery emails, and a real email dataset with Python predictions.
What it assumes
Starts probability reasoning from initial estimates and observed events before combining multiple word-based events.
What you can do after
Apply it via naive Bayes to estimate whether emails are spam from their observed words.
How it connects
Connects posterior probability to prior probability, Bayes’ theorem, events, independence, and the naive Bayes algorithm.

Also explained in

Compare how 8 books explain posterior probability →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning. The section links point to the parts of the book it draws on.