你想做以下事情。
我需要证明我制作的模型文件是我从数据集生成的实际文件
我建议为您的分类器修改 weka 源代码并执行以下操作。
- 添加 DataSourceHashKey 字段
- 每当您生成分类器时,请获取数据集(arff 文件)的 cryptographic hash 并将此值设置为 DataSourceHashKey。
- 当您反序列化模型类时,您可以使用此 DataSourceHashKey。让我们称之为 ModelDataSourceHashKey
- 在运行分类器之前,从数据源(arff 文件)生成新的 DataSourceHashKey,我们将其命名为 CurrentDataSourceHashKey。
- 由于 Hash 函数的属性,您的 ModelDataSourceHashKey 和 CurrentDataSourceHashKey 必须相等。如果不是,那么您的新数据源与此模型生成的数据源不同,即使这种差异只是一个空格。
我还想补充以下几点。以前的答案大部分是正确的,但它遗漏了一些要点。
weka的一些分类器可以产生java代码见Generating source code from WEKA classes。以下摘自该链接。
Some of the schemes in Weka can generate Java source code that represents their current internal state. At the moment these are classifiers (book and developer version) and filters (snapshot or >3.5.6).
翻译如果分类器或过滤器实现Sourcable (Source able?)接口,你可以得到你的分类器/过滤器的java代码版本,见下文。
weka.classifiers
Interface Sourcable
All Known Implementing Classes:
AdaBoostM1, DecisionStump, J48, LogitBoost, OneR, REPTree, ZeroR
对于所有其他分类器,模型文件为java serialized files。请注意,序列化是 java 概念 而不是 weka 概念,因此所有限制都属于 java。你问的可以按照下面link来执行。
The serialized form contains sufficient information
such that it can be restored to an identical clone of the original JAVA object
但我认为为您的分类器实现 Sourcable 接口将比遵循这条路径更容易。