简体   繁体   English

libsvm的准确性不正确

[英]accuracy of libsvm is not right

I am doing libsvm as shown there: 我正在做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);

I got accuracy always above 80% (~83%), and sum of predicted label of each iteration is almost zero, and final accuracy is 11%. 我的准确度始终高于80%(〜83%),每次迭代的预测标签总和几乎为零,最终准确度为11%。 As shown below: 如下所示:

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

How this happens ? 这是怎么发生的? What I am doing wrong here ??? 我在这里做错了什么?

In my opinion, your code is fine. 我认为您的代码很好。 The reason you get the low accuracy is that svm does not work well on this dataset. 准确性低的原因是svm无法在此数据集上很好地工作。

As you can see, in several model, your svm just predicts everything to be negative. 如您所见,在几个模型中,您的svm只是预测一切都是负面的。 This means it is not that confident for predicting the positive label. 这意味着对阳性标记的预测并不那么自信。 Therefore, when you combine all the probability in the end, the accuracy is bad. 因此,当最终将所有概率组合在一起时,准确性很差。

I suggest you to try another kernel with svm to see the result. 我建议您使用svm尝试另一个内核以查看结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM