Conversion functions for class confusionMatrix

# S3 method for confusionMatrix
as.matrix(x, what = "xtabs", ...)

Arguments

x

an object of class confusionMatrix

what

data to convert to matrix. Either "xtabs", "overall" or "classes"

...

not currently used

Value

A matrix or table

Details

For as.table, the cross-tabulations are saved. For as.matrix, the three object types are saved in matrix format.

Examples

################### ## 2 class example 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) results <- confusionMatrix(xtab) as.table(results)
#> truth #> pred abnormal normal #> abnormal 231 32 #> normal 27 54
as.matrix(results)
#> abnormal normal #> abnormal 231 32 #> normal 27 54
as.matrix(results, what = "overall")
#> [,1] #> Accuracy 0.8284883721 #> Kappa 0.5335968379 #> AccuracyLower 0.7844134380 #> AccuracyUpper 0.8667985207 #> AccuracyNull 0.7500000000 #> AccuracyPValue 0.0003096983 #> McnemarPValue 0.6025370061
as.matrix(results, what = "classes")
#> [,1] #> Sensitivity 0.8953488 #> Specificity 0.6279070 #> Pos Pred Value 0.8783270 #> Neg Pred Value 0.6666667 #> Precision 0.8783270 #> Recall 0.8953488 #> F1 0.8867562 #> Prevalence 0.7500000 #> Detection Rate 0.6715116 #> Detection Prevalence 0.7645349 #> Balanced Accuracy 0.7616279
################### ## 3 class example xtab <- confusionMatrix(iris$Species, sample(iris$Species)) as.matrix(xtab)
#> setosa versicolor virginica #> setosa 17 16 17 #> versicolor 16 18 16 #> virginica 17 16 17