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!