How to format confusionMatrix caret package

2.4k views Asked by At

Using the confusionMatrix() function from the caret package in R, how do you format your output vertically?

My current output is as follows:

$positive
[1] "spam"

$table
          Reference
Prediction  ham spam
      ham  1201   30
      spam    6  153

$overall
      Accuracy          Kappa  AccuracyLower  AccuracyUpper   AccuracyNull AccuracyPValue 
  9.741007e-01   8.800535e-01   9.643235e-01   9.817960e-01   8.683453e-01   5.647960e-44 
 McnemarPValue 
  1.264185e-04 

$byClass
         Sensitivity          Specificity       Pos Pred Value       Neg Pred Value 
           0.8360656            0.9950290            0.9622642            0.9756296 
           Precision               Recall                   F1           Prevalence 
           0.9622642            0.8360656            0.8947368            0.1316547 
      Detection Rate Detection Prevalence    Balanced Accuracy 
           0.1100719            0.1143885            0.9155473 

$mode
[1] "sens_spec"

I would like something like:

Accuracy:
95% CI
No Information Rate:
P-Value [Acc > NIR]:

Kappa:
Mcnemar's Test P-Value:

Sensitivity:
Specificity:
Pos Pred Value:
Neg Pred Value:
Prevalence:
Detection Rate:
Detection Prevalence:
Balanced Accuracy:
1

There are 1 answers

1
Derek Corcoran On BEST ANSWER

Try this:

t(confusionMatrix()$byClass)

and this:

confusionMatrix()$overall

Depending on the number of classes of you data you can rbind them or not