How to plot confusion matrix

I have performed my image segmentation using kmeans but need to get the confusion matrix. My image segmentation matrix for six(6) classes has numbers 1 to 6 in it which is perfect. On getting my trained classes BW_1,BW_2,BW_3,BW_4,BW_5,BW_6 I have in each only one's(1's) and zero's(0's) but need to create a single confusion matrix like in this link http://www.mathworks.com/help/nnet/ref/plotconfusion.html?searchHighlight=confusion%2520matrix

 采纳的回答

The function plotconfusion handles more than 2 classes. Replace the iris_dataset or simplecluster_dataset in the help and doc examples for plotconfusion
[x,t] = iris_dataset;
net = patternnet;
rng('default')
[net tr y e] = train(net,x,t);
NMSE = mse(e)/mean(var(t',1)) %0.0418
R2 = 1-NMSE %0.9582
plotconfusion(t,y);
Find the minimum number of hidden nodes that yields an acceptable result
Hope this helps.
Thank you for formally accepting my answer
Greg

3 个评论

Thank you Greg but just on running line one for class 1.
[x,t] = BW_class_1;
It tells me "too many arguments".
Please you could look through my comments with star strider above to help me better. The help document doesn't help so much. I anticipate to formally accept your answer. NOTE: I'm a newbie.
That command assumes the input and target matrices are combined as in the MATLAB example database
help nndatasets
doc nndatasets
If your data is not formatted that way, then change the command to read the way your data is formatted.
You said the command assumes that my input & target matrices are combined. please in the case where my target matrix are 6 different matrices and each contain only ones and zeros while the input has 1,2,3,4,5,6. How can I achieve this. Thanks in advance.

请先登录,再进行评论。

更多回答(1 个)

Star Strider
Star Strider 2014-10-20
编辑:Star Strider 2014-10-20

2 个投票

The Neural Network Toolbox confusion function will only let you plot (2x2) classification results. To plot more classes, use the Statistics Toolbox confusion function.
The crosstab function will give you the chi-squared statistic and the probability.

7 个评论

NOTE: I'm just a little familiar with the software.
I just tried using the confusion function and it tells me
Error using confusionmat (line 67)
G and GHAT need to be vectors or 2D character arrays.
However,
% BW_1 is predicted class 1
% BW_class_1 is known class 1
[C,order] = confusionmat(BW_class_1,BW_1)
where BW_class_1 is <2592x4608 logical>
where BW_1 is <2592x4608 logical>
But as of after segmentation, I had just a matrix called pixel_labels which contained all six(6) classes but I separated it using the code below.
BW_class_1=pixel_labels==1;
Thank you and I anticipate to accept your answer.
My pleasure!
I do not completely understand your comment, though. Is your problem solved or do you need more help?
Thank you. My problem is yet to be answered/solved
I still do not understand how you could have a matrix of classes. In the confusion matrices I have used in statistics, each element has a known class and a predicted class, in your example, every one being a class numbered 1-6. Your classifier should output a particular class number for each input pattern. Those vectors are then the inputs to your confusion matrix.
I understand that The single matrix from segmentation (kmeans,for six classes) is my input, but I trained six classes (known) using
roipoly function
But this gives me six separate matrices with O's and 1's in them.
I need to,from the single segmentation matrix(predicted) and the six different trained classes(known), compute my confusion matrix.
If you have vectors with your known and predicted classes, those are your inputs to your confusion matrix. I got the impression from your Question, specifically ‘My image segmentation matrix for six(6) classes has numbers 1 to 6 in it which is perfect.’ that you already had those and simply wanted to know how to create a confusion matrix for your 6 classes.
Exactly! But am I to combine the trained classes(known, with 0's and 1's) so I could have a single matrix like the predicted or use them as they are? If so, please how do I do that?

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by