如何将WEKA中的分类器Model提取出来
来源:互联网 发布:mac vm共享的文件在哪 编辑:程序博客网 时间:2024/06/05 06:15
源自:http://weka.wikispaces.com/Serialization
最近的一个项目涉及到一些数据挖掘的内容, 因此,接触了WEKA,不得不承认,对于菜鸟来说,WEKA,确实是一个很不错的工具。他的好处太多了,不一一赘述,
刚开始,就有个以为就是,用WEKA训练好的model,以后如何使用,这次知道了,看如下翻译:
Serialization is the process of saving an object in a persistent form, e.g., on the harddisk as a bytestream. Deserialization is the 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();
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 and again available for classification.// deserialize model ObjectInputStream 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 model Classifier cls = (Classifier) weka.core.SerializationHelper.read("/some/where/j48.model");
- 如何将WEKA中的分类器Model提取出来
- 如何将pdf中的图片提取出来
- 如何快速的将word文档中的图片提取出来
- 将字符串中的数字提取出来 NSScanner
- 将plist中的单图提取出来
- 将字符串中的数字提取出来 NSScanner
- .net 下如何将文档文件(Word, Pdf等) 中的文本提取出来
- 如何将word的内容提取出来转成txt
- 将任意字符串中的汉字提取出来的方法
- 将字符串中的数字提取出来, 动态分配内存
- 将字符串中的数字提取出来, 动态分配内存
- weka分类器-NaiveBayes
- Weka集成分类器
- 如何在python程序中调用weka的分类器
- 邻域生长主要是将种子图像提取出来,根据原图像中的连通性将目标生成出来
- Weka 使用元分类器
- weka中分类器算法
- 将表中的某个字段值提取出来赋给变量
- CAGradientLayer的使用
- Android Studio快捷键设置
- jsp页面间的传值方法
- Android中常见的像素单位
- 使用vector出现的错误 subscript out of range
- 如何将WEKA中的分类器Model提取出来
- Spring with Hibernate persistence and transactions example
- NET编程简易生成用友财务软件的财务接口数据
- Tomcat下部署多个项目
- ubuntu 环境变量改错导致所有命令用不了
- @property
- hdu 1257 最少拦截系统 (贪心)
- Java中如何实现时间的加减
- MTK8127 把系统的apk不编译进入system.img