CS代考 ab_test_simulation(1)

ab_test_simulation(1)

AB Testing Simulation¶
Now that we’ve finished the AB testing calculation GIVEN data. How do we get the data?

Copyright By PowCoder代写 加微信 powcoder

The goal of this exercise is to create data like the one you see in your previous lesson. Here are some parameters:

There are 14 days and 1000 users
Assume user ids range from 0 to 999, hint: list(range(5))
Each user has a 50% chance of visiting each day. If they don’t visit, no views are created.
A user should be assigned to the same treatment/control group across the days!
Only 5% of the users should be assigned to treatment
A user’s distribution for views follows a $Geometric(p=0.1)$. Hint: numpy.random.geometric
A user’s distribution for clicks given their views follows a $Binomial(n=views, p_*)$, where $p_a$ and $p_b$, the probability of a click given a view for group A and B should be parametrized, i.e. coded so we can change it later. Hint: numpy.random.binomial
Compile all the data into 2 matrices, each are 1000 by 14, called clicks and views. Hint: numpy.vstack() or numpy.hstack()

Create an variable assign that contains the treatment/control status for each user.

What data type can this be? Later we will need to pull up user X’s treatment status quickly!

# assign can be a list or dictionary

assign = np.random.choice([‘Treat’, ‘Control’], size=n, p=[0.05, 0.95])

assign[:10]

array([‘Control’, ‘Control’, ‘Control’, ‘Control’, ‘Control’, ‘Treat’,
‘Control’, ‘Control’, ‘Control’, ‘Control’], dtype=’= login_rate:
return 0, 0
views = np.random.geometric(view_p)
clicks = np.random.binomial(views, ctr_prob)
return views, clicks

sim_click_views(0.05)

Finish the whole task! Try writing a loop within another loop, e.g.

for i in range(3):
for j in range(4):
print(i + j)

views = np.zeros((n, days))
clicks = views.copy()

for day in range(days):
for uid in range(n):
ctr = 0.05 if assign[uid] == ‘control’ else 0.1
view, click = sim_click_views(ctr)
views[uid, day] = view
clicks[uid, day] = click

Write the data to a file then try to download it!
Hint: numpy.savetxt

np.savetxt(“sim_ab_views.csv”, views, delimiter=’,’)
np.savetxt(“sim_ab_clicks.csv”, clicks, delimiter=’,’)

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com