Real Lift or Leftover Wobble?

MLOpsMedium+20 XP+20

Real Lift or Leftover Wobble?

An online bookshop A/B tests a new recommender. A random draw puts each customer in a group: group A keeps the champion (the current model), group B gets the challenger. Two weeks later, the team compares the share of customers in each group who bought something.

To tell a real difference from chance, they use a two-proportion z-test. With xxx buyers out of nnn customers in each group:

p^A=xAnA,p^B=xBnB,p^=xA+xBnA+nB\hat p_A = \frac{x_A}{n_A}, \qquad \hat p_B = \frac{x_B}{n_B}, \qquad \hat p = \frac{x_A + x_B}{n_A + n_B}p^​A​=nA​xA​​,p^​B​=nB​xB​​,p^​=nA​+nB​xA​+xB​​ SE=p^ (1−p^)(1nA+1nB),z=p^B−p^ASE\text{SE} = \sqrt{\hat p\,(1 - \hat p)\left(\frac{1}{n_A} + \frac{1}{n_B}\right)}, \qquad z = \frac{\hat p_B - \hat p_A}{\text{SE}}SE=p^​(1−p^​)(nA​1​+nB​1​)​,z=SEp^​B​−p^​A​​

The standard error uses the pooled rate p^\hat pp^​, because the null hypothesis says both models convert equally well. The p-value is two-sided: twice the area in one tail of the standard normal curve beyond ∣z∣|z|∣z∣.

The team ships the challenger only when the test gives significant evidence, a p-value below alpha, that the challenger outperforms the champion. Otherwise the champion stays.

Task: write ab_decision(buyers_a, n_a, buyers_b, n_b, alpha) returning a tuple (z, p_value, decision):

  • z and p_value rounded to 4 decimal places,
  • decision either "ship" or "keep".

The inputs always include at least one buyer and at least one non-buyer overall, so the standard error is never zero.

P-Values and Statistical Significance

Observed Z:2.0
Significance (α):

Tail Area representing the P-Value

-3-2-10123

Test Results

P-Value: 0.0455
Significance Level (α): 0.05
Decision:
Reject H₀

Examples

buyers_a = 1100
n_a = 22000
buyers_b = 465
n_b = 7500
alpha = 0.05
returns (4.0041, 0.0001, 'ship')
buyers_a = 210
n_a = 3500
buyers_b = 79
n_b = 1200
alpha = 0.05
returns (0.7259, 0.4679, 'keep')

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run