简体   繁体   中英

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

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);

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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM