我正在尝试使用SVM对步行周期进行分类。我使用的是预先计算好的内核,就像RBF内核一样。 K(X,X')= exp(-sigma * dtw(X,X')^ 2)。我正在尝试一个反对所有stratergy多类分类。目前,我正在使用概率来预测我也希望使用多数投票但是卡住了,我需要考虑如何使用多数投票来做出类决策,我想在模型上测试所有例子并用更多投票来预测类,这是可以接受的方法吗?我有以下代码。我
%# Walk cycles dataset
clear
clc
close all
% addpath to the libsvm toolbox
%addpath('../libsvm-3.12/matlab');
% addpath to the data
dirData = './data';
addpath(dirData);
% Load/read the seprated datasets
load(fullfile(dirData,'myTrainData.mat'));
trainData = myTrainData (:,5:104); clear data;
trainLabel = myTrainData(:,1); clear label;
load(fullfile(dirData,'myTestData.mat'));
testData = myTestData(:,5:104); clear data;
testLabel = myTestData(:,1); clear label;
% Extract important information
labelList = unique(trainLabel);
NClass = length(labelList);
[Ntrain D] = size(trainData);
[Ntest D] = size(testData);
[~,~,labels] = unique(trainLabel); %# labels: 1/2/3/4...../51
%data = zscore(meas); % Currently I am not scaling features
numInst = size(trainData,1);
numLabels = max(trainLabel);
%# split training/testing
% I have already seprated train and test Dataset
idx = randperm(numInst);
numTrain = 100;
numTest = size(testData,1);
%trainData = data(idx(1:numTrain),:); testData = data(idx(numTrain+1:end),:);
%trainLabel = labels(idx(1:numTrain)); testLabel = labels(idx(numTrain+1:end));
%# train one-against-all models
preCompKernel = @(X,Y) (distanceMat2(X,Y));
K_preCompKernel = [(1:numTrain)' , preCompKernel(trainData,trainData)];
K_preCompKernelTest = [(1:numTest)' ,preCompKernel(testData,trainData)];
k_preCompNum = K_preCompKernel(:,1);
k_preCompData = K_preCompKernel(:,2:end);
K_preCompKernelTestNum = K_preCompKernelTest(:,1);
K_preCompKernelTestData = K_preCompKernelTest (:,2:end);
kernalMat = exp((-1/sigma).* k_preCompData.^2);
kernelMatTest = exp((-1/sigma).* K_preCompKernelTestData.^2);
kernelFinalMat = [k_preCompNum k_preCompData];
kernelFinalMatTest = [K_preCompKernelTestNum K_preCompKernelTestData];
model = cell(numLabels,1);
for k=1:numLabels
model{k} = svmtrain(double(trainLabel==k), kernelFinalMat, '-c 1 -t 4 -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), kernelFinalMatTest, 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)
答案 0 :(得分:0)
在一对多的多级分类中没有多数投票的事情。当您对k类进行1对比投票时,您将获得k票/概率/ ...标签被分配给最高的个人。