5.3.14 · D2MLOps & Deployment

Visual walkthrough — A - B testing for models

2,223 words10 min readBack to topic

Prerequisites we lean on (each one is built here too, in case you skipped it): Bernoulli and Binomial Distributions, Central Limit Theorem, Confidence Intervals, Hypothesis Testing.


Step 1 — One user is a coin flip

WHAT. Picture a single user meeting model A. They do exactly one of two things: they convert (buy, click, sign up) or they don't. Nothing in between. We write down a number for that user: if they convert, if they don't. Call it .

WHY. Our raw data are yes/no events. The honest mathematical name for "a single yes/no event that comes up 'yes' with probability " is a Bernoulli trial. We cannot skip to averages before we have named the atom the averages are made of.

PICTURE. Look at the two-branch tree in red. From one user, probability flows to the "convert = 1" branch and probability flows to "no = 0". That is the entire random behaviour of one user.

Two facts about this one coin, both readable off the tree:

The mean of a Bernoulli is just — sensible: if convert, the average of a pile of s and s is .


Step 2 — Averaging many users shrinks the wobble

WHAT. We run users through A, get outcomes , and compute the sample conversion rate

where is simply the count of s (the number who converted). The little hat means "estimated from data" — it is our guess at the true, hidden .

WHY. We can never see directly. is the closest thing we can measure. The whole test is about comparing two of these hats and asking whether their gap is real.

PICTURE. The figure shows three dot-clouds of : for , , users, each cloud centred on the same true (red line). The cloud narrows as grows. That narrowing is the single most important visual on this page.

Here is the algebra that draws that narrowing, term by term:

Read the chain:

  • Pulling out of a variance squares it → (variance is in squared units).
  • Variances of independent things add, so a sum of identical wobbles is .
  • The on top cancels one on the bottom, leaving .

Step 3 — We test the difference, so its noise is the sum of two noises

WHAT. We don't care about A alone or B alone; we care about the gap . Since A-users and B-users are different people (independent groups), the wobbles of the two hats add:

WHY. A minus sign inside a variance still adds the two variances (subtracting a wobbly thing is just as wobbly as adding it). The gap we measure inherits noise from both clouds — so it is noisier than either hat alone. We must beat that combined noise.

PICTURE. Two bell-shaped clouds side by side — A centred at , B centred at — with a red bracket showing the gap between their centres, and a shaded band showing the combined wobble of that gap.


Step 4 — The Central Limit Theorem turns the mess into one bell curve

WHAT. Even though each is a jagged , the average of many of them piles up into a smooth, symmetric bell curve (a Normal distribution). So both and — and their difference — are approximately Normal once is large.

WHY this tool and not another. We need a way to convert "how far apart are the clouds?" into "how surprising is that gap?" A bell curve is the one shape whose surprise is fully described by a single number: how many standard errors from the centre you are. The Central Limit Theorem is what earns us the right to use a bell curve here, even though our data are lumpy coins.

PICTURE. The jagged spikes (top) morph, via CLT, into a smooth red bell (bottom). The horizontal axis is now measured in standard errors, and the marker at distance from the centre shows "how many SEs out is our gap ."

Now we imagine the world of the null hypothesis : "A and B are secretly the same", i.e. , so the true gap is . We ask: if the true gap were zero, how many standard errors is our observed gap? That count is the z-statistic:

A big means "our gap is many noise-widths out — hard to explain by luck."


Step 5 — Pool the rate, because under there is only one true

WHAT. To compute we need and — which we don't know. Under they are equal, so we estimate that one shared rate using all the conversions from both groups pooled together:

and plug it into the standard error:

WHY pool. We are testing the null world where both arms share one true . The most accurate estimate of that single number uses every user we have, not just half. This gives the sharpest, fairest standard error for the "no difference" hypothesis.

PICTURE. Two buckets of conversions ( and ) being poured into one big bucket, whose fill-level is . The red level line is the pooled rate.

Decide. Convert to a two-sided p-value , where is the area under the bell to the left of a point. If p-value (usually ), the gap is too surprising to be luck → reject . See it worked in Step 7.


Step 6 — WHY it takes so long: signal must climb out of noise

WHAT. Before running, we ask: how many users per group do we need to reliably catch a lift of size ? The classic answer:

WHY. Read it as a tug-of-war between signal and noise. To see , it must poke above the noise band. The in the denominator is the killer: halve the effect you want to catch and quadruples.

PICTURE. The signal (red arrow, fixed length) against a noise band that shrinks with . Where the noise band's edge drops below the signal, the effect becomes detectable — that crossing point is your required .


Step 7 — The whole machine on real numbers

WHAT. Run the pipeline on the parent's Example 1.

PICTURE. Our observed (red) sits just inside the rejection thresholds — you can literally see it fall short. The p-value is the shaded tail area beyond .


The one-picture summary

Everything above, compressed: raw coins → averaged into hats that narrow with → their gap standardized against pooled noise into → compared to the bell's thresholds → verdict.

Recall Feynman retelling — the whole walkthrough in plain words

Two lemonade recipes. Each kid who visits either buys again (a ) or doesn't (a ) — that's one coin flip (Step 1). Count the fraction who came back at each stand; with few kids that fraction bounces around wildly, with many kids it settles down (Step 2). You care about the difference between the two stands' fractions, and because both fractions bounce, the difference bounces even more — its jitter is the two jitters added (Step 3). Pile up enough kids and that difference forms a smooth hill; measure how many "jitter-widths" the two stands are apart — that's (Step 4). To judge fairly whether the recipes are truly the same, you pretend they are and pool all the kids to estimate the one shared come-back rate (Step 5). If your measured gap is more than about two jitter-widths out, it's too weird to be luck — the new recipe really is better. And the reason you had to hand out lemonade for weeks? To detect a small improvement, the jitter must shrink below it, and jitter only shrinks with the square root of the crowd — so tiny gains need enormous crowds (Step 6). Example 1 landed at jitter-widths — almost convincing, but not past the line, so you keep pouring (Step 7).

Related deep context: Confidence Intervals (the flip side of this test), Model Monitoring & Drift, Offline vs Online Evaluation, Canary Releases, Shadow Deployment, Multi-Armed Bandits.