2

I am looking for a way to get the prediction confidence for a multi-class prediction with an opencv SVM. What I found so far:

//data is a cv::Mat containing the samples to be predicted in format (num_samples,dimension,CV_32F)
//SVM_classifier is a trained opencv SVM classifier
cv::Mat predLabels(data.rows,1,CV:32F);
cv::Mat predProb(data.rows,1,CV_32F);
predProb = SVM_classifier->predict(data,predLabels,cv::ml::StatModel::RAW_OUTPUT);

Executing this code, I get pretty good prediction results (Fmeasure around 0.95), but the predProb matrix only contains '0' ... Can someone help me to get the correct results? Is the issue that I have a multi-class problem instead of a binary problem?

Also what is the difference in using cv::ml::StatModel::RAW_OUTPUT instead of cv::ml::SVM::Flags::RAW_OUTPUT? No matter which one I use, I get a vector filled with zeros as result... Any help is appreciated!!

Seastar
  • 386
  • 2
  • 19
  • I can answer your last question, both flags are the same. First of all is an enum, so you pass an int, so you can even pass 1 and it will be the same. Second, in the [documentaiton](https://docs.opencv.org/trunk/d1/d2d/classcv_1_1ml_1_1SVM.html#ab4b93a4c42bbe213ffd9fb3832c6c44f) it says that SVM derives from StatModel... and that the flags are inherited. In conclusion, both are exactly the same. About your first question, I can't answer, since I have not tried OpenCV SVM. The only thing I see is that data is not initialized here. Also, have you already trained the SVM? – api55 Nov 10 '17 at 10:25
  • Thanks for the first answer! I updated my question according to your other questions: To improve visibility, I only wrote down part of the code, which is causing my problems:) My classifier is trained and gives good prediction results. The data matrix is filled with data... – Seastar Nov 10 '17 at 10:30

0 Answers0