混淆矩陣
當應變數只有兩種結果時(例如是否流失),衡量模型成效的關鍵在於:「模型正確預測了多少真的流失的個案?」以及「模型正確預測了多少未流失的個案?」。你可以透過建立混淆矩陣並在其上計算摘要指標來取得這些資訊。鑲嵌圖(mosaic plot)是視覺化結果的自然方式。
churn 與 mdl_churn_vs_both_inter 已可使用;dplyr 與 yardstick 已載入。
本練習屬於課程
R 的迴歸分析中級
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Get the actual responses from churn
actual_response <- ___
# Get the predicted responses from the model
predicted_response <- ___
# Get a table of these values
outcomes <- ___
# Convert the table to a conf_mat object
confusion <- ___
# See the result
confusion