format.confusion.matrix <- function(x)
{
## Purpose: Format a confusion matrix (removing zero entry for visual clarity)
## Requires package "formattable".
## Arguments:
## x: a confusion matrix (nrow = ncol, with counts in each cell)
## Return: a formated confusion matrix in html browser and in a CSV file.
## Author: Feiming Chen, Date: 17 Apr 2017, 15:45
## ________________________________________________
x1 <- as.character(as.matrix(x))
x1[x1 == "0"] <- ""
x2 <- matrix(x1, nrow(x), ncol(x), dimnames=dimnames((x)))
write.csv(x2, file="Confusion-Matrix.csv")
formattable::formattable(as.data.frame(x2))
}
if (F) { # Unit Test
x <- matrix(c(3,1,0,1,4,0,0,1,6), 3, 3, dimnames = list(c("A", "B", "C"), c("A", "B", "C")))
format.confusion.matrix(x)
}
No comments:
Post a Comment