By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
A/B testing (also called online experimentation) is a controlled, randomized comparison of two (or more) variants of a product, model, or decision rule. In a data‑science workflow it lets you measure the causal impact of a new ML model or feature on a live metric (e.g., conversion, churn, click‑through). For example, an e‑commerce site may serve a new churn‑prediction model to 10 % of users (variant B) while the existing model continues for the remaining 90 % (variant A) and then compare the resulting retention rates.
[ n = \frac{2\,\sigma^2\,(Z_{1-\alpha/2}+Z_{1-\beta})^2}{\Delta^2} ]
where σ² = variance of the metric, Δ = minimum detectable lift, Z‑scores from the normal distribution. - p‑value – Probability of observing a lift at least as extreme as the one measured, assuming the null hypothesis (no lift) is true. - Confidence Interval (CI) – Range that contains the true lift with a chosen confidence (e.g., 95 % CI = Δ̂ ± Z_{1‑α/2}·SE). - Sequential Testing / Peeking – Re‑evaluating results before the pre‑planned sample size is reached; inflates Type I error unless corrected (e.g., using O’Brien‑Fleming boundaries). - Uplift Modeling – Predictive approach that estimates the individual treatment effect (ITE) rather than the average lift; often built with two‑model or meta‑learner strategies. - A/B Test Metric Types – Binary (conversion, churn), Rate (click‑through rate), Continuous (revenue per user), Time‑to‑event (survival). Choose the appropriate statistical test (e.g., chi‑square for binary, t‑test for continuous, log‑rank for survival). - Multiple Testing Correction – When running many experiments, control the family‑wise error rate (Bonferroni) or false discovery rate (Benjamini‑Hochberg).
python # Example: increase 30‑day retention metric = 'retention_30d' # binary outcome
np.random.rand(N) < 0.1
statsmodels.stats.power.tt_ind_solve_power
python if random() < 0.1: model = new_model # B else: model = baseline # A
user_id, variant, metric, timestamp
python import pandas as pd, statsmodels.api as sm df = pd.read_sql('SELECT * FROM ab_log', con) lift = df.groupby('variant')[metric].mean().diff().iloc[-1] se = sm.stats.proportion.proportion_effectsize(...) ci = sm.stats.proportion_confint(...) p = sm.stats.proportions_ztest(...)
Mistake: Using the same users for multiple experiments (overlap). Correction: Enforce mutual exclusivity or use hierarchical randomization; overlapping users break the independence assumption and bias lift estimates.
Mistake: Stopping the test early because the p‑value looks “good”. Correction: Pre‑specify a stopping rule (e.g., O’Brien‑Fleming) or use a Bayesian monitoring approach; otherwise you inflate Type I error.
Mistake: Ignoring variance heterogeneity (treating binary and continuous metrics the same). Correction: Choose the right statistical test (chi‑square for binary, Welch’s t‑test for unequal variances, or non‑parametric bootstrap).
Mistake: Relying on a single metric while other key KPIs deteriorate. Correction: Track a dashboard of primary and secondary metrics; a “win” on one metric may be a “loss” on revenue or user experience.
Mistake: Not accounting for multiple comparisons when running many experiments in parallel. Correction: Apply Bonferroni or Benjamini‑Hochberg adjustments to keep the overall false‑positive rate under control.
statsmodels.stats.power.NormalIndPower
Scenario: Your baseline churn model yields a 5 % churn rate. The new model (treatment) shows a 4.8 % churn rate with a p‑value = 0.12. Answer: Do not roll out. The lift (0.2 %) is not statistically significant (p > 0.05) and may be due to random variation.
Scenario: You need 80 % power to detect a 2 % absolute lift in a conversion rate of 10 % with α = 0.05. Roughly how many users per variant are required? Answer: ≈ 30 k users per arm (use the two‑proportion sample‑size formula).
Scenario: After 3 days you see a p‑value of 0.03 and stop the test. Answer: Wrong. Early stopping inflates Type I error; you need a pre‑planned sequential test or adjust α for interim looks.
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.