【发布时间】:2014-04-07 18:12:28
【问题描述】:
我正在使用 Weka SMO 对我的训练数据进行分类,并且我想轻松地在我的 SMO 模型文件中保存和加载。我创建了一个保存方法,以便将分类器存储到文件中。我的代码如下:
private static Classifier loadModel(Classifier c, String name, File path) throws Exception {
FileInputStream fis = new FileInputStream("/weka_models/" + name + ".model");
ObjectInputStream ois = new ObjectInputStream(fis);
return c;
}
private static void saveModel(Classifier c, String name, File path) throws Exception {
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(
new FileOutputStream("/weka_models/" + name + ".model"));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
oos.writeObject(c);
oos.flush();
oos.close();
}
我的问题是,如何将 ObjectInputStream 转换为 Classifier 对象。
【问题讨论】: