title: classify all instances and get the highest probability for the positive class label in Weka
body: <p>I have weka arff instances that I created. I have to force only one positive label per dataset. This can be done in this way:</p>
  
  <pre><code>For all instances:
     get the probability of predicted class label 1,
     choose the highest probability as 1 and others 0
     if there is no class label 1:
        get lowest probability of predicted class 0
        label that as predicted class 1
        other instances prediction will be 0
     for the instance that is equal to 1, see the actual value of it's class, if it is the same, then score=score+1. 
  </code></pre>
  
  <p>I can handle the classification in weka as this: </p>
  
  <pre><code>DataSource source = new DataSource(outputFolderPath + "/" + fileName + ".arff");
  Instances data = source.getDataSet();
  if (data.classIndex() == -1)
  data.setClassIndex(data.numAttributes() - 1);
  
  Classifier cls = (Classifier) weka.core.SerializationHelper.read(mainPath+"meta.model");
  
  double prediction=cls.classifyInstance(data.instance(0));
  String actual_label=data.classAttribute().value((int)value); 
  </code></pre>
  
  <p>How can I classify all instances and how can I achieve the results I want with getting the probabilities? 
  I found sub solution in this way:</p>
  
  <pre><code>for (int j = 0; j &lt; data_test.numInstances(); j++) {
                  double prediction=cls.classifyInstance(data.instance(j));
                  double[] prob=cls.distributionForInstance(data_test.instance(j));
                  //prob[0] is probability of class 0 and prob[1] is probability of class1 
  
              }
  </code></pre>
  
  <p>Now the problem comes only to the second part. How to find the highest probable of class 1.</p>
  
  <p>Update2: I tried to store the value, prediction and the probability of class 1 in an array and sort them based on probability. </p>
  
  <pre><code>The method sort(T[], Comparator&lt;? super T&gt;) in the type Arrays is not applicable for the arguments (double[][], new Comparator&lt;Double[]&gt;(){})
  </code></pre>
  
  <p>from this code:</p>
  
  <pre><code> for (int j = 0; j &lt; data_test.numInstances(); j++) {
                  double prediction=cls.classifyInstance(data_test.instance(j));
                  //System.out.println(data_test.instance(j));
                  double[] prob=cls.distributionForInstance(data_test.instance(j));
                  //System.out.println(prediction+"---&gt;"+prob[0]+","+prob[1]);
                  //System.out.println(data_test.classAttribute().value((int) data_test.instance(j).classValue()));
  
                  arrayNumbers[j][0] = Double.parseDouble(data_test.classAttribute().value((int) data_test.instance(j).classValue()));
                  arrayNumbers[j][1] = prediction;
                  arrayNumbers[j][2] = prob[1];
  
              }
  
             //System.out.println(arrayNumbers);
              Arrays.sort(arrayNumbers, new Comparator&lt;Double[]&gt;() {
                  public int compare(Double[] s1, Double[] s2) {
                      if (s1[0] &gt; s2[0])
                          return 1;    
                      else if (s1[0] &lt; s2[0])
                          return -1;   
                      else {
  
                          return 0;
                      }
                  }
              });
  </code></pre>