In R how to get Confusion Matrix in percent (or fraction of 1). The "caret" package provides useful function but shows 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
The caret function is nice if you want all the summary statistics. If all you care about is the 'percentage' confusion matrix, you can just use
prop.table
andtable
. Also, for future reference, strictly programming questions should be posted to stackoverflow not CrossValidated.If you would like to keep the summary statistics from caret, just you prop.table on the confusion matrix object.