java - ArrayList conversion to Instances object -


i ve got arraylist testset. list contains data smo evaluation in weka. want use evaluation weka class in order classify testset. in simpliest case, had features extracted 1 image in arraylist. conversion must done in order use list in following:

evaluation eval = new evaluation(testset); // how can cast testset2 instances object? eval.evaluatemodelonce(c, data); 

this code found here: using in order train smo model. train dataset contains feature extracted train images, stored in .arff file. in test process reading in code image calculate features, stored them in arraylist without stored them in .arff files. want cast list directly instances object , proceed classification.

edit: ve tried else, first connvert arraylist array double data , proceed proceed trainset:

int numatts = data[0].length; fastvector atts = new fastvector(numatts); (int att = 0; att < numatts; att++) {  atts.addelement(new attribute("attribute" + att, att)); }  int numinstances = data.length; instances dataset = new instances("dataset", atts, numinstances); (int inst = 0; inst < numinstances; inst++) { dataset.add(new instance(1.0, data[inst])); } 

however received :

exception in thread "main" java.lang.classcastexception: javax.management.attribute cannot cast weka.core.attribute 

edit:

i change little 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); (int att = 0; att < numatts; att++) {  atts.addelement(new weka.core.attribute("attribute" + att, att)); }  int numinstances = data.length; instances dataset = new instances("dataset", atts, numinstances); (int inst = 0; inst < 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)); 

i getting error:

exception in thread "main" java.lang.arrayindexoutofboundsexception: 84 @ weka.filters.unsupervised.attribute.replacemissingvalues.convertinstance(replacemissingvalues.java:274) @   weka.filters.unsupervised.attribute.replacemissingvalues.input(replacemissingvalues.java:140      ) @ weka.classifiers.functions.smo.distributionforinstance(smo.java:1368) @ weka.classifiers.classifier.classifyinstance(classifier.java:84) @     weka.classifiers.evaluation.evaluatemodelonceandrecordprediction(evaluation.java:1448) @ weka.classifiers.evaluation.evaluatemodel(evaluation.java:1407) @ lbp.lbpdemo.main(lbpdemo.java:466) 

edit2: problem ve got add in last attribute classes labels, trying add :

atts.addelement(new weka.core.attribute(" class {1, 2, 3, 4, 5, 6, 7}" , numatts-1)); 

which indexes fo problem. however, isn't proper way add indexes dataset. when println dataset in last attribute get:

@attribute ' class {1, 2, 3, 4, 5, 6, 7}' numeric 

i want erase apostrophes , numeric in order read properly.

assuming need instances object, cannot cast arraylist that.

i think need use datasource's getdataset() custom loader (constructor).

i guess should work this:

new datasource(new listloader(testdata)).getdataset(); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -