Info

This question is closed. Reopen it to edit or answer.

How to find the confusion matrix of a given network?

1 view (last 30 days)
%%
Folder = 'C:\Users\Vishal\Desktop\Rokesh\NntestCopy\Bacteria';
if ~isdir(Folder)
Message = sprintf('Error: cant find the folder:\n%s', Folder);
uiwait(warndlg(Message));
else Message = sprintf('Folder exists:\n%s', Folder);
uiwait(warndlg(Message));
return;
end
%%
DataPath = fullfile(Folder)
%%
imgdts = imageDatastore(DataPath,'IncludeSubfolders',true,'LabelSource','foldernames')
%%
imgdts.countEachLabel
%%
trainingNumFiles = 46;
rng(1)
[imgdtsTrain,imgdtsValidation] = splitEachLabel(imgdts,...
trainingNumFiles,'randomize')
%%
layers=[...
imageInputLayer([566 804 3])
convolution2dLayer(5,20,'stride',2)
reluLayer
maxPooling2dLayer(5,'stride',1)
convolution2dLayer(5,20,'stride',2)
reluLayer
maxPooling2dLayer(5,'stride',1)
convolution2dLayer(5,20,'stride',2)
reluLayer
maxPooling2dLayer(5,'stride',1)
convolution2dLayer(5,4,'stride',2,'padding',[1 1])
reluLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer()]
%analyzeNetwork(layers)
%%
options = trainingOptions('sgdm',...
'MaxEpochs',25,...
'ValidationData',{imgdtsTrain,imgdtsValidation},...
'ValidationFrequency',2,...
'Momentum',0.8,...
'ValidationPatience',1,...
'InitialLearnRate',0.0001,...
'MiniBatchSize',4,...
'Verbose',true,...
'executionenvironment','auto',...
'Shuffle','every-epoch',...
'Plots','training-progress')
%%
microbenet=trainNetwork(imgdts,layers,options)
%%
i=imread('ccb23.jpg');
figure,imshow(i);
%%
output=classify(microbenet,i)
Here, I have 104 images and then labeled them as four species as a,b,c,d. Each label consists of 26 images. I wanted a confusion matrix of this network.
  1 Comment
KALYAN ACHARJYA
KALYAN ACHARJYA on 30 May 2019
Edited: KALYAN ACHARJYA on 3 Jun 2019
At first, it would be better if you go through, what is confusion matrix?

Answers (1)

Jyotish Kumar
Jyotish Kumar on 3 Jun 2019
Hi,
The Deep Learning Toolbox in MATLAB has ‘confusion’ and ‘plotconfusion’ functions to extract the confusion matrix. Please go through the following links for more details:
I hope it will help you.

Community Treasure Hunt

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

Start Hunting!

Translated by