Rで学ぶ中級回帰分析
Richie Cotton
Data Evangelist at DataCamp
| 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 | 関係の長さ | 直近の活動 |
glm(response ~ explanatory, data = dataset, family = binomial)
glm(response ~ explanatory1 + explanatory2, data = dataset, family = binomial)
glm(response ~ explanatory1 * explanatory2, data = dataset, family = binomial)
explanatory_data <- expand_grid(
explanatory1 = some_values,
explanatory2 = some_values
)
prediction_data <- explanatory_data %>%
mutate(
has_churned = predict(mdl, explanatory_data, type = "response")
)
| 実際: 偽 | 実際: 真 | |
|---|---|---|
| 予測: 偽 | 正解 | 偽陰性 |
| 予測: 真 | 偽陽性 | 正解 |
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")
0.5未満を一色、0.5以上を別の色に。scale_color_gradient2(midpoint = 0.5)
Rで学ぶ中級回帰分析