Find Confidence in Forecasting in SVM
I am doing classification in english using SVM classifier in opencv. I can predict classes using a function predict()
. But I want to get confidence in the forecast between 0-1. Can anyone provide a method for this 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);
source to share
The SVM tries to find the dividing hyperplane during training, so the train examples lie on different sides. There may be many such hyperplanes (or not), therefore, to select the "best" one, we are looking for the one for which the maximum distance from all classes is maximum. Indeed, the farther from the point of the hyperplane, the more confident we are in this solution. So, we are interested in the distance to the hyperplane.
According to OpenCV documentation , CvSVM::predict
has a second default argument that specifies what to return. By default, it returns the grading mark, but you can go to true
and it will return the distance.
Distance itself is pretty good, but if you want to have a confidence value in the range (0, 1), you can apply the sigmoidal function to the result.One such function is if the logistic function.
decision = svmob.predict(testData, true);
confidence = 1.0 / (1.0 + exp(-decision));
source to share