Generate confusion matrix with data out of an excel file

24 visualizzazioni (ultimi 30 giorni)
Hello,
I have my classifications and the true label of a data set written in an excel file. The plan ist to create with this dataset a confusion matrix. Is there a Matlab App to create the confusion matrix or any kind of code which can create this?
The table looks like this. There are 42 classes and 12630 classifications and true label. Here it is just a short outtake of the excel file.
Classification 16 1 38 33 11 38 18 12
True Label 16 1 38 33 11 38 18 12

Risposte (1)

Pratyush Swain
Pratyush Swain il 10 Dic 2023
Hi Eren,
I understand you want to read classifications and true labels of a data set from an excel file and create a confusion matrix. Please refer to the example workflow as follows:
1. Create excel sheet-
I have created an excel sheet containing the provided data.
2 - Read the excel file through 'readtable' or 'readmatrix' function
M = readmatrix('path_to_file.xlsx');
% Can also read the excel file as table through T = readtable('path_to_file.xlsx'); %
3 - Load the labels to 'confusionmat' function.(Requires Statistics and Machine Learning Toolbox to be installed)
g1 = M(:,1); % Known groups
g2 = M(:,2); % Predicted groups
[C1,order] = confusionmat(g1,g2)
% The order of labels can also be changed as required %
[C2,order] = confusionmat(g1,g2,'Order',[38,33,18,16,12,11,1])
4 - Visualize the confusion matrix as confusion chart
cm=confusionchart(C2)
For more information of 'confusionmat' and 'import spreadsheets' , please refer to:
Hope this helps.

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by