類別機率與預測

使用 R 的 caret 進行 Machine Learning

Zach Mayer

Data Scientist at DataRobot and co-author of caret

不同閾值

  • 不侷限於 50% 閾值
    • 設 10% 可抓到更多地雷,但把握度較低
    • 設 90% 可抓到較少地雷,但把握度較高
  • 權衡靈敏度與誤報率
  • 成本效益分析
使用 R 的 caret 進行 Machine Learning

混淆矩陣

# Use a larger cutoff
p_class <- ifelse(p > 0.99, "M", "R")
table(p_class)
p_class
 M  R 
41 42 
# Make simple 2-way frequency table
table(p_class, test[["Class"]])
p_class  M  R
      M 13 28
      R 30 12
使用 R 的 caret 進行 Machine Learning

使用 caret 的混淆矩陣

# Use caret to produce confusion matrix
confusionMatrix(p_class, test[["Class"]])
          Reference
Prediction  M  R
         M 13 28
         R 30 12

               Accuracy : 0.3012          
                 95% CI : (0.2053, 0.4118)
    No Information Rate : 0.5181          
    P-Value [Acc > NIR] : 1.0000          

                  Kappa : -0.397          
 Mcnemar's Test P-Value : 0.8955          

            Sensitivity : 0.3023          
            Specificity : 0.3000          
         Pos Pred Value : 0.3171          
         Neg Pred Value : 0.2857
使用 R 的 caret 進行 Machine Learning

一起來練習吧!

使用 R 的 caret 進行 Machine Learning

Preparing Video For Download...