如何在eclipse java中重用从explorer(在weka中)创建的已保存分类器 [英] How to reuse saved classifier created from explorer(in weka) in eclipse java
问题描述
我在WEKA中创建了一个分类器,我把它保存在我的硬盘上,现在我想在eclipse中使用weka api来使用那个分类器。
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
推荐答案
以下是加载模型以预测实例值的示例。示例模型是在Weka Explorer中创建并保存的J48决策树。它是根据Weka提供的名义天气数据建造的。它被称为tree.model。
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 predicted value of instance 0: no
Weka api的一个很好的起源资源和序列化是这里!
A great beginers resource for the Weka api and Serialization is here!
这篇关于如何在eclipse java中重用从explorer(在weka中)创建的已保存分类器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!