计算混淆矩阵
混淆矩阵(有时也称为混淆表)是对具有分类响应(例如逻辑回归)模型进行性能度量的基础。它包含每种"真实响应–预测响应"组合的计数。在本例中,响应只有两种可能(流失或未流失),因此总体上有 4 种结果。
- 客户已流失,模型也预测为流失。
- 客户已流失,但模型没有预测为流失。
- 客户未流失,但模型预测为流失。
- 客户未流失,模型也预测为未流失。
churn 和 mdl_churn_vs_relationship 已可用。
本练习是课程的一部分
R 中的回归入门
练习说明
- 从数据集的
has_churned列获取真实响应。赋值给actual_response。 - 从模型获取"最可能"的预测响应。赋值给
predicted_response。 - 使用真实与预测响应向量创建计数表。赋值给
outcomes。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Get the actual responses from the dataset
actual_response <- ___
# Get the "most likely" responses from the model
predicted_response <- ___
# Create a table of counts
outcomes <- ___
# See the result
outcomes