Tall cell arrays with confusionchart()

조회 수: 1 (최근 30일)
Christopher McCausland
Christopher McCausland 2023년 1월 28일
답변: Tushar 2023년 2월 24일
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

채택된 답변

Tushar
Tushar 2023년 2월 24일
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개)

카테고리

Help CenterFile Exchange에서 Model Building and Assessment에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by