Skip to main content

Bayesian AB Test Report Builder

Build Status PyPI version

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

Conversion rate example report

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:

Version History

  • 0.1.0-prealpha - 12/02/2019
  • 1.0.0-alpha - 12/27/2019
  • 1.0.1-alpha - 01/02/2020
  • 1.0.2-alpha - 06/17/2020
  • 1.0.3-alpha - 06/17/2020
  • 1.0.4-alpha - 06/22/2020
  • 1.0.5-alpha - 06/22/2020
  • 1.0.6-alpha - 06/22/2020
  • 1.0.7-alpha - 07/09/2021
  • 1.0.8-alpha - 03/29/2022
  • 1.0.9-alpha - 03/29/2022
  • 2.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)

Source distribution for BayesABTest 2.0.0
File Size Uploaded
bayesabtest-2.0.0.tar.gz 1.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for BayesABTest 2.0.0
File Interpreter ABI Platform
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}

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page