how to correct " Error in pro_spec (line 219), if(Classif​icationSVM​(models,Te​stSet(j,:)​)) " and "Error using ClassificationSVM (line 249) Use fitcsvm to train an SVM model."

1 回表示 (過去 30 日間)
my matlab code:
%build models
for k=1:numClasses
%Vectorized statement that binarizes Group
%where 1 is the current class and 0 is all other classes
G1vAll=(GroupTrain==u(k));
models = fitcsvm(TrainingSet,G1vAll);
end
%classify test cases
for j=1:size(TestSet,1)
for k=1:numClasses
if(ClassificationSVM(models,TestSet(j,:)))
break;
end
end
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 10 月 16 日
Notice by the way that you are overwriting all of the variable models for each of your classes. And notice that your inner loop of the "for j" is doing the same thing for every k value.
l divya
l divya 2018 年 10 月 16 日
編集済み: Walter Roberson 2018 年 10 月 16 日
i got following errors while executing attached file:
Error using ClassificationSVM (line 249)
Use fitcsvm to train an SVM model.
Error in pro_spec (line 219)
if(ClassificationSVM(models,TestSet(j,:)))

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2018 年 10 月 16 日
You should be using
models{k} = fitcsvm(TrainingSet,G1vAll);
and
if predict(models{k}, TestSet(j,:))
ClassificationSVM is a class, not a routine that tests for matches.
You can be more efficient, by asking for the prediction about the entire TestSet .
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 10 月 19 日
As I said, "ClassificationSVM is a class, not a routine that tests for matches." Class in an object-oriented sense. It is not a routine which makes predictions about which class (in the dataset label sense) a particular set of data belongs to: you need predict() for that, and I already posted the appropriate line,
if predict(models{k}, TestSet(j,:))

サインインしてコメントする。

その他の回答 (1 件)

sambath kumar
sambath kumar 2020 年 11 月 4 日
HI everone
my matlab code is
%This while loop is the multiclass SVM Trick
c1=(C==u(itr));
newClass=c1;
%svmStruct = svmtrain(T,newClass,'kernel_function','rbf'); % I am using rbf kernel function, you must change it also
model = fitcsvm(T,newClass); %#ok<SVMTRAIN>
classes = ClassificationSVM(model,tst);
% This is the loop for Reduction of Training Set
for i=1:size(newClass,2)
if newClass(1,i)==0;
c3(k,:)=T(i,:);
k=k+1;
end
end
When i use this above code, i am getting error like this:
Error using ClassificationSVM (line 249)
Use fitcsvm to train an SVM model.
Error in multisvm (line 29)
classes = ClassificationSVM(model,tst);
Error in Detect (line 144)
result = multisvm(Train_Feat,Train_Label,test);
could you resolve this
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 11 月 4 日
which is to say that ClassificaitonSVM is not a classification routine and you need to use predict()
I notice that a few different people have made exactly the same mistake, which suggests they are all copying the same source code, but I have not been able to locate which code is being copied.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by