在SVM中找到预测的可信度 [英] Find confidence of prediction in SVM

查看:853
本文介绍了在SVM中找到预测的可信度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在opencv中使用SVM分类器进行英文数字分类。
我可以使用 predict()函数预测类。
但是我想在0-1之间得到预测的信心。可以有人提供一个方法来使用opencv

  //使用svm参数
m_params.svm_type = CvSVM :: C_SVC;
m_params.kernel_type = CvSVM :: RBF
m_params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER,500,1e-8);

//用于训练
svmob.train_auto(m_features,m_labels,cv :: Mat(),cv :: Mat(),m_params,10)

// for prediction
predicted = svmob.predict(testData);训练期间的SVM尝试找到一个分离超平面,如下所示:(1) trainset例子躺在不同的面。可能有许多这样的超平面(或没有),因此为了选择最好,我们寻找与所有类的总距离最大化的那个。事实上,远离超平面点的位置 - 我们对决策的信心越大。所以我们感兴趣的是到超平面的距离。



按照OpenCV 文档 CvSVM :: predict 有一个默认的第二个参数,指定要返回的内容。默认情况下,它返回分类标签,但您可以传入 true ,它将返回距离。



距离本身确实很好,但如果你想在一个范围(0,1)中有一个置信度值,你可以应用 sigmoidal 函数。

  decision = svmob.predict(testData,true); 
confidence = 1.0 /(1.0 + exp(-decision));


I am doing English digit classification using SVM classifier in opencv. I am able to predict the classes using predict() function. But I want get confidence of prediction between 0-1. Can somebody provide a method to do it using opencv

 //svm parameters used
 m_params.svm_type    = CvSVM::C_SVC;
 m_params.kernel_type = CvSVM::RBF;
 m_params.term_crit   = cvTermCriteria(CV_TERMCRIT_ITER, 500, 1e-8);

 //for training
 svmob.train_auto(m_features, m_labels, cv::Mat(), cv::Mat(), m_params, 10);

 //for prediction
 predicted = svmob.predict(testData);

解决方案

SVM during training tries to find a separating hyperplane such that trainset examples lay on different sides. There could be many such hyperplanes (or none), so to select the "best" we look for the one for which total distance from all classes are maximized. Indeed, the further away from the hyperplane point is located — the more confident we are in the decision. So what we are interested in is distance to the hyperplane.

As per OpenCV documentation, CvSVM::predict has a default second arguments which specifies what to return. By default, it returns classification label, but you can pass in true and it'll return the distance.

The distance itself is pretty ok, but if you want to have a confidence value in a range (0, 1), you can apply sigmoidal function to the result. One of such functions if logistic function.

decision = svmob.predict(testData, true);
confidence = 1.0 / (1.0 + exp(-decision));

这篇关于在SVM中找到预测的可信度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆