Skip to content

Commit

Permalink
Merge pull request #21 from bakermoran/gamma_uninformed
Browse files Browse the repository at this point in the history
Gamma uninformed prior
  • Loading branch information
bakermoran authored May 6, 2020
2 parents 237cf30 + e6472da commit 9d02126
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
11 changes: 8 additions & 3 deletions BayesABTest/_prior_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,17 @@ def set_params(self):
if self.ab_test.prior_func == 'beta':
self.alpha = 1
self.beta = 1
elif self.ab_test.prior_info == 'poisson':
elif self.ab_test.prior_func == 'poisson':
raise NotImplementedError('poisson uninformed prior '
'not yet implemented')
elif self.ab_test.prior_func == 'log-normal':
self.mean = np.log(1)
self.var = np.log(20000)
elif self.ab_test.prior_func == 'normal':
self.mean = 1
self.var = 20000
else:
raise NotImplementedError('normal uninformed prior '
'not yet implemented')
raise RuntimeError('Reached unexpected code')
return

# empirical bayes
Expand Down
29 changes: 29 additions & 0 deletions tests/model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,35 @@ def two_variants_continuous():
plt.show()


def gamma_uninformed():
"""Create data and run a two variant report for a continuous metric."""
rawdata_ln = dh.create_continuous_data([600, 610, 615], [1.5, 1.5, 1.5],
['control', 'variant_1',
'variant_2'],
metric_name='total_premium')

premium = ab(rawdata_ln, metric='total_premium', prior_info='uninformed',
prior_func='log-normal', debug=True,
control_bucket_name='control', compare_variants=True,
samples=1000)
premium.fit()
premium.plot()
plt.show()

rawdata_n = dh.create_continuous_data([600, 601, 602], [30, 30, 30],
['control', 'variant_1',
'variant_2'],
metric_name='total_premium',
log=False)
premium = ab(rawdata_n, metric='total_premium',
prior_info='uninformed', prior_func='normal',
debug=True, control_bucket_name='control',
compare_variants=True, samples=1000)
premium.fit()
premium.plot(lift_plot_flag=True)
plt.show()


def three_variants_continuous():
"""Create data and run a three variant report for a continuous metric."""
rawdata = dh.create_continuous_data([600, 610, 615, 620],
Expand Down

0 comments on commit 9d02126

Please sign in to comment.