如何将WEKA中的分类器Model提取出来
2015-09-21 16:00
316 查看
源自:http://weka.wikispaces.com/Serialization最近的一个项目涉及到一些数据挖掘的内容, 因此,接触了WEKA,不得不承认,对于菜鸟来说,WEKA,确实是一个很不错的工具。他的好处太多了,不一一赘述,刚开始,就有个以为就是,用WEKA训练好的model,以后如何使用,这次知道了,看如下翻译:Serialization isthe process of saving an object in a persistent form, e.g., on the harddisk as a bytestream. Deserialization isthe process in the opposite direction, creating an object from a persistently saved data structure.In Java,an object can be serialized if it imports the java.io.Serializable interface. 这里面主要是说串行化和反串行化,这个是讲类成员信息存储到字符串,然后存下来,毫无争议。Members of an object that are not supposed to be serialized, need to be prefixed with the keyword transient.In the following you'll find some Java code snippets for serializing and deserializing a J48 classifier.Of course, serialization is not limited to classifiers. Most schemes in Weka, like clusterers and filters, are also serializable.
Serializing
Here we create a J48 classifier cls,train it with a dataset /some/where/data.arff, and save the built model to a file /some/where/j48.model.下面的代码就是串行化过程。// create J48 Classifier cls = new J48(); // train Instances inst = new Instances( new BufferedReader( new FileReader("/some/where/data.arff"))); inst.setClassIndex(inst.numAttributes() - 1); cls.buildClassifier(inst); // serialize model ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream("/some/where/j48.model")); oos.writeObject(cls); oos.flush(); oos.close();Note:In versions > 3.5.5 this is even easier. The last couple of lines shrink to this:如下是高版本中,更简洁的方法。
// serialize model weka.core.SerializationHelper.write("/some/where/j48.model", cls);
Deserializing
Here the previously saved model is deserialized as cls andagain available for classification.// deserialize modelObjectInputStream ois = new ObjectInputStream(new FileInputStream("/some/where/j48.model"));Classifier cls = (Classifier) ois.readObject();ois.close();Note:With versions > 3.5.5 it is even easier:// deserialize modelClassifier cls = (Classifier) weka.core.SerializationHelper.read("/some/where/j48.model");
相关文章推荐
- setContentView(R.Layout.main)的意思
- SGU 001
- 孤儿进程与僵尸进程的理解
- 定位 - CoreLocation - 指南针
- mac git xcrun error active developer path 错误
- 用route命令添加永久路由
- 去哪儿网试题有点问题1
- myEclipse报“error retrieving AST from Provider”错误
- 数据库性能复习
- 软件版本号整理
- 将博客搬至CSDN
- ThinkPHP 伪静态问题
- HTML5下的WebSocket学习笔记
- Spring的事务 之 9.4 声明式事务 ——跟我学spring3
- 求二叉树中每一个节点对应的层次
- 技术团队如何招聘和管理
- Android开源组件SlidingMenu的基本使用方法和SlidingMenuDemo
- ubuntu下sudo apt-get update Sources 404 Not Found [IP: 91.189.92.200 80]解决办法
- XCode7和ios9的兼容和更新问题解决方案
- count and say