Confusion Matrix Results Issue

1 次查看(过去 30 天)
I need to determine the misclassified rate of a machine learning algorithm. However, when I use the confusion function over the actual dataset and the predicted dataset (using the algorithm) the error rate is 0 whereas when I iterate through each element and compare them the error rate is 33.3%. What is wrong with the confusion matrix?
outputs = [1, 1, 1, 100, 10, 100];
predictedOutput = [1, 1, 1, 10,100, 100];
[c,cm] = confusion(outputs,predictedOutput);
fprintf('Percentage Correct Classification : %f%%\n', 100*(1-c));
counter =0;
for i = 1: size (predictedOutput,2)
if (predictedOutput(1,i) ~= outputs(1,i))
counter = counter + 1;
end
end
fprintf('Percentage Correct Classification : %f%%\n', 100*(1-(counter/(size(predictedOutput,2)))));

采纳的回答

Shoaibur Rahman
Shoaibur Rahman 2014-12-27
The input arguments of confusion, (in this case, outputs and predictedOutput) should be in range of [0 1]. So, instead of 100 and 10, use 1 and 0, for example.
outputs = [1, 1, 1, 1, 0, 1];
predictedOutput = [1, 1, 1, 0, 1, 1];
[c,cm] = confusion(outputs,predictedOutput);
fprintf('Percentage Correct Classification : %f%%\n', 100*(1-c));
counter =0;
for i = 1: size (predictedOutput,2)
if (predictedOutput(1,i) ~= outputs(1,i))
counter = counter + 1;
end
end
fprintf('Percentage Correct Classification : %f%%\n', 100*(1-(counter/(size(predictedOutput,2)))));
  2 个评论
Mr X
Mr X 2014-12-27
I to classify the dataset into 3 different classes so I cannot use 1 and 0 only. Does this mean that I need to create three rows to represent each class and then select it by setting the element to 1?
Shoaibur Rahman
Shoaibur Rahman 2014-12-28
That could be one way, given it serves your purpose. Another way is to analyze the confusion matrix (user your original outputs,predictedOutput).
cmat = confusionmat(outputs,predictedOutput);
This will allow you to determine the misclassification for each group separately.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by