hierarchical classification with SVM

1.3k Views Asked by At

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

There are 1 best solutions below

4
Rash On

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);

enter image description here

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);

enter image description here

I used all the data for training, you can also adjust that to your problem.