Sanity checks: Internal validity

Python में A/B Testing

Moe Lotfy, PhD

Principal Data Science Manager

Sample Ratio Mismatch (SRM)

  • Sample Ratio Mismatch (SRM)
    • वेरिएंट्स में आवंटन डिज़ाइन से भटकता है
  • Chi-square goodness of fit test

Chi-square सूत्र

सैंपल रेशियो मिसमैच आवंटन उदाहरण

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 dataset: 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 dataset: https://www.kaggle.com/datasets/osuolaleemmanuel/ad-ab-testing
Python में A/B Testing

SRM के कारण ढूँढना

SRM के आम कारण:$^1$

  • Assignment: गलत बकेटिंग या ख़राब randomization फंक्शन्स
  • Execution: वेरिएंट का लेट स्टार्ट या धीमा ramp up
  • Data logging: लॉगिंग देरी या bot फ़िल्टरिंग
  • Interference: एक्सपेरिमेंटर द्वारा किसी वेरिएंट को pause करना
1 Diagnosing Sample Ratio Mismatch in Online Controlled Experiments: A Taxonomy and Rules of Thumb for Practitioners
Python में A/B Testing

A/A टेस्ट्स

  • A/A टेस्ट
    • दो यूज़र समूहों को एक जैसा अनुभव दिखाता है
    • एक्सपेरिमेंट सेटअप में बग्स पकड़ता है
    • मेट्रिक्स में कोई सांख्यिकीय रूप से महत्वपूर्ण अंतर नहीं होना चाहिए
    • दिए गए $\alpha$ पर false positives फिर भी हो सकते हैं (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 dataset: https://www.kaggle.com/datasets/osuolaleemmanuel/ad-ab-testing
Python में A/B Testing

अभ्यास करते हैं!

Python में A/B Testing

Preparing Video For Download...