weka:如何通过测试单个实例来获取类名

问题描述 投票:3回答:2

我想为单个实例进行单一测试

我在FilteredClassifier中使用j48,如下所示:

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);

现在,我尝试这些选项:

j48.classifyInstance(dataSet.instance(1))

要么

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

我认为这将是相同的结果。

我的问题是:当我得到双号时,我怎么能把它翻译成班级名?

java testing classification weka evaluate
2个回答
2
投票

试试这个:

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

看看:http://weka.8497.n7.nabble.com/Predicting-in-java-td27363.html


1
投票
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));

}

testtestInstances,所以如果你有一个实例,你可以用你的实例替换test.instance(i)

© www.soinside.com 2019 - 2024. All rights reserved.