Java Weka API: Adding List To Instances Object

This is just a quick one to save anyone else new to the Weka api in Java spending as much time as i did figuring this one out.

Lets suppose you have a weka instances object and a new list of values you want to add into it as a new attribute (weka slang for a new column in your data).

Below gist shows a small reproducible example of this.

And you should see some output like this:

====== BEFORE ======
sepallength,sepalwidth,petallength,petalwidth,class
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5,3.6,1.4,0.2,Iris-setosa

====== AFTER ======
sepallength,sepalwidth,petallength,petalwidth,class,randomDouble
5.1,3.5,1.4,0.2,Iris-setosa,0.173003
4.9,3,1.4,0.2,Iris-setosa,0.304703
4.7,3.2,1.3,0.2,Iris-setosa,0.925626
4.6,3.1,1.5,0.2,Iris-setosa,0.733839
5,3.6,1.4,0.2,Iris-setosa,0.710073

Above we can see the new attribute “randomDouble” has been added to the instances object.

I’m learning the weka java api at the moment so will try post little tidbits like this that could be useful for others of even myself 6 months from now 🙂

Java for Machine Learning

I’ve recently been learning java for machine learning related work (a long story to do with mainframes, and you know, why not).

Decided to stick down in here some resources i found very useful as i found i still needed to do a bit of Googling to find ML related Java tutorials and moocs i found useful. Will add to this post as i discover more stuff.

General Java Intro Stuff

Machine Learning Related

Testing in Java

Found this video pretty good on junit. And this one from intelij if that’s your IDE.

Java IDE’s

This was one of the hardest parts – finding my way around IDE’s like eclipse and intelij. They are super powerful but a very different experience to something like jupyter lab or visual studio with python.

I’m using intelij IDEA and they have some good videos here.

Maven

Other Useful/Interesting Stuff