Question

i want to make a single test for single instance

i use j48 in FilteredClassifier like this:

Remove rm = new Remove();
rm.setAttributeIndices("1"); // remove 1st attribute
// classifier
J48 j48 = new J48();
j48.setUnpruned(true); // using an unpruned J48

// meta-classifier
FilteredClassifier fc_J48 = new FilteredClassifier();
fc_J48.setFilter(rm);
fc_J48.setClassifier(j48);
tdta.dataSet.setClassIndex(tdta.dataSet.numAttributes() - 1);
fc_J48.buildClassifier(tdta.dataSet);

now, i try those options:

j48.classifyInstance(dataSet.instance(1))

or

eval.evaluateModelOnce(j48, dataSet.instance(1))

i think it's will be the same result.

my question is: when i get the double number, how can i translate it to the class name ?

Was it helpful?

Solution

Try this:

System.out.println(dataSet.classAttribute().value((int) j48.classifyInstance(dataSet.instance(1)));

Take a look at: http://weka.8497.n7.nabble.com/Predicting-in-java-td27363.html

OTHER TIPS

for (int i = 0; i < test.numInstances(); i++) {
  double pred = fc.classifyInstance(test.instance(i));
  System.out.print("ID: " + test.instance(i).value(0));
  System.out.print(", actual: " + test.classAttribute().value((int)         test.instance(i).classValue()));
 System.out.println(", predicted: " + test.classAttribute().value((int) pred));

}

test is testInstances, so if you have a single instance you can replace test.instance(i) with your instance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top