我正在使用 WEKA API weka-stable-3.8.1。
我一直在尝试使用J48决策树(weka 的 C4.5 实现)。
我的数据包含大约 22 个特征和一个具有 2 个可能值的标称类:是 或否。
使用以下代码进行评估时:
Classifier model = (Classifier) weka.core.SerializationHelper.read(trainedModelDestination);
Evaluation evaluation = new Evaluation(trainingInstances);
evaluation.evaluateModel(model, testingInstances);
System.out.println("Number of correct predictions : "+evaluation.correct());
我所有预测都是正确的。
但是当我使用以下命令单独尝试这些测试用例时:
for(Instance i : testingInstances){
double predictedClassLabel = model.classifyInstance(i);
System.out.println("predictedClassLabel : "+predictedClassLabel);
}
我总是得到相同的输出,即 0.0。
为什么会发生这种情况?
最佳答案
如果提供的代码片段确实来自您的代码,则您似乎总是对第一个测试实例进行分类:“testingInstances.firstInstance()”。
相反,您可能想要创建一个循环来对每个测试实例进行分类。
for(Instance i : testingInstances){
double predictedClassLabel = model.classifyInstance(i);
System.out.println("predictedClassLabel : "+predictedClassLabel);
}
关于java - 使用 Weka 进行错误的类别预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44904420/