使用 Hibernate 导入 Weka 数据
Weka data import with Hibernate
我必须在 Hibernate 的帮助下导入不同的 tables(这里是 Customer table),并将它们转换为 Weka API 可读的格式。
目前可以使用
获取数据库结果
List<Object[]> myResult = SessionUtils.getSessionFactory().getCurrentSession().createQuery(
"from Customer")
.list();
我得到一个数组列表,其中包含类型为 "Customer" 的对象。
在另一个 class 中,可以使用我的 WEKA 代码读取 arff 文件并按照我想要的方式分析数据
Instances ins = new Instances(new BufferedReader(new FileReader(".../Customer.arff")));
有没有一种简单的方法可以将 myResult 转换为我在 "Instances ins" 中需要的格式?
请询问您是否需要更多信息。
感谢阅读!
您可以像创建任何其他 Java 对象一样创建实例对象。
Instance 的 javadoc 中有一个示例 - Class:
// Create empty instance with three attribute values
Instance inst = new Instance(3);
// Set instance's values for the attributes "length", "weight", and "position"
inst.setValue(length, 5.3);
inst.setValue(weight, 300);
inst.setValue(position, "first");
要将您的集合转换为实例对象:遍历您的 myResult
-列表,为每个 Customer
创建一个新的 Instance
-对象并将其添加到您的 Instances
-通过添加方法对象。
我必须在 Hibernate 的帮助下导入不同的 tables(这里是 Customer table),并将它们转换为 Weka API 可读的格式。 目前可以使用
获取数据库结果List<Object[]> myResult = SessionUtils.getSessionFactory().getCurrentSession().createQuery(
"from Customer")
.list();
我得到一个数组列表,其中包含类型为 "Customer" 的对象。
在另一个 class 中,可以使用我的 WEKA 代码读取 arff 文件并按照我想要的方式分析数据
Instances ins = new Instances(new BufferedReader(new FileReader(".../Customer.arff")));
有没有一种简单的方法可以将 myResult 转换为我在 "Instances ins" 中需要的格式? 请询问您是否需要更多信息。 感谢阅读!
您可以像创建任何其他 Java 对象一样创建实例对象。 Instance 的 javadoc 中有一个示例 - Class:
// Create empty instance with three attribute values
Instance inst = new Instance(3);
// Set instance's values for the attributes "length", "weight", and "position"
inst.setValue(length, 5.3);
inst.setValue(weight, 300);
inst.setValue(position, "first");
要将您的集合转换为实例对象:遍历您的 myResult
-列表,为每个 Customer
创建一个新的 Instance
-对象并将其添加到您的 Instances
-通过添加方法对象。