표본 내 모델 적합도와 임계값 설정

R로 배우는 Machine Learning 기반 마케팅 분석

Verena Pflieger

Data Scientist at INWT Statistics

유사 $R^2$ 통계량 I

$$ \text{McFadden:~} \quad R^2 =1-\frac{lnL_{\text{full}}}{lnL_{\text{null}}} $$

$$ \text{Cox \& Snell:~} R^2 = 1-\left(\frac{L_{\text{null}}}{L_{\text{full}}}\right)^{\frac{2}{n}} $$

$$ \text{Nagelkerke:~} R^2 = \frac{1-\left(\frac{L_{\text{null}}}{L_{\text{full}}}\right)^{\frac{2}{n}}}{1-(L_{\text{null}})^{\frac{2}{n}}} $$

해석:

  • 0.2이면 적절

  • 0.4이면 양호

  • 0.5이면 매우 양호

R로 배우는 Machine Learning 기반 마케팅 분석

유사 $R^2$ 통계량 II

library(descr)

LogRegR2(logitModelNew)
Chi2                     1321.717
Df                       19
Sig.                     0
Cox and Snell Index      0.02879553
Nagelkerke Index         0.0469131
McFadden's R2            0.03071032
R로 배우는 Machine Learning 기반 마케팅 분석

확률 예측

churnData$predNew <- predict(logitModelNew, 
                             type = "response", 
                              na.action = na.exclude)
data %>% select(returnCustomer, predNew) %>% tail()      
      returnCustomer   predNew
45231              0 0.2843944
45232              0 0.1552756
45233              1 0.2522597
45234              1 0.1454276
45235              0 0.2698819
45236              0 0.2886988
R로 배우는 Machine Learning 기반 마케팅 분석

혼동 행렬

library(SDMTools)
# Note that `SDMTools` cannot be downloaded from CRAN anymore. 
# Install it instead via `remotes::install_version("SDMTools", "1.1-221.2")`
confMatrixNew <- confusion.matrix(churnData$returnCustomer, 
                    churnData$predNew, threshold = 0.5)
confMatrixNew
     obs
pred 0     1
   0 36921 8242
   1 43    30
예측 \ 실제 음성 양성
음성 진음성 위음성
양성 위양성 진양성
R로 배우는 Machine Learning 기반 마케팅 분석

정확도

accuracyNew <- sum(diag(confMatrixNew)) / sum(confMatrixNew)
accuracyNew
0.8168494
R로 배우는 Machine Learning 기반 마케팅 분석

최적 임계값 찾기

예측 \ 실제 returnCustomer = 0 returnCustomer = 1
returnCustomer = 0 5 -15
returnCustomer = 1 0 0

payoff = 5 * 진음성 - 15 * 위음성

임계값 정확도 수익
0.5 0.817 60975
0.4 0.815 62180
[0.3] [0.794] [65740]
0.2 0.668 65670
0.1 0.241 10550
R로 배우는 Machine Learning 기반 마케팅 분석

과적합

R로 배우는 Machine Learning 기반 마케팅 분석

직접 실습해 보세요!

R로 배우는 Machine Learning 기반 마케팅 분석

Preparing Video For Download...