Loding weka model for java code

I saved the weka classification result by right-clicking on the model and selecting "save model". Now I want to download it and work in my "JAVA" application. How can i do this? Models may include Naiva deviations, Decision Tree, and regression. I need to use these three models.

Any suggestion or solution would be appreciated.

Thanks.

+6
source share
2 answers

Here is an example assuming you have a RandomTree model saved in model.weka file (change to any classifier and file that you have)

 RandomTree treeClassifier = (RandomTree) SerializationHelper.read(new FileInputStream("model.weka"))); 
+9
source

If you saved the model in a file in WEKA, you can use it to read the generated Java object. Here is an example with the Random Forest classifier (previously saved to a file in WEKA):

 RandomForest rf = (RandomForest) (new ObjectInputStream(PATH_TO_MODEL_FILE)).readObject(); 

Do not forget to import:

 import weka.core.Instance; import weka.core.Instances; import weka.core.Attribute; import weka.core.FastVector; import weka.classifiers.trees.RandomForest; 
+6
source

All Articles