simple example for SVM

Can anyone give me an example of how I can start with support vector machine in MATLAB?

更多回答(1 个)

Nirmal
Nirmal 2012-6-4

0 个投票

12 个评论

Nirmal, in your example, your line
if Group(i,1)==1
should probably be
if Group1(i,1)==1
otherwise you are testing Group(i,1) which you set to all 0 just a few lines above.
GroupF=zeros(90,1);
I am setting GroupF to zero not Group. (I know, my naming convention is not the greatest) but it does work.
You are right, I did misread the code.
There seems to be an error in your code.
if Group1(i,1)==2
GroupF(i,1)=2;
else
GroupF(i,1)=3;
end
should be
if Group1(i,1)==1
GroupF(i,1)=2;
else
GroupF(i,1)=3;
end
Even if there is no error, there is a problem with this approach. You treat the classes asymmetrically. You separate 1 from 2 and 3 and then separate 3 from 1 and 2. Then you assign a new observation to class 2 if it is neither class 1 nor class 3. There are two problems here:
1. The lack of symmetry implies that the classification scheme is sensitive to the order of the classes. In your case, class 2 can work as a sink for all observations that are neither clearly class 1 nor class 3.
2. It is not clear how this extends to more than 3 classes.
1. IRIS dataset has only three classes, so I dont see problem with the code with class 2 acting as a sink. ( I am not sure why I need to be worried about the symmetry though.)
2. If I need to extend it to lets say 4 classes, I need to separate first 1 then 2 followed by 3 and finally 4. It would require me to use SVM 3 times. Again I could also do it by starting with 4,3,2 and finally 1 acting as a sink. It just the matter of separating 2 classes each time, where one of the class is the class we are trying to separate and another classes contains the rest of it. (Is that not right?)
In this scheme, you can end up assigning all uncertain observations to the sink class. The confusion matrix can be heavily skewed in favor of that class. The choice of the sink class is determined by an arbitrary order of the classes in the data (because there is no symmetry). I would be reluctant to use any classifier in which one class gets a heavy load of predictions for no reason other than being arbitrarily chosen as a sink. It is a problem no matter how many classes you have - 3, 4 etc.
I understand what you are saying but there is no uncertain items in IRIS data set. Out of 150 Items, 1-50 are setosa, 51-100 are versicolor and 101-150 are virginica.
Fisher iris is one of the easiest datasets around. Pretty much any classifier can separate the groups. It would be easy to come up with a multiclass example in which your scheme fails miserably but a standard approach such as, for instance, one-vs-one succeeds.
Nirmal,thanks for the code.
LOKESH
LOKESH 2015-11-30
编辑:LOKESH 2015-11-30
Error: ??? Reference to non-existent field 'GroupNames'.
Error in ==> svmclassify at 90 groupnames = svmStruct.GroupNames;
Error in ==> svm at 16 Group = svmclassify(SVMStruct,testset);
LOKESH, which MATLAB version are you using, and where is your svm from? (There are few different SVM around.)
This site is not available..what to do

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Statistics 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