title: How do I test an OpenCV SVM?
body: <p>I have used the OpenCV SVM from this example <a href="http://docs.opencv.org/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.html" rel="nofollow">http://docs.opencv.org/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.html</a>.</p>
  
  <p>Now I need to test the accuracy of this SVM for my predicted values.This is the part of my code for predicting the accuracy of the SVM.</p>
  
  <pre><code>void svm(cv::Mat&amp; trainingDataMat, cv::Mat&amp; labelsMat, cv::Mat&amp; Testdata) {
  int t=0;
  int f=0;
  int Acc;
   CvSVMParams params;
  params.svm_type    = CvSVM::C_SVC;
  params.kernel_type = CvSVM::LINEAR;
  params.term_crit   = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);
  CvSVM SVM;
  SVM.train(trainingDataMat, labelsMat, Mat(), Mat(), params);
  cv::Mat predicted(1,1, CV_32F);
  
  for(int i = 0; i &lt; Testdata.rows; i++) {
      cv::Mat sample = Testdata.row(i);
      predicted.at&lt;float&gt;(i,0)= SVM.predict(sample);
      float p = predicted.at&lt;float&gt;(i,0);
  
      if (p &gt; 0.0) || p&lt;0.0) {
          t++;
      }
      else {
          f++;
      }
  
      Acc=(t*1.0)/(t+f);
      }
    cout &lt;&lt; "Accuracy_{SVM} = " &lt;&lt;Acc &lt;&lt; endl;
     }
  </code></pre>
  
  <p>I am trying to test a single test data at a time and find out whether each column in a row belongs to the positive or negative side of a trained classifier and its accuracy of prediction.</p>
  
  <p>The problem I am facing with this code is that the percentage of prediction is always shown as 100.</p>
  
  <p>I find this a little odd and would like someone to help me in this matter?</p>