Back to blog

Using Weka in Go

A couple of years ago I wrote a blog post about wrapping some of Weka's classification functionality to allow it to be used programmatically in Python programs. A small project I'm currently working on at home is around taking some of the later research from my PhD work to see if it can be expressed and used as a simple web-app.

I began development in Go as I hadn't yet spent much time working with the language. The research work involves using a Bayesian network classifier to help infer a tweet's interestingness, and while Go machine-learning toolkits do exist, I wanted to use my existing models that were serialized in Java by Weka.

I started working on WekaGo, which is able to programmatically support simple classification tasks within a Go program. It essentially just manages the model, abstracts the generation of ARFF files, and executes the necessary Java to make it quick and easy to train and classify data:

model := wekago.NewModel("bayes.BayesNet")
...
model.AddTrainingInstance(train_instance1)
...
model.Train()
model.AddTestingInstance(train_instance1)
...
model.Test()

Results from the classification can then be examined, as described.