Prefer one class in libsvm (python)

拜拜、爱过 提交于 2019-12-12 22:21:43

问题


I just started playing a bit with libsvm in python and got some simple classification to work.

The problem is that I'm constructing a face detection system, and I want a very low false rejection rate. The svm on the other hand seems to optimize for equal false rejection and false acceptance. What options do I have here?

And as a said earlier, I'm very new to libsvm, so be kind. ;)


回答1:


SVMs are not usually thought of as a probabilistic model, but a maximally-discriminant model. Thus I have a hard time formulating your question in the context of what I know of SVMs.

In addition, the Python bindings that come with libSVM are not terribly performant and don't expose all the options of libSVM.

That said, if you are willing to look at other bindings, the scikit-learn's svm bindings are richer and expose some parameters that may come in handy, such as weighted classes, or weighted samples. You might be able to put more emphasis on the class for which you do not want mis-classification.

In addition, the scikit's binding expose a posterior classification probability, but in the case of SVMs, I believe that it relies on a hack (as SVMs are not probabilistic) of libSVM that resamples the classification to have a confidence interval on the prediction.




回答2:


I've been using the python wrapper for libSVM and found I could compute a confidence-measure using the margin... see the "predict_values_raw" function below. It returns a real value, with large positive values indicating high confidence that it IS a class member, large negative values indicating high confidence that it IS NOT a class member; values close to zero indicate that it is not confident about the classification. So instead of calling 'predict', call 'predict_values_raw' and apply a low threshold (e.g. -2) to ensure you don't reject any true faces

# Begin pseudo-code
import svm as svmlib

prob = svmlib.svm_problem(labels, data)
param = svmlib.svm_parameter(svm_type=svmlib.C_SVC, kernel_type = svmlib.RBF)
model = svmlib.svm_model(prob, param)

# get confidence
self.model.predict_values_raw(sample_to_classify)


来源:https://stackoverflow.com/questions/4756937/prefer-one-class-in-libsvm-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!