What is the training accuracy of this model?

8 views (last 30 days)
I’m trying to classifiy ECG signals using LSTM and MATLAB, the above plot shows that the training accuracy of the system is 100% but when I apply this code to calculate and get the accuracy I get only 20%
LSTMAccuracy = sum(trainPred == Labels)/numel(Labels)*100
Am I missing something here? Or there something wrong I did in my code?
Here is the configuration and the training code:
layers = [ ...
sequenceInputLayer(1)
bilstmLayer(100,'OutputMode','last')
fullyConnectedLayer(5)
softmaxLayer
classificationLayer
]
options = trainingOptions('adam', ...
'MaxEpochs',1750, ...
'MiniBatchSize', 150, ...
'InitialLearnRate', 0.0001, ...
'ExecutionEnvironment',"auto",...
'plots','training-progress', ...
'Verbose',false);
net = trainNetwork(Signals, Labels, layers, options);
trainPred = classify(net, Signals,'SequenceLength',1000);
LSTMAccuracy = sum(trainPred == Labels)/numel(Labels)*100
figure
confusionchart(Labels,trainPred,'ColumnSummary','column-normalized',...
'RowSummary','row-normalized','Title','Confusion Chart for LSTM');
I really appreciate your help, thanks.

Accepted Answer

Chunru
Chunru on 1 Aug 2022
If Labels is character array instead of string array, then numel(Labels) will give the number of characters instead of the number of signals intended.
Labels =["abc"; "def"; "ghi"];
numel(Labels)
ans = 3
Labels =['abc'; 'def'; 'ghi'];
numel(Labels)
ans = 9
My guess is that you have a character arrays with 5 characters for each label. If this is the case, use the following
size(Labels, 2)
ans = 3
  9 Comments
Chunru
Chunru on 2 Aug 2022
Try the following:
trainPred = classify(net, Signals,'SequenceLength','longest');

Sign in to comment.

More Answers (0)

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!