🤖 AI/ML

A/B Testing

A/B Testing

An experiment design that compares two versions. Verifies statistical significance.

📖 Detailed Explanation

A/B testing is a methodology that runs two versions (A: Control, B: Variant) simultaneously and statistically compares which one delivers better performance. Users are randomly split into two groups, each shown a different version, and the differences in key metrics such as conversion rate, click-through rate, and revenue are measured.

The origins of A/B testing date back to the agricultural statistical experiments of R.A. Fisher in the 1920s. In the digital field, it took off in 2000 when Google tested displaying 10 vs. 30 results on a search results page. Currently, Amazon runs hundreds of A/B tests simultaneously every day, and Booking.com conducts more than 25,000 experiments per year.

The core of A/B testing is testing the null hypothesis (H0: no difference between the two versions). The p-value is calculated using a t-test or chi-square test, and a result is generally judged "statistically significant" when p < 0.05. Power is usually targeted at 80% or higher, and the minimum sample size needed to achieve this must be calculated in advance.

In practice, A/B testing is the foundation of a culture of making decisions with data instead of intuition and opinions. Deciding based on experiment results rather than the "HiPPO (Highest Paid Person's Opinion)" reduces the cost of failure, and even small improvements can accumulate into a large business impact. A Microsoft experiment in which increasing search result latency by 100ms reduced revenue by 1% shows the sensitivity of A/B testing.

💻 Code Example

import numpy as np
from scipy import stats
import math

def calculate_sample_size(baseline_rate, mde, alpha=0.05, power=0.8):
    """
    A/B 테스트에 필요한 최소 샘플 사이즈 계산

    Args:
        baseline_rate: 기존 전환율 (예: 0.10 = 10%)
        mde: 최소 탐지 효과 크기 (예: 0.02 = 2%p 상승)
        alpha: 유의수준 (기본 0.05)
        power: 검정력 (기본 0.80)
    """
    p1 = baseline_rate
    p2 = baseline_rate + mde
    pooled_p = (p1 + p2) / 2

    z_alpha = stats.norm.ppf(1 - alpha / 2)  # 양측검정
    z_beta = stats.norm.ppf(power)

    numerator = (z_alpha * math.sqrt(2 * pooled_p * (1 - pooled_p)) +
                 z_beta * math.sqrt(p1 * (1 - p1) + p2 * (1 - p2))) ** 2
    denominator = (p2 - p1) ** 2

    n_per_group = math.ceil(numerator / denominator)
    return n_per_group

def ab_test_analysis(control_conversions, control_total,
                     variant_conversions, variant_total):
    """A/B 테스트 결과 분석"""
    # 전환율 계산
    control_rate = control_conversions / control_total
    variant_rate = variant_conversions / variant_total

    # 상대적 상승률
    lift = (variant_rate - control_rate) / control_rate * 100

    # Z-검정 (2-proportion z-test)
    pooled_rate = (control_conversions + variant_conversions) / (control_total + variant_total)
    se = math.sqrt(pooled_rate * (1 - pooled_rate) * (1/control_total + 1/variant_total))
    z_score = (variant_rate - control_rate) / se
    p_value = 2 * (1 - stats.norm.cdf(abs(z_score)))  # 양측검정

    # 신뢰구간 (95%)
    se_diff = math.sqrt(control_rate*(1-control_rate)/control_total +
                        variant_rate*(1-variant_rate)/variant_total)
    ci_lower = (variant_rate - control_rate) - 1.96 * se_diff
    ci_upper = (variant_rate - control_rate) + 1.96 * se_diff

    return {
        "control_rate": f"{control_rate:.2%}",
        "variant_rate": f"{variant_rate:.2%}",
        "lift": f"{lift:+.1f}%",
        "p_value": p_value,
        "significant": p_value < 0.05,
        "confidence_interval": f"[{ci_lower:+.2%}, {ci_upper:+.2%}]"
    }

# 사용 예시: 체크아웃 버튼 색상 테스트
sample_size = calculate_sample_size(baseline_rate=0.10, mde=0.01)
print(f"필요 샘플 사이즈 (그룹당): {sample_size:,}명")

# 실제 실험 결과 분석
results = ab_test_analysis(
    control_conversions=520, control_total=5000,  # 10.4%
    variant_conversions=580, variant_total=5000   # 11.6%
)

print(f"\nControl 전환율: {results['control_rate']}")
print(f"Variant 전환율: {results['variant_rate']}")
print(f"상승률: {results['lift']}")
print(f"p-value: {results['p_value']:.4f}")
print(f"통계적 유의미: {'예' if results['significant'] else '아니오'}")
print(f"95% 신뢰구간: {results['confidence_interval']}")

🗣️ Examples of Practical Conversations

In a marketing team weekly meeting

"The landing page A/B test results are in. With the new headline, the conversion rate rose from 8.2% to 9.7%, and the p-value is 0.023, so it is statistically significant. Can we route 100% of traffic to the winning version starting next week?"

In a growth hacker interview

"In A/B testing, a Type I Error is a false positive, where you judge that there is a difference when there actually is none, and a Type II Error is a false negative, where you judge that there is no difference when there actually is one. Typically, you limit the Type I Error to 5% and keep the Type II Error at 20% or below to secure 80% power."

In a product team review

"Looking at the results now, the Variant appears to be 2% better, but the sample size is still insufficient, so the confidence interval includes 0. We need to keep the experiment running for at least one more week to collect enough data to detect an MDE of 1%."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Cautions

⚠️
Multiple Testing Problem

Testing multiple metrics at the same time increases the probability of false positives. If you test 5 metrics, the probability of a false positive rises to 23%. Choose a single primary metric or apply Bonferroni correction.

⚠️
Sample Ratio Mismatch (SRM)

If you allocated traffic 50:50 but the actual ratio is skewed to something like 48:52, it is a sign that there is a bug in the experiment infrastructure. You must run an SRM check before analyzing the results, and if there is a problem, the experiment should be discarded.

⚠️
Failure to Control External Factors

External factors such as holidays, marketing campaigns, and system outages can distort the results. Record major events during the experiment period, and if necessary, exclude data from that period or perform segment analysis.

🔗 Related Terms

📚 Learn More