How to creat and plot a confusion matrix of the trained CNN netowork?
Show older comments
I have trained a CNN and result showed down but I would need help to find the confusion matrix of the network validation accuracy outcome 

Answers (1)
Mahesh Taparia
on 23 Feb 2021
0 votes
Hi
To find the confusion matrix, first you have to test the model on testing data and then use plotconfusion function. For more information, you can refer this example. Hope it will help!
10 Comments
Mohamed Elbeialy
on 27 Feb 2021
Mahesh Taparia
on 28 Feb 2021
Can you share the model prediction and the ground truth data? Or can you share your code?
Mohamed Elbeialy
on 28 Feb 2021
Edited: Mohamed Elbeialy
on 28 Feb 2021
Mahesh Taparia
on 28 Feb 2021
Try this:
plotconfusion(imdsValidation.Labels,YPred)
Mohamed Elbeialy
on 28 Feb 2021
Mahesh Taparia
on 28 Feb 2021
Are you able to train the network? The trainedNet is the trained network which you have defined as:
trainedNet = trainNetwork(augimdsTrain,layers,options); % train the network
Once training completes, it will be a defined object.
Mohamed Elbeialy
on 10 Apr 2021
Mahesh Taparia
on 12 Apr 2021
You can pass the labels and predictions separately to plotConfusion function for each validation,test and training data. For example, consider below:
[YPredValidation] = classify(trainedNet,augimdsValidation); % classify the validation images
plotconfusion(imdsValidation.Labels,YPredValidation)
[YPredTraining] = classify(trainedNet,augimdsTrain); % classify the training images
plotconfusion(imdsValidation.Labels,YPredTraining)
% Similary for testing dataset
Mohamed Elbeialy
on 2 May 2021
R Ramya
on 19 Jan 2022
plotconfusion(YTrain,YPredicted
Categories
Find more on Deep Learning Toolbox 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!