Contents/ Part IX · Probability & Distributions Case Studies/ Chapter 49

E-commerce Conversions: the Bernoulli Trial

Every web session is a single yes/no experiment: add to cart, or not. That is the Bernoulli distribution, the atom of probability. From 1,000 real sessions we estimate the conversion rate, model it, split it by device, and simulate when the next purchase will arrive.

⏱️ ~13 min read
🐍 Notebook included
📊 Chapter 49

The simplest distribution describes the simplest experiment: one trial, two outcomes. A coin flip, a medical test, and a web session all share the same skeleton. Here the trial is a visit and the success is a cart addition, and the whole story rides on a single number, the conversion rate p.

p
A Bernoulli trial has two outcomes: success (1) with probability p, failure (0) with probability 1 − p. Its mean is p and its variance is p(1 − p). Everything in this chapter is built from that one parameter.
🛒
The dataset

ecommerce_session_logs.csv holds 1,000 sessions, each with a device type and a binary cart_addition flag. We treat each session as an independent Bernoulli trial and ask: what is the baseline rate, does it differ by device, and how long until the next conversion?

1

The Bernoulli Model: One Rate, p

Estimating p is just counting: the conversion rate is the fraction of sessions that added to cart. Of 1,000 sessions, 148 converted, so p = 0.148. That single number is the entire distribution.

The whole distribution is two bars: P(0) = 0.852, P(1) = 0.148 0.852 0.148 no cart addition (0) add to cart (1) mean = p = 0.148 var = p(1−p) = 0.126

Because conversions are rare (p well below 0.5), the variance p(1 − p) = 0.126 is modest: the outcome is lopsided and fairly predictable. A Bernoulli's variance is largest at p = 0.5 (maximum uncertainty) and shrinks toward 0 as p approaches 0 or 1.

2

Segmenting the Trial by Device

A single rate can mask very different audiences. Splitting p by device type treats each segment as its own Bernoulli process, the first move in turning a number into a decision.

Conversion rate by device (each its own p) 0.238 0.140 0.140 overall 0.148 Tablet (n=84)Mobile (n=608)Desktop (n=308)

Tablet visitors convert at 23.8%, well above mobile and desktop (both about 14%). That gap is a lever, but the tablet sample is small (84 sessions), so the estimate is noisy. Whether the difference is real, not just sampling luck, is exactly the kind of question the chi-square test answers (see the Survey Demographics (Chi-Square) case study).

3

When Will the Next Purchase Arrive?

Stack Bernoulli trials in time, one session after another, and a new question appears: how many sessions until the next conversion? That waiting time follows the geometric distribution, with mean 1/p. We answer it by simulation.

Sessions until the next add-to-cart: geometric, mean 1/p ≈ 7 mean ≈ 7 sessions until next conversion →

Simulating two million sessions, the average gap is 6.76 sessions, exactly 1/p, and the geometric PMF fits the simulated waiting times perfectly. Now the funnel speaks in forecasts: there is a 55% chance of a conversion within the next 5 sessions and 80% within 10. Scaled to a day of 200 sessions, the conversion count is binomial with an expected 30 sales, and by the Central Limit Theorem (see the Freight Weights & the CLT case study) the daily total is approximately normal.

🔮
One trial, three distributions

This is the chapter's quiet lesson: the humble Bernoulli trial is the seed of a whole family. One session is Bernoulli; the wait to the next success is geometric; a fixed batch of sessions is binomial; and a long run of daily totals is normal. Master p, and all four follow.

🐍

Run the conversion analysis

The companion notebook loads the 1,000 sessions, estimates p and its variance, breaks the rate down by device, then simulates two million sessions to recover the geometric waiting time to the next purchase (mean 6.76) and scales the trial up to a binomial daily total, every number reproduced in code.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub

View opens the rendered notebook instantly (no setup). Open in Colab runs & edits it live in your browser. To run locally, install numpy, pandas, scipy, and matplotlib and launch jupyter notebook.

🎓 Key Takeaways

  • A web session is a Bernoulli trial: success (cart addition) with probability p, failure with 1 − p.
  • One parameter p = 0.148 carries everything: mean = p, variance = p(1 − p) = 0.126.
  • Segmenting by device gives each group its own p; tablets convert highest (0.238) but on a small sample.
  • The wait to the next success is geometric with mean 1/p ≈ 7 sessions, recovered exactly by simulation.
  • Bernoulli is the seed: it grows into the geometric (waiting), the binomial (batches), and the normal (daily totals).
4

Quiz: Test Yourself

Eight quick questions on the Bernoulli case study. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved, so you can hop back to the chapter and return anytime.