How to reuse a saved classifier created from explorer (in weka) in eclipse java

I created a classifier in WEKA, I saved it on my hard drive, now I want to use this classifier in eclipse using weka api.

How can i do this? please direct me to this ... thanks

+6
source share
1 answer

The following is an example of loading a model to predict the value of instances. An example model is a J48 decision tree created and saved in Weka Explorer. It was built from weather data provided by Weka. It is called "tree.model".

//load model String rootPath="/some/where/"; Classifier cls = (Classifier) weka.core.SerializationHelper.read(rootPath+"tree.model"); //predict instance class values Instances originalTrain= //load or create Instances to predict //which instance to predict class value int s1=0; //perform your prediction double value=cls.classifyInstance(originalTrain.instance(s1)); //get the name of the class value String prediction=originalTrain.classAttribute().value((int)value); System.out.println("The predicted value of instance "+ Integer.toString(s1)+ ": "+prediction); 

The way out of this:

 The predicted value of instance 0: no 

Great source for Weka api and serialization here!

+14
source

Source: https://habr.com/ru/post/958194/


All Articles