weka: how to get class name from testing single instance

风格不统一 提交于 2019-12-06 02:03:41
Sametimsi

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

Kashif Khan
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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!