how to find the accuracy from the predicted labels for test data in Matlab?
1 次查看(过去 30 天)
显示 更早的评论
I am using classification learner app svm generated code for the classification of multiclass dataset.
Now I wanted to test with the unseen dataset for this I am using yfit.
Now I got the predicted labels for the test data. How to find the test accuracy and from the predicted laebls?
Can someone please help me in this.
0 个评论
回答(1 个)
Riya
2025-3-26
Hi Kanuparthi,
You can compute the accuracy by comparing the predicted labels (“yfit”) with the actual labels (say “yTest”).
The accuracy is calculated as the percentage of correctly predicted labels. Below is a sample MATLAB code for the same:
% Assuming yTest contains the actual labels of the test data
correctPredictions = sum(yfit == yTest); % Count correct predictions
totalTestSamples = length(yTest); % Total number of test samples
% Compute accuracy
accuracy = (correctPredictions / totalTestSamples) * 100;
% Display accuracy
fprintf('Test Accuracy: %.2f%%\n', accuracy);
This will give you the classification accuracy of the model on the test dataset. If your labels are categorical, you may need to use “categorical(yfit) == categorical(yTest)” for comparison.
For further reference, you can refer to the following official MATLAB documentation:
web(fullfile(docroot, 'stats/select-data-and-validation-for-classification-problem.html'))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Classification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!