Caret Package - Determining Positive Results

When using Caret's machine learning package, I am amazed at Caret's default selection of Positive, i.e. The first level of the result factor in binary classification problems.

The package says that it can be installed at an alternative level. Can any body help me determine a positive result?

Thank you

+6
source share
1 answer

look at this example. Enlarge this from carriage examples with confusionMatrix.

lvs <- c("normal", "abnormal") truth <- factor(rep(lvs, times = c(86, 258)), levels = rev(lvs)) pred <- factor( c( rep(lvs, times = c(54, 32)), rep(lvs, times = c(27, 231))), levels = rev(lvs)) xtab <- table(pred, truth) str(truth) Factor w/ 2 levels "abnormal","normal": 2 2 2 2 2 2 2 2 2 2 ... 

Since abnormal is the first level, it will be a positive class by default

 confusionMatrix(xtab) Confusion Matrix and Statistics truth pred abnormal normal abnormal 231 32 normal 27 54 Accuracy : 0.8285 95% CI : (0.7844, 0.8668) No Information Rate : 0.75 P-Value [Acc > NIR] : 0.0003097 Kappa : 0.5336 Mcnemar Test P-Value : 0.6025370 Sensitivity : 0.8953 Specificity : 0.6279 Pos Pred Value : 0.8783 Neg Pred Value : 0.6667 Prevalence : 0.7500 Detection Rate : 0.6715 Detection Prevalence : 0.7645 Balanced Accuracy : 0.7616 'Positive' Class : abnormal 

To change to positive class = normal, just add this to confusionMatrix. Pay attention to the difference with the previous output, the occurrence of the difference appears with sensitivity and other calculations.

 confusionMatrix(xtab, positive = "normal") Confusion Matrix and Statistics truth pred abnormal normal abnormal 231 32 normal 27 54 Accuracy : 0.8285 95% CI : (0.7844, 0.8668) No Information Rate : 0.75 P-Value [Acc > NIR] : 0.0003097 Kappa : 0.5336 Mcnemar Test P-Value : 0.6025370 Sensitivity : 0.6279 Specificity : 0.8953 Pos Pred Value : 0.6667 Neg Pred Value : 0.8783 Prevalence : 0.2500 Detection Rate : 0.1570 Detection Prevalence : 0.2355 Balanced Accuracy : 0.7616 'Positive' Class : normal 
+12
source

All Articles