Linear Regression and cross validation in Java using Weka

I stumbled upon a question in the internet about how to make price prediction based on price history in Android. Assuming the history size is quite small (few hundreds) and the attribute is not many (less than 20), I quickly thought that Weka Java API would be one of the easiest way to achieve this.

Unfortunately, I can’t easily find straightforward tutorial or example on this since most of them are for GUI version of Weka. So, I decided to whip up an example (using bleeding-edge weka-dev 3.9.2) and post the brief explanation here 😆

I use a demand-forecasting (regression) dataset from UCI for this example. I choose this dataset because it has quite similar characteristics with price prediction.