matlab – libsvm中的多类分类

我正在使用libsvm,我必须实现多类的分类,而不是全部.

我该怎么做?
libsvm版本2011是否使用此功能?

我认为我的问题不是很清楚.
如果libsvm没有自动使用one,那么我将为每个类使用一个svm,否则我如何在svmtrain函数中定义这个参数.
我读过libsvm的自述文件.

最佳答案
根据官方libsvm documentation(第7节):

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.

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.

在一对一的方法中,我们构建了与类一样多的二元分类器,每个类都训练将一个类与其余类分开.为了预测新实例,我们选择具有最大决策函数值的分类器.

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

请考虑以下示例:

%# 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的一对一方法的实现:

%# 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

转载注明原文:matlab – libsvm中的多类分类 - 代码日志