有没有人坚持过 CI-Bayes 的训练集?我有来自该站点的示例代码:http://www.theserverside.com/news/thread.tss?thread_id=49773
代码如下:
FisherClassifier fc=new FisherClassifierImpl();
fc.train("The quick brown fox jumps over the lazy dog's tail","good");
fc.train("Make money fast!", "bad");
String classification=fc.getClassification("money", "unknown"); // should be "bad"
所以我需要能够将训练集存储在本地文件中。
以前有人做过吗?
最佳答案
要将 java 对象持久化到本地文件中,对象必须首先实现可序列化接口(interface)。
import java.io.Serializable;
public class MyClass implements Serializable {...
然后,您希望保留此训练集的类(class)应包括如下方法:
public void persistTrainingSet(FisherClassifier fc) {
String outputFile = <path/to/output/file>;
try {
FileOutputStream fos = new FileOutputStream(outputFile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(fc);
oos.close();
}
catch (IOException e) {
//handle exception
}
finally {
//do any cleaning up
}
}
关于java - 持久化 Java CI-Bayes 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1909344/