07Reading an A/B test on conversion (Python, no SciPy)

mediumpython
35:00

07 Reading an A/B test on conversion (Python, no SciPy)

One OpenAI senior data scientist candidate reports a take-home that asked how to define success metrics and decide whether a launch worked (1 report). This is practice in that shape, not a leaked question.

Set a 35-minute timer. Read one level at a time, and run only that level's tests until they pass: pytest problems/07_ab_test -k level1. Earlier levels must keep passing. statistics.NormalDist is in the standard library.

Level 1. two_proportion_test(conv_a, n_a, conv_b, n_b, alpha=0.05, share_b=0.5) returns a dict. For now it holds diff, B's conversion rate minus A's, and z, the z statistic under the null of equal rates, so its standard error uses the pooled rate.

Level 2. Add p_value, two-sided.

Level 3. Add ci, (low, high): the 1 - alpha confidence interval for diff (Wald, with the unpooled standard error).

Level 4. Add srm: True when the split missed its plan by more than chance allows, which is a sample ratio mismatch. The plan sends a share share_b of users to B. Test B's user count against (n_a + n_b) * share_b with a two-sided z test (a chi-square test with one degree of freedom gives the same p). A miss in either direction counts. Use the strict cutoff the check needs when it runs on every experiment: flag it when p < 0.001.

Things to get right: pooled for the test and unpooled for the interval (and why), two-sided, and what you'd tell a PM when p = 0.04 on day 2 of a 14-day test. Follow-ups: peeking and sequential testing, multiple metrics and corrections, novelty effects, guardrails, and what changes for a revenue metric with a heavy tail.

solution.py
Run the tests to see which pass.