title: How to print out the predicted class after cross-validation in WEKA
body: <p>Once a 10-fold cross-validation is done with a classifier, how can I print out the prediced class of every instance and the distribution of these instances? </p>
  
  <pre><code>J48 j48 = new J48();
  Evaluation eval = new Evaluation(newData);
  eval.crossValidateModel(j48, newData, 10, new Random(1));
  </code></pre>
  
  <p>When I tried something similar to below, it said that <em>the classifier is not built</em>.</p>
  
  <pre><code>for (int i=0; i&lt;data.numInstances(); i++){
     System.out.println(j48.distributionForInstance(newData.instance(i)));
   }
  </code></pre>
  
  <p>What I'm trying to do is the same function as in the WEKA GUI wherein once a classifier is trained, I can click on <code>Visualize classifier error" &gt; Save</code>, and I will find the predicted class in the file. But now I need it in to work in my own Java code. </p>
  
  <hr>
  
  <p>I have tried something like below:</p>
  
  <pre><code>J48 j48 = new J48();
  Evaluation eval = new Evaluation(newData);
  StringBuffer forPredictionsPrinting = new StringBuffer();
  weka.core.Range attsToOutput = null;
  Boolean outputDistribution = new Boolean(true);
  eval.crossValidateModel(j48, newData, 10, new Random(1), forPredictionsPrinting, attsToOutput, outputDistribution);
  </code></pre>
  
  <p>Yet it prompts me the error:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: java.lang.StringBuffer cannot be cast to weka.classifiers.evaluation.output.prediction.AbstractOutput
  </code></pre>