Bayesian AB Test Report Builder
Baker Moran
This allows AB testers to create a standard report for test results with python. Handles multiple variant tests, with a variety of prior function types. This is meant to be an abstraction from the nitty gritty of the details of Bayesian statistics. That said, some knowledge about which prior function to use etc. will be helpful for the user.
Example Output for a conversion rate test
Installation
-
Install via pip or uv (requires Python 3.12+)
pip install BayesABTest # or uv add BayesABTest
OR
-
Download files from PyPi and install
Quick start
import pandas as pd
from matplotlib import pyplot as plt
from BayesABTest import ABTest
df = pd.read_csv('results.csv') # a metric column and a bucket column
result = ABTest('conversion', 'beta', control='off', random_state=0).fit(df)
result.prob_better('on') # probability the variant beats the control
result.summary() # posterior mean, interval and lift per bucket
result.plot() # the standard report
plt.show()
family is 'beta' (conversion rates), 'log-normal', 'normal' or 'poisson'. See the ABTest docs for priors, loss and plotting options.
Development
uv sync # create .venv and install runtime + dev dependencies
uv run pytest -n 4 # run tests
uv run ruff check . # lint
uv build # build sdist and wheel
Package Functions and Classes
ABTest
Class implementing out of the box AB testing functionality. Simple, easy to use AB testing with many different prior function types, all in one clean interface.
ab_test_dist_explorer
Functions allowing a user to explore different distributions with simple to user interface. Allows a user to visually learn about bayesian statistics, and inform proper prior function choice when doing Bayesian AB testing.
Upgrading from 1.x
2.0 changes the API and fixes several math errors. See the migration guide.
Appendix
Learning
For a documentation explaining and motivating the use of Bayesian statistics to evaluate A/B tests, see documentation
Acknowledgements
There is a lot of documentation out there about a Bayesian framework of A/B testing. Some of the specific articles are listed below. Most of the work I came across was written in R, and I set out to create a Python implementation. The visuals were inspired by a standard template we use at Root, first written by https://github.com/zachurchill-root.
Articles Reference:
- https://www.countbayesie.com/blog/2015/4/25/bayesian-ab-testing
- https://medium.com/convoy-tech/the-power-of-bayesian-a-b-testing-f859d2219d5
- https://cdn2.hubspot.net/hubfs/310840/VWO_SmartStats_technical_whitepaper.pdf
Version History
0.1.0-prealpha- 12/02/20191.0.0-alpha- 12/27/20191.0.1-alpha- 01/02/20201.0.2-alpha- 06/17/20201.0.3-alpha- 06/17/20201.0.4-alpha- 06/22/20201.0.5-alpha- 06/22/20201.0.6-alpha- 06/22/20201.0.7-alpha- 07/09/20211.0.8-alpha- 03/29/20221.0.9-alpha- 03/29/20222.0.0- API redesign and math fixes, see the migration guide
Metadata
Release files for BayesABTest 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bayesabtest-2.0.0.tar.gz | 1.1 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bayesabtest-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.1 MB
Release files / bayesabtest-2.0.0.tar.gz
| Download URL | bayesabtest-2.0.0.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d8336d158f257a2337028dd291db035f1bf6c83df3731f42dea1d2e6546f5af7
|
|
BLAKE2b-256 checksum How to use checksums |
398a1a40905b62b990bcdcced63b95128ff0bbcc31420e6631a901318eccde7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / bayesabtest-2.0.0-py3-none-any.whl
| Download URL | bayesabtest-2.0.0-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db9dbca97e1317ec16355944caf5993640ee2deb951c26d60fe650523b07deaa
|
|
BLAKE2b-256 checksum How to use checksums |
0b2a787b53b229968eb3ae4d2a5ac952ba8829dc8ec3b5703481d5d5341b9dfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|