5

Has anyone ever persisted a training set for CI-Bayes? I have sample code from this site: http://www.theserverside.com/news/thread.tss?thread_id=49773

here is the code:

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"

so I need to be able to store the training set in a local file.

Has anyone ever done this before?

wlindner
  • 417
  • 1
  • 5
  • 13

2 Answers2

0

I have. After doing a couple projects with CI-Bayes, I would recommend you look elsewhere (of course this was a long time ago). It is a very bad idea to use an inference engine that needs to be trained before each use and if you really consider the issue of state management, it's complicated (e.g. do you want to just store the training data? or perhaps the trained distributions? chains?).

CI-Bayes is also kind of a convoluted codebase. It was modeled off some Python code that appeared in a book about intelligence. The Java version is not very well designed. It also does not use TDD, does not really have JavaDoc to speak of.

That said, you can get a simple classifier going pretty quickly. The longer term goal is the one you asked about though.

Rob
  • 11,446
  • 7
  • 39
  • 57
0

To persist a java Object in a local file, the Object must first implement the Serializable interface.

import java.io.Serializable;
public class MyClass implements Serializable {...

Then, the class from which you would like to persist this training set, should include a method like:

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
    }
}