验证逻辑回归结果

HR Analytics:用 R 预测员工流失

Anurag Gupta

People Analytics Practitioner

测试样本的离职概率分布

HR Analytics:用 R 预测员工流失

用阈值将概率转为类别

HR Analytics:用 R 预测员工流失

用阈值将概率转为类别

# Classify predictions using a cut-off of 0.5
pred_cutoff_50_test <- ifelse(predictions_test > 0.5, 1, 0)
HR Analytics:用 R 预测员工流失

什么是混淆矩阵?

混淆矩阵用于衡量分类模型的性能。

HR Analytics:用 R 预测员工流失

创建混淆矩阵

## Creating confusion matrix
table(pred_cutoff_50_test, test_set$turnover)
prediction_categories   0   1
                    0 450  22
                    1  20  94
HR Analytics:用 R 预测员工流失

理解混淆矩阵

  • 真负类(TN):模型正确识别为在职员工
  • 真正类(TP):模型正确识别为离职员工
  • 假正类(FP):模型预测为离职,但实际在职
  • 假负类(FN):模型预测为在职,但实际离职
HR Analytics:用 R 预测员工流失

混淆矩阵:准确率

$$ \text{Accuracy} = \frac{\text{ TP + TN }}{\text{ TP + TN + FP + FN }} $$

$$ \text{Accuracy} = \frac{\text{ 450 + 94 }}{\text{ 450 + 94 + 22 + 20}} $$

$$ = $$

$$ \text{0.9283} $$

HR Analytics:用 R 预测员工流失

创建混淆矩阵

# Load library
library(caret)

# Construct a confusion matrix
conf_matrix_50 <- confusionMatrix(table(test_set$turnover, 
                                        pred_cutoff_50_test))
HR Analytics:用 R 预测员工流失
conf_matrix_50
Confusion Matrix and Statistics

prediction_categories   0   1
                    0 450  22
                    1  20  94

               Accuracy : 0.9283          
                 95% CI : (0.9044, 0.9479)
    No Information Rate : 0.802           
    P-Value [Acc > NIR] : <2e-16                                        
                  Kappa : 0.7728          
 Mcnemar's Test P-Value : 0.8774                                       
            Sensitivity : 0.9574          
            Specificity : 0.8103          
         Pos Pred Value : 0.9534          
         Neg Pred Value : 0.8246          
             ... 
HR Analytics:用 R 预测员工流失

进阶方法资源

HR Analytics:用 R 预测员工流失

开始练习吧!

HR Analytics:用 R 预测员工流失

Preparing Video For Download...