Clear Filters
Clear Filters

HOW I Can classify ecg signal using CNN_LSTM

12 views (last 30 days)
Aisha
Aisha on 28 Oct 2022
Answered: Meet on 19 Aug 2024 at 11:18
I work on ecg signal and iwant to compare between cnn_lstm
and lstm only in ecg classification i reserch on code i dont found may be some one have it.

Answers (1)

Meet
Meet on 19 Aug 2024 at 11:18
Hi Aisha,
Assuming you have both CNN-LSTM and LSTM-only models trained, you can utilize the "predict" function to obtain the output label scores (using softmax), which are essential for inference. The "predict" function can be utilized as below,
% Use predict function to get scores
cnnScores = predict(cnnnet, XValidation);
% Convert scores to class labels
[~, idx] = max(cnnScores, [], 2);
cnnYPred = categories(YTrain);
cnnYPred = cnnYPred(idx);
% Calculate accuracy
cnnAccuracy = sum(cnnYPred == YValidation) / numel(YValidation);
fprintf('CNN-LSTM Validation Accuracy: %.2f%%\n', cnnAccuracy * 100);
% Use predict function to get scores
lstmScores = predict(lstmnet, XValidation);
% Convert scores to class labels
[~, idx] = max(lstmScores, [], 2);
lstmYPred = categories(YTrain);
lstmYPred = lstmYPred(idx);
% Calculate accuracy
lstmAccuracy = sum(lstmYPred == YValidation) / numel(YValidation);
fprintf('LSTM-only Validation Accuracy: %.2f%%\n', lstmAccuracy * 100);
Here "cnnnet" and "lstmnet" are the network models that you have trained.
  • "max" function is used to find the index of the maximum score for each row in "cnnScores" and "lstmScores".
  • cnnAccuracy = sum(cnnYPred == YValidation) / numel(YValidation); This line calculates the accuracy of the CNN-LSTM network by comparing the predicted labels "cnnYPred" with the true labels "YValidation". It counts the number of correct predictions and divides by the total number of validation samples to get the accuracy as a fraction.
For more information on the "predict" function, you can refer to the following documentation:
Here are some screenshots of the model execution along with their accuracy,
  1. CNN-LSTM Model
2. LSTM only Model
3. Accuracy of both the models

Tags

Community Treasure Hunt

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

Start Hunting!