Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
533 views
in Technique[技术] by (71.8m points)

machine learning - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...