how to find the accuracy from the predicted labels for test data in Matlab?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Riya
am 26 Mär. 2025
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 Kommentare
Siehe auch
Kategorien
Mehr zu Classification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!