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,
cnnScores = predict(cnnnet, XValidation);
[~, idx] = max(cnnScores, [], 2);
cnnYPred = categories(YTrain);
cnnYPred = cnnYPred(idx);
cnnAccuracy = sum(cnnYPred == YValidation) / numel(YValidation);
fprintf('CNN-LSTM Validation Accuracy: %.2f%%\n', cnnAccuracy * 100);
lstmScores = predict(lstmnet, XValidation);
[~, idx] = max(lstmScores, [], 2);
lstmYPred = categories(YTrain);
lstmYPred = lstmYPred(idx);
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,
- CNN-LSTM Model
2. LSTM only Model
3. Accuracy of both the models