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

别说谁变了你拦得住时间么 提交于 2019-11-27 13:18:11

问题


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


回答1:


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!



来源:https://stackoverflow.com/questions/20017957/how-to-reuse-saved-classifier-created-from-explorerin-weka-in-eclipse-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!