我WEKA,我遇到了以下代码:
Instances train = DataSource.read(args[0]);
train.setClassIndex(train.numAttributes() - 1);
Instances test = DataSource.read(args[1]);
test.setClassIndex(test.numAttributes() - 1);
// train classifier
J48 cls = new J48();
cls.buildClassifier(train);
// output predictions
System.out.println("# - actual - predicted - distribution");
for (int i = 0; i < test.numInstances(); i++) {
double pred = cls.classifyInstance(test.instance(i));
double[] dist = cls.distributionForInstance(test.instance(i));
System.out.print((i+1) + " - ");
System.out.print(test.instance(i).toString(test.classIndex()) + " - ");
System.out.print(test.classAttribute().value((int) pred) + " - ");
System.out.println(Utils.arrayToString(dist));
}
这里的目标是在测试数据集上运行一个预先构建的分类器,然后打印实际类、预测类和类成员值分布。我理解除了一行之外的所有内容:
System.out.print(test.classAttribute().value((int) pred) + " - ");
如果“test”是一组实例,上面的语句如何能够在 for 循环中打印当前实例的预测类值?
谢谢阿布舍克 S