how to find the accuracy from the predicted labels for test data in Matlab?
2 ビュー (過去 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!