본문 바로가기
카테고리 없음

A/B Test 실전

by Mojito 2021. 8. 24.

 

Columns Description

  • auction_id: the unique id of the online user who has been presented the BIO. In standard terminologies this is called an impression id. The user may see the BIO questionnaire but choose not to respond. In that case both the yes and no columns are zero.
  • experiment: which group the user belongs to - control or exposed.
    • control: users who have been shown a dummy ad
    • exposed: users who have been shown a creative, an online interactive ad, with the SmartAd brand.
  • date: the date in YYYY-MM-DD format
  • hour: the hour of the day in HH format.
  • device_make: the name of the type of device the user has e.g. Samsung
  • platform_os: the id of the OS the user has.
  • browser: the name of the browser the user uses to see the BIO questionnaire.
  • yes: 1 if the user chooses the “Yes” radio button for the BIO questionnaire.
  • no: 1 if the user chooses the “No” radio button for the BIO questionnaire.

 

A/B testing 을 실전에 적용시키기 위해, 데이터를 찾아보았다. 아래 데이터는 Biotechnology Innovation Organization 에서 수집한 데이터이다.

AdSmartABdata - AdSmartABdata.csv
0.76MB

간략히 데이터를 설명하자면, control 과 exposed (test) 그룹으로 나눈 후, 설문조사(?)를 진행했을경우 응답을 했을 경우 Yes = 1 응답을 안했을경우 No = 1, 응답을 하지도 않고 안하겠다고 의사를 밝히지도 않고 창을 종료한경우 Yes=0 No=0에 표시가 된다. 나머지 column 들은 봣을경우 어려운게 없어서 넘어가겠다.

 

테스트 이전에 먼저 필요한 라이브러리를 import 해준다.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

from statsmodels.stats.proportion import proportions_ztest

데이터를 import  한 후 필요한 데이터만 추출해 주겠다.

우리는 experiment 와 yes/no 만 필요하므로 해당 column 들만 할당해주면된다.

그전에 위 데이터에는 yes/no 둘다 0인 응답을 안한 상태도 있으므로, A/B 테스트를 위해 응답한 경우만 이용해서 측정해야하므로 아래와 같은 순서로 해준다.

1. yes/no 둘다 0인 경우는 dataframe 에서 제거

2. yes/no 새로운 column 에 합쳐주기 (0 = no / 1 = yes)

 

responded = df[~((df['yes'] == 0) & (df['no'] == 0))] #1. 응답안한경우 제외
responded.loc[responded.yes == 0, 'success'] = int(0)
responded.loc[responded.yes == 1, 'success'] = int(1) #2. 0 = no / 1 = yes

responded = responded.drop(['yes','no'], axis = 1)    ## yes/no drop
responded.head()

barchart 로 데이터 보기

X = ['Exposed','Control']
e0=(len(responded[(responded['experiment'] == 'exposed') & (responded['success'] == 0)]))
e1=(len(responded[(responded['experiment'] == 'exposed') & (responded['success'] == 1)]))
c0=(len(responded[(responded['experiment'] == 'control') & (responded['success'] == 0)]))
c1=(len(responded[(responded['experiment'] == 'control') & (responded['success'] == 1)]))

a = [e0, c0]
b = [e1, c1]
  
X_axis = np.arange(len(X))
  
plt.bar(X_axis - 0.2, a, 0.4, label = '0')
plt.bar(X_axis + 0.2, b, 0.4, label = '1')
  
plt.xticks(X_axis, X)
plt.xlabel("Groups")
plt.ylabel("Number of Success")
plt.legend()
plt.show()

위 bar chart 를 보게되면 test 그룹의 응답율과 거절율이 조금씩 더 높은것을 볼수있다. 그럼 A/B Test 를 이용해서 test 결과가 유의미한건지 알아보겠다.

 

 

df_control = responded[responded['experiment'] == 'control']
df_exposed = responded[responded['experiment'] == 'exposed']

ad_succes_count = [df_control.success.sum(), df_exposed.success.sum()]
obs_count = [df_control.Ad.count(), df_exposed.Ad.count()]

z_stat, pval = proportions_ztest(ad_succes_count, nobs=obs_count)

print("z_stat: {} \nP-value: {}".format(z_stat, pval))

[결론]

null hypothesis (  H0: There is no difference between the control and variant group ) 을 reject 하기 위에서는 p-value 가 알파값인 0.05 보다 작아야 하지만 우리가 검사한 결과의 모델의 p-value 는 0.518로 훨신 높다. 그리하여 우리는 null hypothesis 를 reject 할 수 없고, test 그룹의 결과는 유의미하지 않다고 결론내릴수있다. 즉, control과 test 의 바뀐광고는 큰 효율을 못내고있고 있다. 

 

 

 

 

 

 

 

데이터출저: https://www.kaggle.com/osuolaleemmanuel/ad-ab-testing

 

Ad A/B Testing

A Dataset containing an A/B test done by an Advertising agency

www.kaggle.com

 

반응형

댓글