如何使用java代码在weka中使用新实例测试现有模型?

我有一个通过Weka GUI获得的分类器之一的.model文件。 现在我想在某个实例上测试这个模型。 谁能告诉我怎么做?

Classifier cModel = (Classifier)new NaiveBayes(); cModel.buildClassifier(isTrainingSet); 

我不想像在这段代码中一次又一次地构建分类器。 如何使用.model文件?

  // Test the model Evaluation eTest = new Evaluation(isTrainingSet); eTest.evaluateModel(cModel, isTrainingSet); 

将您的代码与Omer提供的链接中的代码结合起来:

 Classifier cModel = (Classifier)new NaiveBayes(); cModel.buildClassifier(isTrainingSet); weka.core.SerializationHelper.write("/some/where/nBayes.model", cModel); Classifier cls = (Classifier) weka.core.SerializationHelper.read("/some/where/nBayes.model"); // Test the model Evaluation eTest = new Evaluation(isTrainingSet); eTest.evaluateModel(cls, isTrainingSet); 

如果你想要预测新的实例而不需要重建/重新训练你的分类器/filter,你也应该训练你的filter:1)训练它们2)用weka.core.SerializationHelper保存它们3)在你的应用程序中重新加载它们并做出预测