Skip to content

Commit 42702b0

Browse files
adding ABtestingpy
1 parent 556bccc commit 42702b0

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
This is an example of using Bayesian A/B testing
3+
4+
"""
5+
6+
import pymc as mc
7+
8+
#these two quantities are unknown to us.
9+
true_p_A = 0.05
10+
true_p_B = 0.04
11+
12+
#notice the unequal sample sizes -- no problem in Bayesian analysis.
13+
N_A = 1500
14+
N_B = 1000
15+
16+
#generate data
17+
observations_A = mc.rbernoulli( true_p_A, N_A )
18+
observations_B = mc.rbernoulli( true_p_B, N_B )
19+
20+
21+
22+
#set up the pymc model. Again assume Uniform priors for p_A and p_B
23+
24+
p_A = mc.Uniform("p_A", 0, 1)
25+
p_B = mc.Uniform("p_B", 0, 1)
26+
27+
28+
#define the deterministic delta function. This is our unknown of interest.
29+
30+
@mc.deterministic
31+
def delta( p_A = p_A, p_B = p_B ):
32+
return p_A - p_B
33+
34+
35+
#set of observations, in this case we have two observation datasets.
36+
obs_A = mc.Bernoulli( "obs_A", p_A, value = observations_A, observed = True )
37+
obs_B = mc.Bernoulli( "obs_B", p_B, value = observations_B, observed = True )
38+
39+
#to be explained in chapter 3.
40+
mcmc = mc.MCMC( [p_A, p_B, delta, obs_A, obs_B] )
41+
mcmc.sample( 20000, 1000)

0 commit comments

Comments
 (0)