我在 WEKA 中创建了一个分类器,我将它保存在我的硬盘上,现在我想在 eclipse 中使用 weka api 使用该分类器。
我该怎么做?请指导我...谢谢
最佳答案
这是一个加载模型以预测实例值的示例。示例模型是在 Weka Explorer 中创建和保存的 J48 决策树。它是根据 Weka 提供的名义天气数据构建的。它被称为“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 和序列化的一个很好的初学者资源是 here!
关于java - 如何在 eclipse java 中重用从资源管理器(在 weka 中)创建的已保存分类器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20017957/