I've created a Decision Tree (J48) using Weka API and Java. First I train my decision tree using an arff file.
public static void Tree(String Path) throws Exception {//Path path for the arff file
J48 tree = new J48(); // new instance of tree
DataSource source = new DataSource(Path);
Instances data = source.getDataSet();
// setting class attribute if the data format does not provide this information
// For example, the XRFF format saves the class attribute information as well
if (data.classIndex() == -1) {
data.setClassIndex(data.numAttributes() - 1);
}
tree.buildClassifier(data);
System.out.println(tree.toString());
}
The used arff file includes 780 instances. Each instance has 6 attributes {PT1, w1, d1, PT2, w2, d2} all numeric and a class {yes, no}. My code is working and I can see the resulting Decision Tree using
System.out.println(tree.toString());
Now, I want to create a new Instance (not using another arff file) and classify this new instance. Say the values for this new instance are, for example, {50, 5, 800, 74, 3, 760}. Then the Decision Tree must return the corresponding class (a "yes" or a "no").