mercredi 9 septembre 2020

Generating multiple test-control variants randomly for A/B testing in Python

I want to perform an A/B experiment with 3 buckets. If I had 2 buckets, I could get 2 sets of users from all the users by using the method random.sample

from random import sample

test = sample(all_users, k=100)
control = set(all_users) - set(test)

Since I need 3 sets of users, will the following code ensure that every user has equal chances of being in either variant?

NUM_USERS = int(len(all_users) * 0.33)

variant1 = sample(all_users, NUM_USERS)
variant2 = sample(set(all_users) - set(variant1), NUM_USERS) 
variant3 = set(all_users) - variant1 - variant2



Aucun commentaire:

Enregistrer un commentaire