title: ArrayList conversion to Instances object
body: <p>I ve got an ArrayList testset. This list contains my data for SMO evaluation in WEKA. I want to use Evaluation weka class in order to classify my testset. In simpliest case, I had a features extracted by only one image in a ArrayList. What conversion it must be done in order to use my list in the following:</p>
  
  <pre><code>Evaluation eval = new Evaluation(testset); // how can I cast testset2 Instances object?
  eval.evaluateModelOnce(c, data);
  </code></pre>
  
  <p>This code found from  <a href="https://stackoverflow.com/questions/9451651/smo-sequential-minimal-optimization-in-weka">here</a>: I am using it in order to train a SMO model. Train dataset contains feature extracted train  images, stored in an .arff file. In test process I am reading in my code an image I calculate the features, stored them in arrayList without stored them in .arff files. I want to cast the list directly to Instances object and proceed with classification. </p>
  
  <p>EDIT: I ve tried to do something else, first connvert arrayList to array double data and to proceed as  I proceed for my trainSet:</p>
  
  <pre><code>int numAtts = data[0].length;
  FastVector atts = new FastVector(numAtts);
  for (int att = 0; att &lt; numAtts; att++) {
   atts.addElement(new Attribute("Attribute" + att, att));
  }
  
  int numInstances = data.length;
  Instances dataset = new Instances("Dataset", atts, numInstances);
  for (int inst = 0; inst &lt; numInstances; inst++) {
  dataset.add(new Instance(1.0, data[inst]));
  }
  </code></pre>
  
  <p>However I am received :</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: javax.management.Attribute cannot be cast to weka.core.Attribute
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I change a little my code</p>
  
  <pre><code>double data[][] = new double[1][];
  data[0] = dt;
  
  System.out.println(args[1]);
  System.out.println(args[2]);
  ClothesAnalysis asdf = new ClothesAnalysis();
  weka.classifiers.Classifier c = asdf.loadModel(new File(args[1]), args[2]);
  
  
  String opt = ("-C 100 -K weka.classifiers.functions.supportVector.NormalizedPolyKernel");
      String[] options = opt.split(" ");
  
  int numAtts = data[0].length;
  FastVector atts = new FastVector(numAtts);
  for (int att = 0; att &lt; numAtts; att++) {
   atts.addElement(new weka.core.Attribute("Attribute" + att, att));
  }
  
  int numInstances = data.length;
  Instances dataset = new Instances("Dataset", atts, numInstances);
  for (int inst = 0; inst &lt; numInstances; inst++) {
   dataset.add(new Instance(1.0, data[inst]));
  }
  
  dataset.setClassIndex(dataset.numAttributes() - 1);
  
  Evaluation eval = new Evaluation(dataset);
  
  eval.evaluateModel(c, dataset);
  System.out.println(eval.toSummaryString("\nResults\n======\n", false));
  </code></pre>
  
  <p>I am getting error:</p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 84
  at weka.filters.unsupervised.attribute.ReplaceMissingValues.convertInstance(ReplaceMissingValues.java:274)
  at   weka.filters.unsupervised.attribute.ReplaceMissingValues.input(ReplaceMissingValues.java:140
       )
  at weka.classifiers.functions.SMO.distributionForInstance(SMO.java:1368)
  at weka.classifiers.Classifier.classifyInstance(Classifier.java:84)
  at  
    weka.classifiers.Evaluation.evaluateModelOnceAndRecordPrediction(Evaluation.java:1448)
  at weka.classifiers.Evaluation.evaluateModel(Evaluation.java:1407)
  at LBP.LBPDemo.main(LBPDemo.java:466)
  </code></pre>
  
  <p>EDIT2: My problem is that I ve got to add in the last attribute the classes labels, so I am trying to add :</p>
  
  <pre><code>atts.addElement(new weka.core.Attribute(" class {1, 2, 3, 4, 5, 6, 7}" , numAtts-1));
  </code></pre>
  
  <p>which are the indexes fo my problem. However, this isn't the proper way to add indexes to dataset. When I println the dataset in the last Attribute I get:</p>
  
  <pre><code>@attribute ' class {1, 2, 3, 4, 5, 6, 7}' numeric
  </code></pre>
  
  <p>I want to erase apostrophes and numeric in order to be read properly.</p>