การตรวจสอบความถูกต้อง: ความสมเหตุสมผลภายใน

A/B Testing ด้วย Python

Moe Lotfy, PhD

Principal Data Science Manager

Sample Ratio Mismatch (SRM)

  • Sample Ratio Mismatch (SRM)
    • การจัดสรรกลุ่มทดลองเบี่ยงเบนจากที่ออกแบบไว้
  • Chi-square goodness of fit test

สูตร Chi-square

ตัวอย่างการจัดสรรที่เกิด Sample Ratio Mismatch

A/B Testing ด้วย Python

ตัวอย่าง 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 dataset: https://www.kaggle.com/datasets/osuolaleemmanuel/ad-ab-testing
A/B Testing ด้วย Python

ตัวอย่าง 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 dataset: https://www.kaggle.com/datasets/osuolaleemmanuel/ad-ab-testing
A/B Testing ด้วย Python

การหาสาเหตุของ SRM

สาเหตุที่พบบ่อยของ SRM:$^1$

  • การกำหนดกลุ่ม: การแบ่ง bucket ที่ผิดพลาดหรือฟังก์ชัน randomization มีข้อบกพร่อง
  • การดำเนินการ: variant เริ่มทำงานล่าช้าหรืออัตราการ ramp up ไม่สอดคล้องกัน
  • การบันทึกข้อมูล: ความล่าช้าในการบันทึกหรือการกรอง bot
  • การรบกวน: ผู้ทดลองหยุด variant ชั่วคราว
1 Diagnosing Sample Ratio Mismatch in Online Controlled Experiments: A Taxonomy and Rules of Thumb for Practitioners
A/B Testing ด้วย Python

A/A tests

  • A/A test
    • นำเสนอประสบการณ์เดียวกันให้กับผู้ใช้ 2 กลุ่ม
    • ช่วยตรวจพบข้อผิดพลาดในการตั้งค่าการทดลอง
    • ไม่ควรพบความแตกต่างทางสถิติที่มีนัยสำคัญระหว่าง metric
    • False positive ยังคงเกิดขึ้นได้ที่ระดับ $\alpha$ ที่กำหนด (5% ของเวลา)
    • ช่วยตรวจจับความไม่สมดุลของการกระจายตัวข้ามกลุ่ม (เช่น เบราว์เซอร์ อุปกรณ์ ฯลฯ)
A/B Testing ด้วย Python

ตัวอย่างการตรวจสอบความสมดุลของการกระจายตัวด้วย 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 dataset: https://www.kaggle.com/datasets/osuolaleemmanuel/ad-ab-testing
A/B Testing ด้วย Python

มาฝึกกันเถอะ!

A/B Testing ด้วย Python

Preparing Video For Download...