R Percentage Confusion Matrix

In R, how to get the Confusion matrix in percent (or fraction 1). The caret package provides a useful feature, but shows the absolute number of samples.

library(caret)
data(iris)
T <- iris$Species
P <- sample(iris$Species)
confusionMatrix(P, T)
Confusion Matrix and Statistics
             Reference
Prediction   setosa versicolor virginica
setosa         15         16        19
versicolor     19         16        15
virginica      16         18        16
+4
source share
1 answer

The carriage function is good if you need summary statistics. If all you care about is a “percentage” matrix of confusion, you can simply use prop.tableand table. In addition, for future reference, rigorous programming questions should be published on /fooobar.com / ... and not on CrossValidated.

prop.table(table(P,T))
> prop.table(table(P,T))
            T
P                setosa versicolor  virginica
  setosa     0.11333333 0.10666667 0.11333333
  versicolor 0.09333333 0.13333333 0.10666667
  virginica  0.12666667 0.09333333 0.11333333

, prop.table .

prop.table(caret::confusionMatrix(P,T)$table)
+5

All Articles