I am trying to deal with a problem of classification with SVM, at the beginning I managed to solve the problem at the first level, ie classify my data into 2 classes (class1 and class2). now I want to continue the classification hierarchically ie f I want to separate the second class into two classes. is there a way to do it with Matlab SVM. thank you
1
votes
Could you use a loop...?
- Dan
actually, im use the folowing code to classify my data into 2 classes model=svmtrain(lab_train,train,'-t 2 -d 2 -c 7 -g 0.5'); [labeltrain,valtrain,prectrain]= svmpredict(lab_train,train,model); [labeltest,valtest,prectest]= svmpredict(lab_test,test,model); and i dont know how to use the result in a way that i take only the second class and classify it aigain in to 2 classes
- user3127771
@user3127771 You should edit your question instead of adding a comment.
- Michaƫl
1 Answers
3
votes
You haven't said anything about your features, because after the first classification you would have to define new features for the new classifier.
You can have the features stored in a matrix and use them in the new classifier.
Since I don't know exactly what your problem is, I provided an example without a loop, but you can easily change to a loop if you want.
x1 = 5 * rand(100,1);
y1 = 5 * rand(100,1);
data1 = [x1,y1];
x2 = -5 * rand(100,1);
y2 = 5 * rand(100,1);
data2 = [x2,y2];
x3 = -5 * rand(100,1);
y3 = -5 * rand(100,1);
data3 = [x3,y3];
plot(data1(:,1),data1(:,2),'r.'); hold on
plot(data2(:,1),data2(:,2),'bo');
plot(data3(:,1),data3(:,2),'ms');
data = [data1;data2;data3];
above is my data, representing points in a 2D plane.
Now I will classify them in 2 classes x>0
and x<0
.
label = ones(size(data,1),1);
label(1 : size(data1,1)) = -1;
c1 = svmtrain(data,label,'Kernel_Function','linear','showplot',true);
hold on;
p1 = svmclassify(c1,data);
After the first classifier I choose one class (x<0
) and define new a feature.
and I will classify them in 2 classes, y>0
and y<0
.
newdata = data(p1 == 1,:);
data1 = newdata(newdata(:,2)>=0,:);
data2 = newdata(newdata(:,2)< 0,:);
data = [data1;data2];
label = ones(size(data,1),1);
label(1 : size(data1,1)) = -1;
c2 = svmtrain(data,label,'Kernel_Function','linear','showplot',true);
I used all the data for training, you can also adjust that to your problem.