로지스틱 회귀 적합도 정량화

R로 시작하는 회귀 분석

Richie Cotton

Data Evangelist at DataCamp

네 가지 결과

실제 음성 실제 양성
예측 음성 정확 거짓 음성
예측 양성 거짓 양성 정확
R로 시작하는 회귀 분석

혼동 행렬: 결과 개수

mdl_recency <- glm(has_churned ~ time_since_last_purchase, data = churn, family = "binomial")
actual_response <- churn$has_churned
predicted_response <- round(fitted(mdl_recency))
outcomes <- table(predicted_response, actual_response)
                  actual_response
predicted_response   0   1
                 0 141 111
                 1  59  89
R로 시작하는 회귀 분석

혼동 행렬 시각화: 모자이크 플롯

library(ggplot2)
library(yardstick)
confusion <- conf_mat(outcomes)
                  actual_response
predicted_response   0   1
                 0 141 111
                 1  59  89
autoplot(confusion)

이탈 대 최근성 모델 결과의 모자이크 플롯. 실제 이탈과 비이탈이 각각 200개여서 각 열의 너비가 같습니다.

R로 시작하는 회귀 분석

성능 지표

summary(confusion, event_level = "second")
# A tibble: 13 x 3
   .metric              .estimator .estimate
   <chr>                <chr>          <dbl>
 1 accuracy             binary         0.575
 2 kap                  binary         0.150
 3 sens                 binary         0.445
 4 spec                 binary         0.705
 5 ppv                  binary         0.601
 6 npv                  binary         0.560
 7 mcc                  binary         0.155
 8 j_index              binary         0.150
 9 bal_accuracy         binary         0.575
10 detection_prevalence binary         0.37 
11 precision            binary         0.601
12 recall               binary         0.445
13 f_meas               binary         0.511
R로 시작하는 회귀 분석

정확도 (Accuracy)

summary(confusion) %>% 
  slice(1)
# A tibble: 3 x 3
  .metric  .estimator .estimate
  <chr>    <chr>          <dbl>
1 accuracy binary         0.575

정확도는 올바른 예측의 비율입니다.

$$ accuracy = \frac{TN + TP}{TN + FN + FP + TP} $$

confusion
                  actual_response
predicted_response   0   1
                 0 141 111
                 1  59  89
(141 + 89) / (141 + 111 + 59 + 89)
0.575
R로 시작하는 회귀 분석

민감도 (Sensitivity)

summary(confusion) %>% 
  slice(3)
# A tibble: 1 x 3
  .metric .estimator .estimate
  <chr>   <chr>          <dbl>
1 sens    binary         0.445

민감도는 실제 양성 중 참양성의 비율입니다.

$$ sensitivity = \frac{TP}{FN + TP} $$

confusion
                  actual_response
predicted_response   0   1
                 0 141 111
                 1  59  89
89 / (111 + 89)
0.445
R로 시작하는 회귀 분석

특이도 (Specificity)

summary(confusion) %>% 
  slice(4)
# A tibble: 1 x 3
  .metric .estimator .estimate
  <chr>   <chr>          <dbl>
1 spec    binary         0.705

특이도는 실제 음성 중 참음성의 비율입니다.

$$ specificity = \frac{TN}{TN + FP} $$

confusion
                  actual_response
predicted_response   0   1
                 0 141 111
                 1  59  89
141 / (141 + 59)
0.705
R로 시작하는 회귀 분석

Ayo berlatih!

R로 시작하는 회귀 분석

Preparing Video For Download...