How can I plot a confusion matrix for a multi-class or non-binary classification problem?
Show older comments
I want to make a plot similar to the confusion matrix created in the Classification Learner app. This can make a confusion matrix for a multi-class or non-binary classification problem. In addition, it can plot things such as a True Positive or False Negative rates.
How can I do this?
Accepted Answer
More Answers (1)
David Franco
on 23 Jan 2018
Edited: MathWorks Support Team
on 16 Mar 2018
Implementation code:
Confusion Matrix
function [] = confusion_matrix(T,Y)
M = size(unique(T),2);
N = size(T,2);
targets = zeros(M,N);
outputs = zeros(M,N);
targetsIdx = sub2ind(size(targets), T, 1:N);
outputsIdx = sub2ind(size(outputs), Y, 1:N);
targets(targetsIdx) = 1;
outputs(outputsIdx) = 1;
% Plot the confusion matrix
plotconfusion(targets,outputs)
Categories
Find more on Classification Ensembles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!