Start learning free

LESSON 124 OF 165 · MACHINE LEARNING: STATISTICS AND A/B TESTS

An A/B Test: Two Conversion Rates

Practice

The shop has a new checkout page. In an A/B test, visitors are split at random during the same days: group A sees the old page and group B sees the new one. For each group you count the visitors and the buyers. Buyers divided by visitors is the group's conversion rate.

The starting code builds the experiment with a seed, so it comes out the same on every run. rng.random(2000) gives back 2,000 random numbers between 0 and 1, and < 0.10 turns each one into True (bought) or False. So a is 2,000 visitors on the old page who each buy with a 10% chance, and b is 2,000 visitors on the new page with a 12% chance. In a real test you never see those chances. You only see who bought.

In an array of True and False, True counts as 1 and False as 0. len(x) gives back how many values there are, x.sum() gives back how many are True, and x.mean() gives back the share that is True:

clicks = np.array([True, False, False, True, False])
print(len(clicks), clicks.sum(), clicks.mean())   # 5 2 0.4

A gap between two rates proves nothing on its own. Two groups that see the same page also get different rates, just by luck. So your code also shows the old page to two fresh groups of 2,000, five times, and prints how far apart their rates land. Your code must print:

A (old page): 2000 visitors, 210 bought, rate 0.105
B (new page): 2000 visitors, 236 bought, rate 0.118
Difference B - A: 0.013
Old page twice, difference: -0.004
Old page twice, difference: 0.0
Old page twice, difference: -0.005
Old page twice, difference: -0.008
Old page twice, difference: -0.008

Your task: print each group's visitors, buyers and rate, then B's rate minus A's rate. Then, 5 times, make two new old-page groups, old_1 and old_2, and print the rate of old_2 minus the rate of old_1. Round every rate and difference to 3 decimals.


Assignment
Follow the Coding Tutorial to print the two groups' rates and their difference, then five differences between two groups that saw the same page.


Hint
a.mean() is group A's rate. Inside the loop, make each old-page group the way a is made, with rng.random(2000) < 0.10, and indent the loop's lines.


STEP 1 OF 7
    Ctrl + Enter to check