title: Get the top n classes and the corresponding confidence level from the libSVM package
body: <p>I'm using libsvm library (<a href="https://www.csie.ntu.edu.tw/~cjlin/libsvm/" rel="nofollow">https://www.csie.ntu.edu.tw/~cjlin/libsvm/</a>) to classify some data.</p>
  
  <p>This is the syntax that i'm using for prediction:</p>
  
  <pre><code>[predict_label, accuracy, prob_estimates] = svmpredict(lbpModel.labels(1,1), lbpModel.features(1,:), trainedModel);
  </code></pre>
  
  <p>From my understanding prob_estimates is computed this way: If you have the following classes : (class 1, 2, 3, 4), the algorithm does the following comparations:</p>
  
  <p>1 vs. 2, 1 vs. 3, 1 vs 4, 2 vs. 3, 2 vs. 4, and 3 vs. 4.</p>
  
  <p>Thus you get 6 decision values in the prob_estimates vector.</p>
  
  <p>What changes should I make to the prob_estimates vector to get something like this:</p>
  
  <pre><code>[0.7 , 0.19, 0,2, 0,1 ....]
  </code></pre>
  
  <p>It can be translated to:
  Class1 = 70%, Class2 19%, Class3 2%, Class4 1% etc.</p>
  
  <p>So basically I want to extract the top 3 predicted classes and I need to know the confidence level (%). Because if I get Class1 50%, Class2 49%, Class3 1% and Class4 0%, I don't really want to label the data with the winning class, since the difference between the confidence level for the first 2 classes is too small, so I would rather label the data with both classes (I know that for most problems it doesn't make too much sense, but for my problem it does).</p>
  
  <p>Any solution? </p>