How can I plot confusion matrix using the below code?

2 visualizaciones (últimos 30 días)
Biplab  Madhu
Biplab Madhu el 4 de Jul. de 2019
Respondida: Yash Totla el 5 de Jul. de 2019
function [confusion, accuracy, CR, FR] = confusion_matrix(class, c)
class = class.';
c = c.';
n = length(class);
c_len = length(c);
if n ~= sum(c)
disp('ERROR: wrong input!');
return;
end
% confusion matrix
confusion = zeros(c_len, c_len);
a = 0;
for i = 1: c_len
for j = (a + 1): (a + c(i))
confusion(i, class(j)) = confusion(i, class(j)) + 1;
end
a = a + c(i);
end
confusion = confusion';
% Correct_classification_rate + False_alarm_rate + Overall_accuracy
CR = zeros(1, c_len);
FR = zeros(1, c_len);
for i = 1: c_len
CR(i) = confusion(i, i)/sum(confusion(:, i));
FR(i) = (sum(confusion(i,:)) - confusion(i, i))/sum(confusion(i, :));
end
accuracy = sum(diag(confusion))/sum(c);
  1 comentario
KALYAN ACHARJYA
KALYAN ACHARJYA el 4 de Jul. de 2019
Editada: KALYAN ACHARJYA el 4 de Jul. de 2019
Thsi is a custom function, you have to pass the data to the function. Read about confusion matrix here.

Iniciar sesión para comentar.

Respuestas (1)

Yash Totla
Yash Totla el 5 de Jul. de 2019
There is a plotconfusion function in MATLAB Deep Learning Toolbox for plotting the confusion matrix.

Categorías

Más información sobre Descriptive Statistics and Visualization en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by