Přesnost modelu na trénovacích datech a prahování

Machine Learning for Marketing Analytics in R

Verena Pflieger

Data Scientist at INWT Statistics

Pseudo $R^2$ statistiky 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}}} $$

Interpretace:

  • Přijatelné, pokud > 0,2

  • Dobré, pokud > 0,4

  • Velmi dobré, pokud > 0,5

Machine Learning for Marketing Analytics in R

Pseudo $R^2$ statistiky 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
Machine Learning for Marketing Analytics in R

Předpověď pravděpodobností

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
Machine Learning for Marketing Analytics in R

Matice záměn

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
Predikce \ Skutečnost negativní pozitivní
negativní skutečně negativní falešně negativní
pozitivní falešně pozitivní skutečně pozitivní
Machine Learning for Marketing Analytics in R

Přesnost

accuracyNew <- sum(diag(confMatrixNew)) / sum(confMatrixNew)
accuracyNew
0.8168494
Machine Learning for Marketing Analytics in R

Nalezení optimálního prahu

Predikce \ Skutečnost returnCustomer = 0 returnCustomer = 1
returnCustomer = 0 5 -15
returnCustomer = 1 0 0

výnos = 5 * skutečně negativní - 15 * falešně negativní

Práh Přesnost Výnos
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
Machine Learning for Marketing Analytics in R

Přeučení

Machine Learning for Marketing Analytics in R

Vyzkoušejte si to!

Machine Learning for Marketing Analytics in R

Preparing Video For Download...