title: WEKA: get the class from classifyInstance,why it's wrong
body: <p>I train and create a J48 model use WEKA Java Api.
  Then, I use classifyInstance() to classify my instance.
  but the result is wrong.
  my code id following:</p>
  
  <pre><code>    Instances train = reader.getDataSet();
      Instances test = reader_test.getDataSet();
  
      train.setClassIndex(train.numAttributes() - 1);
      Classifier cls = new J48();
      cls.buildClassifier(train);
  
      test.setClassIndex(test.numAttributes() - 1);
  
      for(int i = 0; i &lt; test.numInstances(); i++){
          Instance inst = test.instance(i);
          double result = cls.classifyInstance(inst);
          System.out.println(train.classAttribute().value((int)r));
      }
  </code></pre>
  
  <p>The result always equal 0.0</p>
  
  <p>Finally, I use test.insertAttributeAt() before test.setClassIndex().
  as following:</p>
  
  <pre><code>test.insertAttributeAt(train.attribute(train.numAttributes() - 1), test.numAttributes());
  </code></pre>
  
  <p>The result become right. I am very surprising!
  however, most documents are not use the function to inserAttribute.
  I want to understand why the result become right suddenly.</p>