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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6979067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 18:07:09  来源:igfitidea点击:

How to test existing model with new instance in weka, using java code?

javaweka

提问by Nav Ali

I have a .model file of one of the classifier which I got through Weka GUI. Now I would like to test this model on some instance. Can anyone tell me how to do this ?

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

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

I don't want to build classifier again and again like in this code. How to do this using .model file?

我不想像这段代码那样一次又一次地构建分类器。如何使用 .model 文件执行此操作?

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

回答by ronny

Combining your code with the code found in the link provided by Omer:

将您的代码与 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);

回答by rapid2share

you shoud train your filter too if you want to predict new instances without rebuild /retrain your classifier / filter you shoud: 1) train both of them 2) save them with weka.core.SerializationHelper3) reload them in your application and make prediction

如果您想在不重建/重新训练分类器/过滤器的情况下预测新实例,您也应该训练您的过滤器,您应该:1) 训练它们 2) 保存它们 weka.core.SerializationHelper3) 在您的应用程序中重新加载它们并进行预测