libsvm中的多类分类 [英] Multi-class classification in libsvm

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

问题描述

我正在使用 libsvm ,我必须实现分类对于具有 one vs all 的多类.

I'm working with libsvm and I must implement the classification for multiclasses with one versus all.

我该怎么办?
libsvm 2011版是否使用此?

How can I do it?
Does libsvm version 2011 use this?

我认为我的问题不是很清楚. 如果libsvm不自动使用一个vs所有,则我将为每个类使用一个svm,否则如何在svmtrain函数中定义此参数. 我已经阅读了libsvm的自述文件.

I think that my question is not very clear. if libsvm don't use automatically one versus all,I will use one svm for every class, else how can i defined this parameters in the svmtrain function. I had read README of libsvm.

推荐答案

根据官方libsvm 文档(第7节):

According to the official libsvm documentation (Section 7):

LIBSVM对多类实施一对一"方法 分类.如果k是类数,则k(k-1)/2 构造分类器,每个分类器训练两个分类器中的数据 课.

LIBSVM implements the "one-against-one" approach for multi-class classification. If k is the number of classes, then k(k-1)/2 classifiers are constructed and each one trains data from two classes.

在分类中,我们使用投票策略:每个二进制 分类被认为是可以进行投票的投票 对于所有数据点x-最后将一个点指定为位于 投票最多的班级.

In classification we use a voting strategy: each binary classification is considered to be a voting where votes can be cast for all data points x - in the end a point is designated to be in a class with the maximum number of votes.

在万事通"方法中,我们建立了与所有类一样多的二进制分类器,每个分类器都经过训练,可以将一个分类与其他分类分开.为了预测新实例,我们选择决策函数值最大的分类器.

In the one-against-all approach, we build as many binary classifiers as there are classes, each trained to separate one class from the rest. To predict a new instance, we choose the classifier with the largest decision function value.

正如我之前提到的,其思想是训练k SVM模型,每个模型将一个类与其他类分开.一旦有了这些二元分类器,就可以使用概率输出(-b 1选项),通过选择概率最高的类来预测新实例.

As I mentioned before, the idea is to train k SVM models each one separating one class from the rest. Once we have those binary classifiers, we use the probability outputs (the -b 1 option) to predict new instances by picking the class with the highest probability.

请考虑以下示例:

%# Fisher Iris dataset
load fisheriris
[~,~,labels] = unique(species);   %# labels: 1/2/3
data = zscore(meas);              %# scale features
numInst = size(data,1);
numLabels = max(labels);

%# split training/testing
idx = randperm(numInst);
numTrain = 100; numTest = numInst - numTrain;
trainData = data(idx(1:numTrain),:);  testData = data(idx(numTrain+1:end),:);
trainLabel = labels(idx(1:numTrain)); testLabel = labels(idx(numTrain+1:end));

这是我针对多类SVM的一种万事通"方法的实现:

Here is my implementation for the one-against-all approach for multi-class SVM:

%# train one-against-all models
model = cell(numLabels,1);
for k=1:numLabels
    model{k} = svmtrain(double(trainLabel==k), trainData, '-c 1 -g 0.2 -b 1');
end

%# get probability estimates of test instances using each model
prob = zeros(numTest,numLabels);
for k=1:numLabels
    [~,~,p] = svmpredict(double(testLabel==k), testData, model{k}, '-b 1');
    prob(:,k) = p(:,model{k}.Label==1);    %# probability of class==k
end

%# predict the class with the highest probability
[~,pred] = max(prob,[],2);
acc = sum(pred == testLabel) ./ numel(testLabel)    %# accuracy
C = confusionmat(testLabel, pred)                   %# confusion matrix

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

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