驗證羅吉斯回歸結果

HR 分析:以 R 預測員工流失

Anurag Gupta

People Analytics Practitioner

測試案例的離職機率分布

HR 分析:以 R 預測員工流失

用臨界值將機率轉成類別

HR 分析:以 R 預測員工流失

用臨界值將機率轉成類別

# Classify predictions using a cut-off of 0.5
pred_cutoff_50_test <- ifelse(predictions_test > 0.5, 1, 0)
HR 分析:以 R 預測員工流失

什麼是混淆矩陣?

混淆矩陣用來衡量分類模型的表現。

HR 分析:以 R 預測員工流失

建立混淆矩陣

## Creating confusion matrix
table(pred_cutoff_50_test, test_set$turnover)
prediction_categories   0   1
                    0 450  22
                    1  20  94
HR 分析:以 R 預測員工流失

理解混淆矩陣

  • 真負(TN):模型正確辨識在職員工
  • 真正(TP):模型正確辨識離職員工
  • 偽正(FP):模型預測為離職,但實際在職
  • 偽負(FN):模型預測為在職,但實際離職
HR 分析:以 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 分析:以 R 預測員工流失

建立混淆矩陣

# Load library
library(caret)

# Construct a confusion matrix
conf_matrix_50 <- confusionMatrix(table(test_set$turnover, 
                                        pred_cutoff_50_test))
HR 分析:以 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 分析:以 R 預測員工流失

進階方法資源

HR 分析:以 R 預測員工流失

一起來練習吧!

HR 分析:以 R 預測員工流失

Preparing Video For Download...