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
Asked
Active
Viewed 1,287 times
1
-
Could you use a loop...? – Dan Dec 17 '14 at 12:46
-
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 Dec 17 '14 at 13:39
-
1@user3127771 You should edit your question instead of adding a comment. – Michaël Dec 17 '14 at 13:43
1 Answers
3
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.

Rashid
- 4,326
- 2
- 29
- 54
-
for my data i have images stored in a matrix of form <128x128x512 double> : 256 imagefor the first class and 256 image for class 2. , firstly i exctract features from images . my feture verctor is of the form <512x15104 double> and i used 50% for training and 50% for testing . and i classify like that : 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); where: train is the training data , test is the testing data – user3127771 Dec 17 '14 at 16:09
-
@user3127771, you can add that to your question. What features are you going to use for the second classifier? – Rashid Dec 17 '14 at 17:04
-
for the second classifier i want to use features witch were classified as belonging to the class2 – user3127771 Dec 17 '14 at 17:13
-
@user3127771, I didn't mean that. In my example I have used the value of `x` as feature for first classification and the value of `y` in second classification. In your case I don't get what your second classification will be based on. – Rashid Dec 17 '14 at 17:26