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

*爱你&永不变心* 提交于 2019-12-30 00:16:15

问题


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 ?

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?

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

回答1:


Combining your code with the code found in the link provided by 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);



回答2:


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.SerializationHelper 3) reload them in your application and make prediction



来源:https://stackoverflow.com/questions/6979067/how-to-test-existing-model-with-new-instance-in-weka-using-java-code

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