To plot a confusion matrix in MATLAB, you need first to generate the confusion matrix. The confusion matrix is a matrix that represents the performance of a classification algorithm. It tells you how many observations were classified correctly and incorrectly.
Once you have the confusion matrix, you can use the MATLAB function confusionchart
to plot the matrix. Here is an example code that generates a confusion matrix and plots it using the confusionchart function:
main.m237 chars9 lines
This will produce a plot of the confusion matrix that looks like this:
Note that the actual
and predicted
vectors used to generate the confusion matrix in this example represent three classes (labeled 1,2, and 3), but you can use this code with any number of classes.
gistlibby LogSnag