การทดสอบทางสถิติแบบไม่ใช้พารามิเตอร์

A/B Testing ด้วย Python

Moe Lotfy, PhD

Principal Data Science Manager

ข้อสมมติฐานของการทดสอบแบบพารามิเตอร์

  1. การสุ่มตัวอย่าง
    • ข้อมูลถูกสุ่มตัวอย่างจากประชากร
    • ตรวจสอบกระบวนการเก็บและสุ่มตัวอย่างข้อมูล
  2. ความเป็นอิสระ
    • แต่ละการสังเกต/จุดข้อมูลต้องเป็นอิสระต่อกัน
    • หากละเลยความสัมพันธ์ระหว่างข้อมูล จะทำให้อัตราข้อผิดพลาดสูงขึ้น
  3. การแจกแจงแบบปกติ
    • ข้อมูลมีการแจกแจงแบบปกติ
    • ขนาดตัวอย่าง "เพียงพอ"
      • Two sample t-test: n >= 30 ในแต่ละกลุ่ม
      • Two sample proportions test: >=10 ครั้งที่สำเร็จและ >=10 ครั้งที่ไม่สำเร็จในแต่ละกลุ่ม
A/B Testing ด้วย Python

Mann-Whitney U test

  • การทดสอบนัยสำคัญทางสถิติแบบไม่ใช้พารามิเตอร์
  • ตรวจสอบว่าสองกลุ่มตัวอย่างที่เป็นอิสระมีการแจกแจงพื้นฐานเดียวกันหรือไม่
  • การทดสอบผลรวมอันดับ
  • ข้อมูลที่ไม่จับคู่
A/B Testing ด้วย Python

Mann-Whitney U test ใน Python

# Calculate the mean and count of time on page by variant
print(checkout.groupby('checkout_page')['time_on_page'].agg({'mean', 'count'}))
                    mean  count
checkout_page                  
A              44.668527   3000
B              42.723772   3000
C              42.223772   3000
# Set random seed for repeatability 
np.random.seed(40)
# Take a random sample of size 25 from each variant
ToP_samp_A = checkout[checkout['checkout_page'] == 'A'].sample(25)['time_on_page']
ToP_samp_B = checkout[checkout['checkout_page'] == 'B'].sample(25)['time_on_page']
A/B Testing ด้วย Python

Mann-Whitney U test ใน Python

# Run a Mann-Whitney U test
mwu_test = pingouin.mwu(x=ToP_samp_A,
                        y=ToP_samp_B,
                        alternative='two-sided')
# Print the test results
print(mwu_test)
     U-val alternative     p-val     RBC    CLES
MWU  441.0   two-sided  0.013007 -0.4112  0.7056
A/B Testing ด้วย Python

Chi-square test of independence

  • ไม่ขึ้นอยู่กับข้อสมมติฐานของการทดสอบแบบพารามิเตอร์
  • ทดสอบว่าตัวแปรเชิงกลุ่มตั้งแต่สองตัวขึ้นไปเป็นอิสระต่อกันหรือไม่
    • สมมติฐานหลัก: ตัวแปรเป็นอิสระต่อกัน
    • สมมติฐานทางเลือก: ตัวแปรไม่เป็นอิสระต่อกัน
A/B Testing ด้วย Python

Chi-square test ใน Python

A/B test อัตราการสมัครบนหน้าแรก

สมมติฐานหลัก: ไม่มีความแตกต่างอย่างมีนัยสำคัญในอัตราการสมัครระหว่างหน้า Landing Page C และ D

สมมติฐานทางเลือก: มีความแตกต่างอย่างมีนัยสำคัญในอัตราการสมัครระหว่างทั้งสอง

# Calculate the number of users in groups C and D
n_C = homepage[homepage['landing_page'] == 'C']['user_id'].nunique()
n_D = homepage[homepage['landing_page'] == 'D']['user_id'].nunique()
# Compute unique signups in each group
signup_C = homepage[homepage['landing_page'] == 'C'].groupby('user_id')['signup'].max().sum()
no_signup_C = n_C - signup_C
signup_D = homepage[homepage['landing_page'] == 'D'].groupby('user_id')['signup'].max().sum()
no_signup_D = n_D - signup_D
A/B Testing ด้วย Python

Chi-square test ใน Python

# Create the signups table
table = [[signup_C, no_signup_C], [signup_D, no_signup_D]]
print('Group C signup rate:',round(signup_C/n_C,3))
print('Group D signup rate:',round(signup_D/n_D,3))

# Calculate p-value
print('p-value=',stats.chi2_contingency(table,correction=False)[1])
Group C signup rate: 0.064
Group D signup rate: 0.048
p-value= 0.009165
A/B Testing ด้วย Python

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

A/B Testing ด้วย Python

Preparing Video For Download...