我正在做libsvm,如图所示:
numLabels = max(trainlabels);
model = cell(numLabels,1);
for k=1:numLabels
model{k} = svmtrain(double(trainlabels==k), train_data, '-t 0 -b 1');
end
numTest = size(test_data,1);
prob = zeros(numTest,numLabels);
for k=1:numLabels
[predicted_label, accuracy, prob_estimates] = svmpredict(double(testlabels==k), test_data, model{k}, '-b 1');
fprintf('sum(predicted_label==1) = %i \n', sum(predicted_label==1));
fprintf('sum(testlabels==k) = %i \n', sum(testlabels==k));
cc = model{k}.Label==1;
prob(:,k) = prob_estimates(:,cc); %# probability of class==k
end
%# predict the class with the highest probability
[~,pred] = max(prob,[],2);
acc = sum(pred == testlabels) ./ numel(testlabels); %# accuracy
fprintf('Final accuracy = %f %\n', acc*100);
我的准确度始终高于80%(~83%),每次迭代的预测标签总和几乎为零,最终精度为11%。如下图所示:
Accuracy = 65% (39/60) (classification)
sum(predicted_label==1) = 17
Accuracy = 83.3333% (50/60) (classification)
sum(predicted_label==1) = 0
Accuracy = 83.3333% (50/60) (classification)
sum(predicted_label==1) = 0
Accuracy = 63.3333% (38/60) (classification)
sum(predicted_label==1) = 16
Accuracy = 83.3333% (50/60) (classification)
sum(predicted_label==1) = 0
Accuracy = 83.3333% (50/60) (classification)
sum(predicted_label==1) = 0
Final accuracy = 11.666667 >>
这是怎么回事?我在这里做错了什么???
答案 0 :(得分:0)
在我看来,你的代码很好。 您获得低精度的原因是svm在此数据集上不能很好地工作。
正如你所看到的,在几个模型中,你的svm只是预测一切都是消极的。 这意味着它对预测正面标签没有信心。 因此,当你最终将所有概率结合起来时,准确性就会很差。
我建议你用svm尝试另一个内核来查看结果。