건전성 점검: 내부 타당도

Python으로 배우는 A/B Testing

Moe Lotfy, PhD

Principal Data Science Manager

표본 비율 불일치(SRM)

  • 표본 비율 불일치(SRM)
    • 변형 간 할당이 설계와 다름
  • 카이제곱 적합도 검정

카이제곱 공식

표본 비율 불일치 할당 예시

Python으로 배우는 A/B Testing

SRM Python 예시

# Calculate the unique IDs per variant
AdSmart.groupby('experiment')['auction_id'].nunique()
experiment
control    4071
exposed    4006
# Assign the unqiue counts to each variant
control_users=AdSmart[AdSmart['experiment']=='control']['auction_id'].nunique()
exposed_users=AdSmart[AdSmart['experiment']=='exposed']['auction_id'].nunique()
total_users=control_users+exposed_users
# Calculate allocation ratios per variant
control_perc = control_users / total_users
exposed_perc = exposed_users / total_users
print("Percentage of users in the Control group:",100*round(control_perc,5),"%")
print("Percentage of users in the Exposed group:",100*round(exposed_perc,5),"%")
Percentage of users in the Control group: 50.402 %
Percentage of users in the Exposed group: 49.598 %
1 Adsmart Kaggle 데이터셋: https://www.kaggle.com/datasets/osuolaleemmanuel/ad-ab-testing
Python으로 배우는 A/B Testing

SRM Python 예시

# Creat lists of observed and expected counts per variant
observed = [ control_users, exposed_users ]
expected = [ total_users/2, total_users/2 ]
# Import chisquare from scipy library
from scipy.stats import chisquare
# Run chisquare test on observed and expected lists
chi = chisquare(observed, f_exp=expected)
# Print test results and interpretation
print(chi)
if chi[1] < 0.01:
    print("SRM may be present")
else:
    print("SRM likely not present")
Power_divergenceResult(statistic=0.5230902562832735, pvalue=0.4695264353014863)
SRM likely not present
1 Adsmart Kaggle 데이터셋: https://www.kaggle.com/datasets/osuolaleemmanuel/ad-ab-testing
Python으로 배우는 A/B Testing

SRM 원인 추적

SRM의 흔한 원인:$^1$

  • 배정: 잘못된 버킷팅 또는 랜덤화 함수 오류
  • 실행: 변형 시작 지연 또는 램프업 속도 문제
  • 데이터 로깅: 로깅 지연 또는 봇 필터링
  • 간섭: 실험자가 변형을 일시 중지함
1 온라인 통제 실험에서 표본 비율 불일치 진단: 분류와 실무용 가이드라인
Python으로 배우는 A/B Testing

A/A 테스트

  • A/A 테스트
    • 두 그룹에 동일한 경험 제공
    • 실험 설정의 버그를 드러냄
    • 지표 간 유의한 차이가 없어야 함
    • 지정된 $\alpha$에서 거짓 양성은 가능(5%)
    • 그룹 간 분포 불균형을 파악(예: 브라우저, 기기 등)
Python으로 배우는 A/B Testing

분포 균형: Python 예시

  • 브라우저 분포가 균형적
  • 유효한 테스트
checkout.groupby('checkout_page')['browser'].value_counts(normalize=True)
checkout_page  browser
A              chrome     0.341333
               safari     0.332000
               firefox    0.326667
B              safari     0.352000
               firefox    0.325000
               chrome     0.323000
C              safari     0.346000
               chrome     0.330000
               firefox    0.324000
  • 브라우저 분포가 불균형
  • 무효한 테스트
 AdSmart.groupby('experiment')['browser'].value_counts(normalize=True)
experiment  browser                   
control     Chrome Mobile                 0.591992
            Facebook                      0.137804
            Samsung Internet              0.120855
            Chrome Mobile WebView         0.071727
            Mobile Safari                 0.060427
            Chrome Mobile iOS             0.008352
            Mobile Safari UI/WKWebView    0.007369
exposed     Chrome Mobile                 0.535197
            Chrome Mobile WebView         0.298802
            Samsung Internet              0.082876
            Facebook                      0.050674
            Mobile Safari                 0.022716
            Chrome Mobile iOS             0.004244
1 Adsmart Kaggle 데이터셋: https://www.kaggle.com/datasets/osuolaleemmanuel/ad-ab-testing
Python으로 배우는 A/B Testing

연습해 봅시다!

Python으로 배우는 A/B Testing

Preparing Video For Download...