Hồi quy logistic bội

Hồi quy trung cấp với R

Richie Cotton

Data Evangelist at DataCamp

Tập dữ liệu rời bỏ ngân hàng

has_churned time_since_first_purchase time_since_last_purchase
0 0.3993247 -0.5158691
1 -0.4297957 0.6780654
0 3.7383122 0.4082544
0 0.6032289 -0.6990435
... ... ...
response length of relationship recency of activity
1 https://www.rdocumentation.org/packages/bayesQR/topics/Churn
Hồi quy trung cấp với R

glm()

glm(response ~ explanatory, data = dataset, family = binomial)
glm(response ~ explanatory1 + explanatory2, data = dataset, family = binomial)
glm(response ~ explanatory1 * explanatory2, data = dataset, family = binomial)
Hồi quy trung cấp với R

Quy trình dự đoán

explanatory_data <- expand_grid(
  explanatory1 = some_values,
  explanatory2 = some_values
)
prediction_data <- explanatory_data %>% 
  mutate(
    has_churned = predict(mdl, explanatory_data, type = "response")
  )
Hồi quy trung cấp với R

Bốn kết quả

thực tế sai thực tế đúng
dự đoán sai đúng âm tính giả
dự đoán đúng dương tính giả đúng
1 https://campus.datacamp.com/courses/introduction-to-regression-in-r/simple-logistic-regression?ex=10
Hồi quy trung cấp với R

Ma trận nhầm lẫn

actual_response <- dataset$response
predicted_response <- round(fitted(mdl))
outcomes <- table(predicted_response, actual_response)
confusion <- conf_mat(outcomes)
autoplot(confusion)
summary(confusion, event_level = "second")
Hồi quy trung cấp với R

Trực quan hóa

  • Dùng faceting cho biến phân loại.
  • Với 2 biến giải thích số, dùng màu cho biến phản hồi.
  • Gán một màu cho phản hồi dưới 0.5, màu khác cho trên 0.5.
scale_color_gradient2(midpoint = 0.5)
Hồi quy trung cấp với R

Ayo berlatih!

Hồi quy trung cấp với R

Preparing Video For Download...