Sunday, September 01, 2013

Javascript Homework

Learning From Data
Homework #1 visualization
101 iterations
20 data points
A jQuery Mobile Charts post encouraged me to try out an unusual javascript project. It helped answer question 7 of homework #1 from the 2012 archives of the Learning From Data course by CalTech. In this homework assignment, an exercise is proposed to use a very basic perceptron learning algorithm presented in lecture. The problem definition restricted input to a 2-d feature set to facilitate visualization with scatter charts. Another simplification involved limiting the number of classes to 2. A function defined by a randomly placed line determined class. As can be seen in the picture, above the orange line was the red class, and below the line was the blue class. The orange line in the chart is the function the learning algorithm is trying to approximate. The particular case posted in the image was an outlier that took 101 tries before the learning algorithm hypothesized the green line shown in the picture and thus correctly classified all 20 points of the training data. The two lines look very similar so in this case the classification error was very low. Some runs with a different random set of data were not so close.

The project requirements were not tied to a programming language or platform and don't need high performance. This was just the first homework assignment, and I am sure it gets harder. At first I started with a C# tool due to familiarity, but later I attended a jQuery mobile class and found the related charts blog post. Since I still want to finish my reversi project from last year in javascript and also wanted to try out some of what was taught in the class, I changed platforms and languages. Of course, using javascript for a machine learning solution seems unusual. Most existing machine learning libraries are in another language. But due to the nature of the homework assignment, it seemed to make sense for this special case:

  1. The simple perceptron learning algorithm isn't likely to be found in an existing library because it is too basic to be of practical use.
  2. Coding it from scratch enables learning
  3. It is simple enough to code from scratch
  4. I have some familiarity with javascript language already
  5. It is relatively easy to share the results cross platform
  6. It doesn't take a lot of code as long as you have a plotting library
  7. Performance isn't a requirement
  8. Platform isn't a requirement

 I only needed to restart plotting points and a line to get to the point were I left off in the other language. A problem with the charting library arose, but thankfully a guy from Europe found a workaround and posted it to stack overflow. With his help, I was able to use the jqplot library together with jquery mobile to finish the tool this holiday weekend.