Error using svm classifier

1 回表示 (過去 30 日間)
Basavaraja V
Basavaraja V 2018 年 7 月 12 日
コメント済み: Walter Roberson 2018 年 7 月 12 日
Error using svmtrain (line 274) SVMTRAIN only supports classification into two groups. GROUP contains 4 groups.
Error in Classifier_10_fold (line 15) svmModel = svmtrain(FM(trainIdx,:), groups(trainIdx), ...

回答 (1 件)

KSSV
KSSV 2018 年 7 月 12 日
編集済み: KSSV 2018 年 7 月 12 日
svm will work on only two classes or groups. You need to send only two groups data to train it. Check the below example:
load fisheriris
% the data has three classes, pick only two classes out of it.
inds = ~strcmp(species,'setosa'); % don't consider this class
X = meas(inds,3:4);
y = species(inds);
%
SVMStruct = svmtrain(X,y)
Where as if I use all the classes, it will throw the same error as you got .
SVMStruct = svmtrain(meas,species) ; % this will give error as three classes are present
Also check that svmtrain is outdated, you need to use fitcsvm.
  3 件のコメント
KSSV
KSSV 2018 年 7 月 12 日
YOu select any two groups and run the model. You can select the group using:
load fisheriris
% the data has three classes, pick only two classes out of it.
inds = strcmp(species,'setosa') | strcmp(species,'virginica'); % select these two out of all groups
X = meas(inds,3:4);
y = species(inds);
%
SVMStruct = svmtrain(X,y) ;
Walter Roberson
Walter Roberson 2018 年 7 月 12 日

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by