重回帰ロジスティック回帰

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 関係の長さ 直近の活動
1 https://www.rdocumentation.org/packages/bayesQR/topics/Churn
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)
Rで学ぶ中級回帰分析

予測の流れ

explanatory_data <- expand_grid(
  explanatory1 = some_values,
  explanatory2 = some_values
)
prediction_data <- explanatory_data %>% 
  mutate(
    has_churned = predict(mdl, explanatory_data, type = "response")
  )
Rで学ぶ中級回帰分析

4つの結果

実際: 偽 実際: 真
予測: 偽 正解 偽陰性
予測: 真 偽陽性 正解
1 https://campus.datacamp.com/courses/introduction-to-regression-in-r/simple-logistic-regression?ex=10
Rで学ぶ中級回帰分析

混同行列

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")
Rで学ぶ中級回帰分析

可視化

  • カテゴリ変数にはファセットを使用。
  • 数値説明変数が2つのときは、応答を色で示す。
  • 0.5未満を一色、0.5以上を別の色に。
scale_color_gradient2(midpoint = 0.5)
Rで学ぶ中級回帰分析

Passons à la pratique !

Rで学ぶ中級回帰分析

Preparing Video For Download...