Friday, December 16, 2011

Implementing Example One from the Machine Learning Class in Java

At the end of 2011, Stanford offered a free online machine learning course.  The course covered many aspects of machine learning including linear regression, neural networks, super vector machines, and anomaly detection.

Octave is an open software platform for numerical applications that is compatible with Matlab.  Octave was the   tool of choice for the machine learning class, all of the programming exercises required that you submit Octave source.

Overview of example one:

The first example in the course is to implement one variable linear regression.  The regression in linear regression is a regression towards a mean or moving closer towards a mean.

Partial Approach for Gradient Descent with Octave



In the example, data points are read from a file and after running the example from Octave, this plot is generated.



Overview of example one in Java:


The Java implementation as you might expect is more verbose than the Octave equivalent.  Java doesn't include a matrix library in the standard toolkit so it took 5-10 lines more code to implement basic matrix multiplication as opposed to the seamless multiplication in Octave.



Java Swing Example of MlClass Ex1, regression line and data points

Resources

http://www.gnu.org/software/octave/
http://www.ml-class.org/course/class/index

Note:  I tried not to provide a full matlab implementation from the machine learning course as that wouldn't be fair to the students.  Plus the implementation is in Java and really ideal for the actual course.

Source


http://jvmnotebook.googlecode.com/svn/trunk/blog/java/ConvertMachineLearningToJava/

Contact
berlin dot brown at gmail.com

"In the tumultuous business of cutting-in and attending to a whale, there is much running backwards and forwards among the crew. Now hands are wanted here, and then again hands are wanted there. There is no staying in any one place; for at one and the same time everything has to be done everywhere. It is much the same with him who endeavors the description of the scene. "

No comments: