Home/AI/ML Notes/Deep Learning and Machine Learning/A/B Testing
⌂ Main Page
Deep Learning and Machine Learning

A/B Testing

Experiment design, hypothesis testing, and pitfalls.

On this page

A/B Testing

Simplest randomized controlled experiment. Comparing samples A and B that are similar except for one variation (two versions of webpage / product) – which one has a greater impact on business metrics?

Create Control Group (no change, H0) and Test Group (modified product, Ha). Avoid selection bias (random sampling), under-coverage bias (sample size).

  1. Hypothesis Testing

  1. Null hypothesis, H0: no difference between the control and test groups.

  2. Alternative Hypothesis, Ha: educated guess to be verified.

    1. 3. Conduct A/B Test

4, Statistical significance

  1. Type I error: rejecting H0 when it is true (“You are pregnant” to a man)

  1. Type II error: not rejecting H0 when it is false (“You are not pregnant” to pregn. woman)

A diagram of a statistical distribution Description automatically generated
  1. Significance level (α) = 0.05 = probability of Type I error

  2. P-Value = smallest significance when H0 is rejected. Smaller p-value - stronger evidence for Ha.
    If p-value < significance level 0.05, reject H0.

  3. Confidence interval = u r 95% confident that the result is accurate - We reject H0 at 95% confidence interval.

To avoid ‘ errors – we have 2 samples => determine statistical significance using two-sample t-test.

One-sample t test: compare mean of one sample w/hypothesized population mean.

Two-sample t test: compare means of two samples.

Independent Samples t-test: compare means of two independent groups.

Paired Sample t-test: compare separate means for one group at two different times.

t-statistic = how much sample’s data diverges from H0.

xˉ - sample mean, μ - population mean under H0,

s - sample’s st_dev, n = sample size.

Denominator = also known as standard error.

one-sample test

two-sample test

A mathematical equation with black letters AI-generated content may be incorrect.two-sample t-test

p-value - proba of obtaining test statistic at least as extreme as observed, assuming H0 is true

First, t-statistic is computed from the sample data, then p-value is derived from t-statistic using the t-distribution (similar to normal distribution, but with heavier tails - more prone to producing values). Interpretation: larger absolute t-statistic = greater deviation from H0 and smaller p-value = stronger evidence against H0.

Python:

import scipy.stats as ss

t_stat, p_val= ss.ttest_ind(data_B, data_A)

print(t_stat, p_val)

# 1.55, 0.02 => reject H0

What Mistakes Should we Avoid While Conducting A/B Testing?

There are a few key mistakes I’ve seen data science professionals making. Let me clarify them for you here:

When Should We Use A/B Testing?

A/B testing works best when testing incremental changes (UX changes, new features, ranking, and page load times - compare pre and post-modification results).

A/B testing doesn’t work well when testing major changes, like new products, new branding, or completely new user experiences. In these cases, there may be effects that drive higher than normal engagement or emotional responses that may cause users to behave in a different manner.

More here: