Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have created a classifier in WEKA, i saved it on my hard-disk, now I want to use that classifier in eclipse using weka api.

How can i do this? please guide me to this... thank you

like image 273
Mr_Hmp Avatar asked Nov 16 '13 11:11

Mr_Hmp


People also ask

How can I use Weka software for data mining?

Let's Start WekaClick the “Explorer” button to launch the Weka Explorer. This GUI lets you load datasets and run classification algorithms. It also provides other features, like data filtering, clustering, association rule extraction, and visualization, but we won't be using these features right now.

What is Java Weka?

Weka is a collection of machine learning algorithms for data mining tasks. It contains tools for data preparation, classification, regression, clustering, association rules mining, and visualization. Found only on the islands of New Zealand, the Weka is a flightless bird with an inquisitive nature.

Is Weka used for machine learning?

Weka is a collection of machine learning algorithms for data mining tasks. The algorithms can either be applied directly to a dataset or called from your own Java code. Weka contains tools for data pre-processing, classification, regression, clustering, association rules, and visualization.


1 Answers

Here is an example of loading a model to predict the value of instances. The example model is a J48 decision tree created and saved in the Weka Explorer. It was built from the nominal weather data provided with 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 output from this is:

The predicted value of instance 0: no  

A great beginers resource for the Weka api and Serialization is here!

like image 109
Walter Avatar answered Nov 15 '22 19:11

Walter