필터 지우기
필터 지우기

Why Accuracy is zero

조회 수: 1 (최근 30일)
sun rise
sun rise 2021년 10월 3일
댓글: Walter Roberson 2021년 10월 13일
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
sun rise
sun rise 2021년 10월 13일
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 2021년 10월 13일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 10월 3일
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 ?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by