Plot classification confusion matrix
On the confusion matrix plot, the rows correspond to the predicted
Output Class), and the columns show the
true class (
Target Class). The diagonal cells show
for how many (and what percentage) of the examples the trained network
correctly estimates the classes of observations. That is, it shows
what percentage of the true and predicted classes match. The off diagonal
cells show where the classifier has made mistakes. The column on the
far right of the plot shows the accuracy for each predicted class,
while the row at the bottom of the plot shows the accuracy for each
true class. The cell in the bottom right of the plot shows the overall
several confusion plots in one figure, and prefixes the
to the titles of the appropriate plots.
This example shows how to train a pattern recognition network and plot its accuracy.
Load the sample data.
[x,t] = cancer_dataset;
cancerInputs is a 9x699 matrix defining nine attributes of 699 biopsies.
cancerTargets is a 2x966 matrix where each column indicates a correct category with a one in either element 1 (benign) or element 2 (malignant). For more information on this dataset, type
help cancer_dataset in the command line.
Create a pattern recognition network and train it using the sample data.
net = patternnet(10); net = train(net,x,t);
Estimate the cancer status using the trained network,
y = net(x);
Plot the confusion matrix.
In this figure, the first two diagonal cells show the number and percentage of correct classifications by the trained network. For example 446 biopsies are correctly classifed as benign. This corresponds to 63.8% of all 699 biopsies. Similarly, 236 cases are correctly classified as malignant. This corresponds to 33.8% of all biopsies.
5 of the malignant biopsies are incorrectly classified as benign and this corresponds to 0.7% of all 699 biopsies in the data. Similarly, 12 of the benign biopsies are incorrectly classified as malignant and this corresponds to 1.7% of all data.
Out of 451 benign predictions, 98.9% are correct and 1.1% are wrong. Out of 248 malignant predictions, 95.2% are correct and 4.8% are wrong. Out of 458 benign cases, 97.4% are correctly predicted as benign and 2.6% are predicted as malignant. Out of 241 malignant cases, 97.9% are correctly classified as malignant and 2.1% are classified as benign.
Overall, 97.6% of the predictions are correct and 2.4% are wrong classifications.
targets— True class labels
True class labels, where N is the number of classes and M is the number of examples. Each column of the matrix must be in the 1-of-N form indicating which class that particular example belongs to. That is, in each column, a single element is 1 to indicate the correct class, and all other elements are 0.
outputs— Class estimates from a neural network that performs classification
Class estimates from a neural network that performs classification, specified as an N-by-M matrix, where N is the number of classes and M is the number of examples. Each column of the matrix can either be in the 1-of-N form indicating which class that particular example belongs to, or can contain the probabilities, where each column sums to 1.
name— Name of the confusion matrix
Name of the confusion matrix, specified as a character array.
name prefixes the confusion matrix
plot title as
name Confusion Matrix.