Error using svmclassify The number of columns in TEST and training data must be equal. Error in multisvm classes = svmclassify(svmStruct,tst);
조회 수: 1 (최근 30일)
이전 댓글 표시
when i try to classify i got the above error in multisvm this is the code that am using
function [itrfin] = multisvm( T,C,test )
itrind=size(test,1);
itrfin=[];
Cb=C;
Tb=T;
for tempind=1:itrind
tst=test(tempind,:);
C=Cb;
T=Tb;
u=unique(C);
N=length(u);
c4=[];
c3=[];
j=1;
k=1;
if(N>2)
itr=1;
classes=0;
cond=max(C)-min(C);
while((classes~=1)&&(itr<=length(u))&& size(C,2)>1 && cond>0)
c1=(C==u(itr));
newClass=c1;
svmStruct = svmtrain(T,newClass);
classes = svmclassify(svmStruct,tst);
for i=1:size(newClass,2)
if newClass(1,i)==0;
c3(k,:)=T(i,:);
k=k+1;
end
end
T=c3;
c3=[];
k=1;
for i=1:size(newClass,2)
if newClass(1,i)==0;
c4(1,j)=C(1,i);
j=j+1;
end
end
C=c4;
c4=[];
j=1;
cond=max(C)-min(C);
if classes~=1
itr=itr+1;
end
end
end
valt=Cb==u(itr);
val=unique(val);
itrfin(tempind,:)=val;
end
end
댓글 수: 0
답변 (2개)
Walter Roberson
2018년 3월 11일
tst=test(tempind,:)
has multiple columns
itr=1;
[...]
c1=(C==u(itr));
newClass=c1;
itr is a scalar, so u(itr) is a scalar, so c1 is a scalar so newClass is a scalar
svmStruct = svmtrain(T,newClass);
You are training on T as if everything is in the same class. If you get different results for newClass = false versus newClass = true then out would be due to round-off error in the calculations. svm does not care what the one class is labeled with; it only cares that you are telling it that all of the data is in the same class.
"The number of columns in TEST and training data must be equal."
size(T,2) is not the same as size(test,2) . You did not happen to show us the sizes.
Be careful with whether your rows represent different attributes within one observation, or whether your rows represent the same attribute for each different observation. Different classification routines have different rules about whether they expect row-oriented or column-oriented values.
댓글 수: 2
thejas A V
2019년 3월 28일
use equal number of dataset and corresponding label pls refer to attachment
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!