Why Accuracy is zero

6 views (last 30 days)
sun rise
sun rise on 3 Oct 2021
Commented: Walter Roberson on 13 Oct 2021
function [result] = multisvm(TrainingSet,Group_Train1,TestSet,Group_Test1)
%Models a given training set with a corresponding group vector and
%classifies a given test set using an SVM classifier according to a
%one vs. all relation.
%
%This code was written by Cody Neuburger cneuburg@fau.edu
%Florida Atlantic University, Florida USA...
%This code was adapted and cleaned from Anand Mishra's multisvm function
%found at http://www.mathworks.com/matlabcentral/fileexchange/33170-multi-class-support-vector-machine/
%GroupTrain=GroupTrain';
u=unique(Group_Train1);
numClasses=length(u);
%TestSet=TestSet';
%TrainingSet=TrainingSet';
result = categorical.empty();
%build models
models = cell(numClasses,1);
for k=1:numClasses
%Vectorized statement that binarizes Group
%where 1 is the current class and 0 is all other classes
G1vAll=(Group_Train1==u(k));
%models{k} = fitcsvm(TrainingSet,G1vAll);
models{k} = fitcsvm(TrainingSet,G1vAll,'KernelFunction','polynomial','polynomialorder',3,'Solver','ISDA','Verbose',0,'Standardize',true);
if ~models{k}.ConvergenceInfo.Converged
fprintf('Training did not converge for class "%s"\n', string(u(k)));
end
end
%classify test cases
for t=1:size(TestSet,1)
matched = false;
for M=1:numClasses
if(predict(models{M},TestSet(t,: )))
matched = true;
break;
end
end
if matched
result(t,1) = u(M);
else
result(t,1) = 'No Match';
end
%--------------------------------
end
Accuracy = mean(Group_Test1==result) * 100;
fprintf('Accuracy = %.2f\n', Accuracy);
fprintf('error rate = %.2f\n ', mean(result ~= Group_Test1 ) * 100);
end
Accuracy = 0.00
error rate = 100.00
  4 Comments
sun rise
sun rise on 13 Oct 2021
The result matrix is ​​not equal to the Group_test matrix. Hence the accuracy is zero. Because the counter k reaches 2 only and goes out to the outer loop and does not complete the count to 5. After entering the outer loop again, the count starts from 1 again .. I want the count to continue to 5 and put the value in the result matrix
Walter Roberson
Walter Roberson on 13 Oct 2021
Temporary work around: change
for M = 1:numClasses
if(predict(models{M},TestSet(t,: )))
matched = true;
break;
end
end
to
for M = numClasses:-1:1
if(predict(models{M},TestSet(t,: )))
matched = true;
break;
end
end

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 3 Oct 2021
Your data does not fit your model at all
I showed in https://www.mathworks.com/matlabcentral/answers/894727-why-accuracy-is-zero#comment_1699059 that you can get up to 19% with those exact same training parameters, for the database that you were using then.
I also showed that with that database, it was practically impossible for you to run that code on your system. I suggested some performance improvements, but you do not appear to have used any of them.
Did you get a much bigger computer to run all of this on? Or did you reduce the image size a lot ?

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!