title: using the saved model for predicting using weka (Eclipse+Java)
body: <p>I was confused with the arguments of the lines "Instances originalTrain=" can anyone please help me to correct this error since I was new to this weka. We are creating a disease prediction system using weka in java.</p>
  
  <pre><code>import weka.classifiers.Classifier;
  import weka.core.Instances;
  
  public class Main {
  
      public static void main(String[] args) throws Exception
      {
          String rootPath="/some/where/"; 
          Instances originalTrain= //instances here (don't know to complete this statement)
  
          //load model
          Classifier cls = (Classifier) weka.core.SerializationHelper.read(rootPath+"tree.model");
  
          //predict instance class values
          Instances originalTrain= //load or create Instances to predict (This statement too)
  
          //which instance to predict class value
          int s1=0;
  
          //perform your prediction
          double value=cls.classifyInstance(originalTrain.instance(s1));
  
          //get the prediction percentage or distribution
          double[] percentage=cls.distributionForInstance(originalTrain.instance(s1));
  
          //get the name of the class value
          String prediction=originalTrain.classAttribute().value((int)value); 
  
          System.out.println("The predicted value of instance "+
                              Integer.toString(s1)+
                              ": "+prediction); 
  
          //Format the distribution
          String distribution="";
          for(int i=0; i &lt;percentage.length; i=i+1)
          {
              if(i==value)
              {
                  distribution=distribution+"*"+Double.toString(percentage[i])+",";
              }
              else
              {
                  distribution=distribution+Double.toString(percentage[i])+",";
              }
          }
          distribution=distribution.substring(0, distribution.length()-1);
  
          System.out.println("Distribution:"+ distribution);
      }
  
  }
  </code></pre>