【发布时间】:2015-07-16 09:45:21
【问题描述】:
我使用 Weka API 和 Java 创建了一个决策树 (J48)。首先,我使用 arff 文件训练我的决策树。
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());
}
使用的 arff 文件包括 780 个实例。每个实例有 6 个属性 {PT1, w1, d1, PT2, w2, d2} 都是数字和一个类 {yes, no}。 我的代码正在运行,我可以使用
查看生成的决策树System.out.println(tree.toString());
现在,我想创建一个新实例(不使用另一个 arff 文件)并对这个新实例进行分类。假设这个新实例的值是 {50, 5, 800, 74, 3, 760}。然后决策树必须返回相应的类(“是”或“否”)。
【问题讨论】: