라일락 꽃이 피는 날

Bootstrapping (부트스트래핑) 본문

데이터 분석/Python

Bootstrapping (부트스트래핑)

eunki 2021. 6. 3. 17:24
728x90

Bootstrapping (부트스트래핑)

# A그룹: gate_30 / B그룹: gate_40
# 각각의 A,B 그룹에 대해 bootstrapp된 means값의 리스트 생성
boot_1d = []
for i in range(1000):
    boot_mean = df.sample(frac = 1,replace = True).groupby('version')['retention_1'].mean()
    boot_1d.append(boot_mean)
    
# list를 DataFrame으로 변환
boot_1d = pd.DataFrame(boot_1d)
    
# A Kernel Density Estimate plot of the bootstrap distributions
boot_1d.plot(kind='density')

 

위의 두 분포는 A,B 그룹에 대해 1 day retention(retention_1)이 가질 수 있는 부트 스트랩 불확실성을 표현한다.

 

 

# 두 A,B 그룹간의 % 차이 평균 컬럼 추가
boot_1d['diff'] = (boot_1d.gate_30 - boot_1d.gate_40)/boot_1d.gate_40*100

# bootstrap % 차이를 시각화
ax = boot_1d['diff'].plot(kind='density')
ax.set_title('% difference in 1-day retention between the two AB-groups')

# 게이트가 레벨30에 있을 때 1-day retention이 클 확률 계산
(boot_1d['diff'] > 0).mean()  # 0.96

 

위 도표에서 가장 가능성이 높은 % 차이는 약 1%-2%이며 분포의 95%는 0%이상이므로 레벨 30의 게이트를 선호한다.

부트 스트랩 분석에 따르면 게이트가 레벨 30에있을 때 1일 유지율(retention_1)이 더 높을 가능성이 있다.

 

 

# 각각의 A,B그룹에 대해 bootstrapp된 means 값의 리스트 생성
boot_7d = []
for i in range(500):
    boot_mean = df.sample(frac=1,replace=True).groupby('version')['retention_7'].mean()
    boot_7d.append(boot_mean)
    
# list를 DataFrame으로 변환
boot_7d = pd.DataFrame(boot_7d)

# 두 A,B 그룹간의 % 차이 평균 컬럼 추가
boot_7d['diff'] = (boot_7d.gate_30 - boot_7d.gate_40)/boot_7d.gate_40*100

# bootstrap % 차이를 시각화
ax = boot_7d['diff'].plot(kind='density')
ax.set_title('% difference in 7-day retention between the two AB-groups')

# 게이트가 레벨30에 있을 때 7-day retention이 더 클 확률 계산
(boot_7d['diff'] > 0).mean()  # 1.0

 

부트 스트랩 결과는 게이트가 레벨 40에 있을 때보다 레벨 30에 있을 때 7일 retention(retention_7)이 더 높다는 것을 나타낸다.

결론은 retention을 늘리기 위해서 게이트를 레벨 30에서 레벨 40으로 이동해서는 안된다는 것이다.

728x90

'데이터 분석 > Python' 카테고리의 다른 글

Chi-Square (카이제곱 검정)  (0) 2021.06.03
T-test (T-검정)  (0) 2021.06.03
텍스트 마이닝  (0) 2021.05.27
Kmeans 군집 분류  (0) 2021.05.27
회귀분석  (0) 2021.05.27