Editor

Run an A/B Test with a T-Test

Advanced · Write the code · from SciPy Statistics: Distributions, Hypothesis Tests, and Correlations

From the lesson: SciPy Statistics: Distributions, Hypothesis Tests, and Correlations

A pharmaceutical company develops a new headache medicine. They give it to 100 patients and a placebo to another 100. The treatment group reports slightly fewer headaches. But is that difference real, or just random chance? This is the question statistics answers.

Read the lesson

You ran an A/B test on email subject lines. Group A (old subject) and Group B (new subject) have different open rates. Run an independent samples t-test using stats.ttest_ind(). Print the t-statistic rounded to 2 decimal places, the p-value rounded to 4 decimal places, and whether the result is 'Significant' or 'Not significant' at alpha=0.05.

import numpy as np
from scipy import stats
np.random.seed(123)
group_a = np.random.normal(loc=22, scale=5, size=50) # Old subject
group_b = np.random.normal(loc=25, scale=5, size=50) # New subject
# Run t-test
# Print t-statistic (2 decimals)
# Print p-value (4 decimals)
# Print Significant or Not significant

More SciPy Statistics exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz