java - 如何在 eclipse java 中重用从资源管理器(在 weka 中)创建的已保存分类器

标签 java machine-learning artificial-intelligence weka

我在 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/

相关文章:

python - Keras 中自定义层的 trainable_variables 属性返回空列表

c++ - 列表迭代器不可取消引用运行时

java - JFrame + Canvas : why do I get a NUllPointerException when calling glViewport?

java - 具有 Activity 配置文件的 Spring Batch 仍在寻找 Application.properties

python - TensorFlow 估计器 DNNClassifier 无法进行 2 次线性分离

azure - 在 Azure 机器学习中,日志文件存储在哪里?

ide - 您希望在 IDE 中看到哪些人工智能驱动的功能?

artificial-intelligence - 进化计算中的适应度共享和生态位计数是什么?

java - .equals() 方法是否适用于 StringBuilder?

java - WebSphere,多场 war 的相同上下文根