Tall cell arrays with confusionchart()

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Tushar
Tushar il 24 Feb 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!!

Più risposte (0)

Categorie

Scopri di più su Sequence and Numeric Feature Data Workflows in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by