CommerceLens
Probability

Bayes' Theorem

Interactive

Worked example: given that a session contains an add-to-cart event, what is the probability it results in a purchase? Bayes' theorem lets us get there starting from P(Cart | Purchase) instead of measuring P(Purchase | Cart) directly.

The Formula

Bayes' Theorem
P(Purchase | Cart) = [ P(Cart | Purchase) · P(Purchase) ] / P(Cart)

Plugging In the Numbers

Step-by-Step
Every value below comes directly from data.bayes in the precomputed analytics payload.
1
Start with P(Cart | Purchase)
50.8% — among sessions that purchased, this share also added to cart.
2
Multiply by the base rate P(Purchase)
50.8% × 27.5% = 13.9783%
3
Divide by P(Cart)
13.9783% ÷ 25.4% = 55.0%
4
Result
P(Purchase | Cart) = 55.0%, computed entirely via Bayes' theorem — without ever directly counting purchase-given-cart sessions.

Two Routes, Same Answer

Direct Empirical Calculation
55.0%
P(Purchase ∩ Cart) / P(Cart), counted straight from the data
Bayes' Theorem Calculation
55.0%
[P(Cart|Purchase) · P(Purchase)] / P(Cart)
Absolute Difference
0
Both routes agree, up to floating point

The two calculations agree because Bayes’ theorem is a mathematical identity, not a source of new information — it is simply a different way of arranging the same joint probabilities. It becomes genuinely useful in practice when you know P(B | A) from one source (for example, a subgroup study or a lab test’s known false-positive rate) but cannot directly observe P(A | B).

Try It Yourself: Any Two Events

Interactive Bayes Calculator
Pick any outcome event A and evidence event B. We compute P(A | B) via Bayes’ theorem — starting only from P(B | A), P(A), and P(B) — and compare it against the direct empirical conditional probability, live from the underlying session-level data.
Outcome (A)
Evidence (B)
Bayes' Theorem
P(P | D) = [ P(D | P) · P(P) ] / P(D) = [ 56.9% × 27.5% ] / 46.8%
Direct Empirical Calculation
33.5%
P(P ∩ D) / P(D), counted straight from the data
Bayes' Theorem Calculation
33.5%
[P(D|P) · P(P)] / P(D)
Absolute Difference
0
Both routes agree, up to floating point

Understanding Bayes’ Theorem

Bayes’ theorem is a way to flip a conditional probability around. If you know how likely evidence is given an outcome, you can use it — together with how common the outcome and the evidence are on their own — to work out how likely the outcome is given the evidence. It is the mathematical backbone of updating a belief when new information arrives.

This page describes the observed sample. It does not claim that adding an item to a cart causes a purchase — only that the two events are strongly associated in the data. Confounding factors (purchase intent, browsing time, discount exposure) plausibly drive both.