Tall cell arrays with confusionchart()
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Christopher McCausland
le 28 Jan 2023
Réponse apportée : Tushar
le 24 Fév 2023
Hi,
I have trained a deep learning model on a datastore. The datastore is split into three subsets; train, test and validate.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create a subset of the datastore for test, train & val purposes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
split = [10,80,10]; % [Train, val, test] as a int percentage i.e. [60,20,20]
[split_idx] = round(length(ds.Files)*(split/100));
train_idx = [1:split_idx(1)];
val_idx = [split_idx(1):split_idx(1)+split_idx(2)];
test_idx = [split_idx(1)+split_idx(2):split_idx(1)+split_idx(2)+split_idx(3)];
dstrain = subset(ds,train_idx);
dsval = subset(ds,val_idx);
dstest = subset(ds,test_idx);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
After training the model I want to generate a confusion chart. However my datastore is a tall cell array, the first cell column is data and the second column is a lable. As brace indexing isn't allowed with tall data (myarray{..,..}{..,..}) I cannot come up with a simple way to extract the lablels from the tall array. Am I missing something obvious? I will attach a sample of the data.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Train the network and calculate performance
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
net = trainNetwork(dstrain,layers,options);
YPred = classify(net,dstest,'MiniBatchSize',70);
%confusionchart(dstest(),YPred); % Trying to get the second column of
%dstest as the true labels
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Unfortunatly I received the data in a cell column format so can't just recompute to an easier format. After importing the sample data
tall(ans)
should generate a sample; 4X1 tall cell where each row is an x*2 cell array, the first column being data and the second column being the ground truth label which I would like to extract as a variable for confusionchart().
Kind regards,
Christopher
0 commentaires
Réponse acceptée
Tushar
le 24 Fév 2023
Hi,
As far as I understood, you wanted to separate out the labels, i.e the second column from the data you have given.
This can be done by playing around a bit with the data as:
load('tall_test_example.mat')
labels = []
for i = 1:length(ans) % ans is the loaded data
labels = [labels; string(ans{i}(:,2))]
end
This generates a 374x1 string of labels, which you can use as a variable for confusionchart().
Hope it helps!!
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!