A simple tool to calculate P-value after conducting an A/B experiment
Project description
Pyabtest
A simple tool to calculate P-value after conducting an A/B experiment
A/B experiment & Hypothesis testing
Normally we run an A/B experiment to see whether a new model brings some improvement in the production metrics. After running the experiment for a fixed time period, we use hypothesis testing to scientifically come to a conclusion whether to accept the new feature or not. Usually, hypothesis testing has following components:
Null hypothesis: New model does not bring any improvement
Alternative hypothesis: New model does bring some improvement
This tool will be useful to calculate P-value to check whether we can reject the null hypothesis or not.
Installation
Use the package manager pip to install pyabtest
pip install pyabtest
Usage
Following functionalities are exposed in this package
1. Test for Sample Ratio Mismatch (SRM)
This is a test to check whether we have created audience for control vs test in a truly random manner. If there is an SRM, we should discard the A/B test results as control and variant have different type of audience. For example, we can pass following numbers in control vs test to check for SRM.
- Number of male vs Number of female
- Number of users of age < 40 vs Number of users of age >= 40
- Number of active users vs Number of inactive users
- Number of english speaking users vs Number of non-english speaking users
- Number of mobile users vs Number of desktop users
Input: Control group 1 size, Control group 2 size, Variant group 1 size, Variant group 2 size
Output: P-value, Decision
>>> import pyabtest
>>> pyabtest.test_for_sample_ratio_mismatch(control_group1_size=1000,control_group2_size=2000,variant_group1_size=
1010,variant_group2_size=1990,alpha=0.05)
{'P-value': 0.78445, 'Alpha value (significance level)': 0.05, 'Decision': "Don't discard A/B test results"}
Test used: Chi-squared Test
2. Test for Binary Metric
This test can be used when when the result/action/feedback is binary & we want to see if variant observations are coming from a differant population when compared to control. For example, this test can be used in the following situations:
- Clicks vs No clicks
- Cart vs No cart
- Order vs No order
- Number of zero search results vs Number of non-zero serach results
- Number of successful sessions vs Number of non-successful sessions
- Number of positive reviews vs Number of negative reviews
- Number of converted users vs Number of non-converted users
Input: No. of success in Control, No. of failures in Control, No. of success in variant, No. of failures in variant
Output: P-value, Decision
>>> import pyabtest
>>> pyabtest.test_for_binary_metric(control_success=50, control_failures=1000, variant_success=40, variant_failures=900, alpha=0.05)
{'P-value': 0.58718, 'Alpha value (significance level)': 0.05, 'Decision': 'Do not reject null hypothesis'}
Test used: Chi-squared Test
3. Test for Numeric Metric
This test can be used for any generic numeric metric (Count or Fraction). We can use this test even if the observations do not follow a normal distribution. In general, this test does not assume anything about the distribution as it is a non-parametric test. Example metrics include:
- Number of clicks per unique user
- Number of carts per unique user
- Number of orders per unique user
- Clicks/Views per unique user
- Orders/Views per unique user
- Orders/Session per unique user
- Revenue per unique user
- Session time per unique user
- Order value per unique user
- Successful sessions per unique user
Input: Control array, Variant array
Output: P-value, Decision
>>> import pyabtest
>>> from numpy import random
>>> pyabtest.test_for_numeric_metric(control_observations=random.randint(100, size=(20)), variant_observations=random.randint(100, size=(20)), alpha=0.05, no_of_samples=10000)
{'P-value': 0.7411, 'Alpha value (significance level)': 0.05, 'Decision': 'Do not reject null hypothesis'}
Test used: Bootstrap Test
License
References
Author
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyabtest-0.2.2.tar.gz.
File metadata
- Download URL: pyabtest-0.2.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88dd59c8f09652bcb2370267f3a6d68174cbda78bba9d5236c3e8c963ce278ad
|
|
| MD5 |
1b82c77552143ea4ebd8b92318e4d4f3
|
|
| BLAKE2b-256 |
5d3f5548ef5b388376b65770758351d520de1a6e8e515175b209c6496d825c32
|
File details
Details for the file pyabtest-0.2.2-py3-none-any.whl.
File metadata
- Download URL: pyabtest-0.2.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41b453f48c95db8d884acd98f9352ecd5d2683a566d9aef6cf3a73e86e65312a
|
|
| MD5 |
9866cf70e19e8f77d3f5994ad680a407
|
|
| BLAKE2b-256 |
591da24087da852f024db12212418aa4f594f20e339e4faef3d8eebf868b7989
|