Using SVM to train my Dataset

人盡茶涼 提交于 2019-12-23 01:42:09

问题


To understand well the concept behind how Support Vector Machine works in MATLAB, I advised you to read briefly THIS VERY IMPORTANT LINK.

I am trying to apply the same concept but I have different train set and test set.

For more precision:

My train set refers to be named as C2res{1} where this last is equal to:

 C2res{1} =

           1.0e-05 *

          Columns 1 through 10

            0.5341    0.5822    0.6185    0.7555    0.7369    0.7131    0.5985    0.6483    0.5668    0.6620

          Columns 11 through 12

            0.6523    0.6097  

My test set refers to be named as C2res{2} where this last has the same form of C2res{1} but with different values...

Then, I used the concept used in the above link:

XTrain = [C2res{1}];
XTest = [C2res{2}];
label = [ones(size(C2res{1},2),1)];
SVMStruct = svmtrain(XTrain , label, 'kernel_function', 'linear');
Group       = svmclassify(SVMStruct, XTest);

But unfortunately I always get errors like as:

Error using svmtrain (line 335)
Y must contain exactly two groups for method 'SMO'.

That is why I need your help please.

Any help will be very appreciated!


回答1:


Are you trying to implement the classification training with two classes? Your label = [ones(size(C2res{1},2),1)]; contains only one value, and it seems to be expected two values (as two categories). I think that's the reason the error comes out.

If you are applying one-class SVM, try to add such option (see this page for more references on the option):

SVMStruct = svmtrain(XTrain , label,'-t 0 -s 2');


来源:https://stackoverflow.com/questions/21429154/using-svm-to-train-my-dataset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!