confusion matrix label in matlab

To create a confusion matrix with labels in Matlab, you can use the confusionmat function. Here is an example:

main.m
actual_labels = [1, 1, 0, 1, 0, 0, 1, 0];
predicted_labels = [1, 0, 0, 1, 1, 0, 0, 1];
labels = [0, 1];

confusion_mat = confusionmat(actual_labels, predicted_labels, 'order', labels)

185 chars
7 lines

In this example, we have two classes with labels 0 and 1. The confusionmat function takes in the actual labels, predicted labels and the order of the labels. The resulting confusion matrix will have the actual labels as rows and the predicted labels as columns. You can then use the confusionchart function to visualize the confusion matrix with labels:

main.m
confusionchart(confusion_mat, labels, 'RowSummary', 'row-normalized', 'ColumnSummary', 'column-normalized')
108 chars
2 lines

This will create a confusion chart with row-normalized and column-normalized summary statistics.

gistlibby LogSnag