비모수 통계 검정

Python으로 배우는 A/B Testing

Moe Lotfy, PhD

Principal Data Science Manager

모수 검정의 가정

  1. 무작위 표본추출
    • 모집단에서 무작위로 추출된 데이터
    • 수집/표본추출 과정을 점검
  2. 독립성
    • 각 관측값은 서로 독립적
    • 종속성 미반영 시 오류율 증가
  3. 정규성
    • 데이터가 정규분포 가정 충족
    • 표본 크기가 충분히 큼
      • 두 표본 t-검정: 각 집단 n >= 30
      • 두 비율 검정: 각 집단에서 성공 ≥10, 실패 ≥10
Python으로 배우는 A/B Testing

만–휘트니 U 검정

  • 통계적 유의성을 위한 비모수 검정
  • 두 독립 표본이 동일한 모분포를 갖는지 판단
  • 순위합 검정
  • 비대응(독립) 자료
Python으로 배우는 A/B Testing

파이썬에서의 만–휘트니 U 검정

# 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']
Python으로 배우는 A/B Testing

파이썬에서의 만–휘트니 U 검정

# 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
Python으로 배우는 A/B Testing

카이제곱 독립성 검정

  • 모수 가정에 자유로움
  • 두 개 이상의 범주형 변수의 독립성 검정
    • 귀무가설: 변수들은 독립적임
    • 대립가설: 변수들은 독립적이지 않음
Python으로 배우는 A/B Testing

파이썬에서의 카이제곱 검정

홈페이지 가입률 A/B 테스트

귀무가설: 랜딩 페이지 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
Python으로 배우는 A/B Testing

파이썬에서의 카이제곱 검정

# 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
Python으로 배우는 A/B Testing

연습해 봅시다!

Python으로 배우는 A/B Testing

Preparing Video For Download...