Find confidence of prediction in SVM

北慕城南 提交于 2019-12-06 09:45:04

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/27738986/find-confidence-of-prediction-in-svm

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