How to test existing model with new instance in we

2020-02-20 07:00发布

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

标签: java weka
2条回答
叛逆
2楼-- · 2020-02-20 07:28

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);
查看更多
看我几分像从前
3楼-- · 2020-02-20 07:33

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

查看更多
登录 后发表回答