簡體   English   中英

如何在“ caret-xgbDART”的保留樣本中生成混淆矩陣?

[英]How to Generate Confusion Matrix on HOLD OUT sample in “caret-xgbDART”?

我正在使用“ xgbDART”方法來訓練caret可用的模型。 采樣方法是“ repeatedcv”。

是否可以生成內部保持樣本的混淆矩陣? 我認為打印最終模型就像在“ rf”算法中那樣會生成它,但是不會。 任何建議都會有所幫助。

要在插入符號訓練后獲得混淆矩陣,只需在生成的訓練object上調用caret::confusionMatrix 這是有關Sonar數據的示例:

library(mlbench)
library(caret)
library(xgboost)
data(Sonar)
ctrl <- trainControl(method = "repeatedcv", 
                     number = 2,
                     repeats = 2)


grid <- expand.grid(max_depth = 5,
                    nrounds = 500,
                    eta =  .01,
                    colsample_bytree = 0.7,
                    gamma = 0.1,
                    min_child_weight = 1,
                    subsample = .6,
                    rate_drop = c(.1, .3),
                    skip_drop = c(.1, .3))


fit.dart <- train(Class ~ .,
                  data =  Sonar, 
                  method = "xgbDART", 
                  metric = "Accuracy",
                  trControl = ctrl, 
                  tuneGrid = grid)

confusionMatrix(fit.dart)
#output
Cross-Validated (2 fold, repeated 2 times) Confusion Matrix 

(entries are percentual average cell counts across resamples)

          Reference
Prediction    M    R
         M 44.5 13.7
         R  8.9 32.9

 Accuracy (average) : 0.774

為了創建一個定制的混淆矩陣(例如使用自定義的閾值和不跨越重新采樣一個可以設置平均classProbs = TRUEsavePredictions = TRUEtrainControl

現在,例如,對合並的保留數據使用截斷閾值0.3可以做到:

confusionMatrix(fit.dart$pred$obs,
                factor(ifelse(fit.dart$pred$R > 0.3, "R", "M"), levels = c("M", "R")))
#output
Confusion Matrix and Statistics

          Reference
Prediction   M   R
         M 106 116
         R   8 186

               Accuracy : 0.7019          
                 95% CI : (0.6554, 0.7455)
    No Information Rate : 0.726           
    P-Value [Acc > NIR] : 0.8753          

                  Kappa : 0.4214          
 Mcnemar's Test P-Value : <2e-16          

            Sensitivity : 0.9298          
            Specificity : 0.6159          
         Pos Pred Value : 0.4775          
         Neg Pred Value : 0.9588          
             Prevalence : 0.2740          
         Detection Rate : 0.2548          
   Detection Prevalence : 0.5337          
      Balanced Accuracy : 0.7729          

       'Positive' Class : M   

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM