ArrayIndexOutOfBoundsException when classifying an instance
dnes <[email protected]>
| Newsgroups | gmane.comp.ai.weka |
|---|---|
| Message-ID | <[email protected]> |
Hi everyone.
I am trying to classify instances and code is given below.
public void prepare_data() throws IOException {
BufferedReader buf_reader=new BufferedReader(new
FileReader(this.train_file));
Instances train_data = new Instances(buf_reader);
train_data.setClassIndex(train_data.numAttributes() - 1);
this.train=train_data;
buf_reader.close();
buf_reader=new BufferedReader(new FileReader(this.test_file));
Instances test_data = new Instances(buf_reader);
test_data.setClassIndex(test_data.numAttributes() - 1);
this.test=test_data;
buf_reader.close();
}
public void filteredFier() throws Exception {
System.out.println("hi"+ this.train.equalHeaders(this.test));
NumericToNominal nn = new NumericToNominal();
String[] options= {"-R", "first-last"};
nn.setOptions(options);
nn.setInputFormat(this.train);
this.rf=new RandomForest();
this.fc = new FilteredClassifier();
this.fc.setFilter(nn);
this.fc.setClassifier(this.rf);
this.fc.buildClassifier(this.train);
Evaluation eval=new Evaluation(this.train);
eval.crossValidateModel(this.fc,this.train,10,new Random(1));
System.out.println(eval.toSummaryString());
}
public void get_accuracy() throws Exception {
for (int i = 0; i < this.test.numInstances(); i++) {
double clsLabel = this.fc.classifyInstance(this.test.instance(i));
System.out.println(clsLabel);
}
}
I get ArrayIndexOutOfBoundException. Somebody here knows solution, I need
your help. Thank you in advance.
--
Sent from: https://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list -- [email protected]
Send posts to [email protected]
To unsubscribe send an email to [email protected]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html