我在WEKA中对单个实例进行分类存在问题,这是我的代码:
public void addInstance() throws Exception {
Scanner s = new Scanner(System.in);
DenseInstance newInstance = new DenseInstance(m_Training.numAttributes());
for(int i = 0 ; i < m_Training.numAttributes()-1 ; i++)
{
double value = s.nextDouble();
newInstance.setValue(i , value);
//i is the index of attribute
//value is the value that you want to set
}
newInstance.setValue(m_Training.numAttributes()-1, Float.NaN);
//add the new instance to the main dataset at the last position
m_Training.add(newInstance);
// Print header and instances.
System.out.println("\nDataset:\n");
System.out.println(m_Training);
System.out.print("\n\nClassification result : ");
System.out.println(m_Classifier.classifyInstance(m_Training.instance(150)));
System.out.println(m_Training.instance(150));
System.out.println(m_Training.classAttribute().value((int)m_Classifier.classifyInstance(m_Training.instance(150))));
}
但它总是给出0.0的结果。我已经阅读了这个教程:weka: how to get class name from testing single instance但是,程序只给了我0.0,类名总是“iris-setosa”。
我在这个程序中使用了Iris.arff,而分类器(m_classifier)是J48。我不知道为什么它不起作用,任何帮助赞赏