결과 해석과 모델 비교

Python으로 배우는 Bayesian 데이터 분석

Michal Oleszak

Machine Learning Engineer

모델 실행 복습

formula = "num_clicks ~ clothes_banners_shown + sneakers_banners_shown"

with pm.Model() as model_1:
    pm.GLM.from_formula(formula, data=ads_aggregated)
    trace_1 = pm.sample(draws=1000, tune=500)
Python으로 배우는 Bayesian 데이터 분석

모델 실행 복습

formula = "num_clicks ~ clothes_banners_shown + sneakers_banners_shown"

with pm.Model() as model_1:
    pm.GLM.from_formula(formula, data=ads_aggregated)
    trace_1 = pm.sample(draws=1000, tune=500, chains=4)
  • 매개변수 수: 4
  • 각 매개변수의 드로 수: 1000 $\times$ 4 = 4000
Python으로 배우는 Bayesian 데이터 분석

트레이스 플롯

pm.traceplot(trace_1)

두 열 네 행의 8개 플롯 그리드. 왼쪽 열은 밀도 플롯 4개, 오른쪽 열은 각 매개변수별 선 플롯 4개.

Python으로 배우는 Bayesian 데이터 분석

트레이스 플롯: 한 매개변수 확대

 

나란한 두 플롯: 왼쪽은 밀도 플롯, 오른쪽은 매개변수 드로의 선 플롯.

Python으로 배우는 Bayesian 데이터 분석

포리스트 플롯

pm.forestplot(trace_1)

각 매개변수의 드로 분포를 가로 막대로 나타낸 플롯.

Python으로 배우는 Bayesian 데이터 분석

트레이스 요약

pm.summary(trace_1)
                         mean     sd  hdi_3%  hdi_97%  mcse_mean  mcse_sd  \
Intercept               1.307  0.886  -0.305    2.962      0.018    0.013   
clothes_banners_shown   0.103  0.031   0.043    0.160      0.001    0.000   
sneakers_banners_shown  0.104  0.032   0.045    0.163      0.001    0.001   
sd                      2.654  0.157   2.382    2.970      0.003    0.002   

                        ess_mean  ess_sd  ess_bulk  ess_tail  r_hat  
Intercept                 2346.0  2318.0    2351.0    2083.0    1.0  
clothes_banners_shown     2085.0  2085.0    2089.0    1868.0    1.0  
sneakers_banners_shown    2105.0  1953.0    2122.0    1869.0    1.0  
sd                        2615.0  2590.0    2646.0    1834.0    1.0
Python으로 배우는 Bayesian 데이터 분석

다른 모델 적합

formula = "num_clicks ~ clothes_banners_shown + sneakers_banners_shown + weekend"

with pm.Model() as model_2:
    pm.GLM.from_formula(formula, data=ads_aggregated)
    trace_2 = pm.sample(draws=1000, tune=500)
Python으로 배우는 Bayesian 데이터 분석

WAIC (넓게 적용 가능한 정보 기준)

comparison = pm.compare({"trace_1": trace_1, "trace_2": trace_2}, 
                        ic="waic", scale="deviance")
print(comparison)
        rank     waic   p_waic    d_waic    weight       se      dse warning  \
trace_2    0   -362.8   5.1576         0  0.513792  9.37269        0    True   
trace_1    1 -362.926  4.13318  0.126236  0.486208  9.48352  1.50682    True   

        waic_scale  
trace_2        log  
trace_1        log
Python으로 배우는 Bayesian 데이터 분석

비교 플롯

pm.compareplot(comparison)

두 모델의 WAIC 값을 시각화한 플롯.

Python으로 배우는 Bayesian 데이터 분석

모델 비교를 연습해 봅시다!

Python으로 배우는 Bayesian 데이터 분석

Preparing Video For Download...