使用 SVM 进行分层分类 [英] hierarchical classification with SVM

查看:62
本文介绍了使用 SVM 进行分层分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SVM 处理分类问题,一开始我设法解决了第一级的问题,即将我的数据分为 2 类(class1 和 class2).现在我想继续分层分类,即我想将第二个类分成两个类.有没有办法用 Matlab SVM 做到这一点.谢谢

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

推荐答案

你还没有说你的特征,因为在第一次分类之后,你必须为新的分类器定义新的特征.

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.

现在我将它们分为两类x>0x<0.

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

在第一个分类器之后,我选择一个类 (x<0) 并定义一个新的特征.

After the first classifier I choose one class (x<0) and define new a feature.

我将它们分为两类,y>0y<0.

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.

这篇关于使用 SVM 进行分层分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆