Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

weka

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);
like image 644
Nav Ali Avatar asked Aug 08 '11 07:08

Nav Ali


1 Answers

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);
like image 68
ronny Avatar answered Nov 02 '22 15:11

ronny