Sunday, February 12, 2012

Machine Learning Examples in R

This is a post that has been a long time in the making. Following on from the excellent Stanford Machine Learning Course I have made examples of the main algorithms covered in R.

We have Linear Regression

Followed by Neural Networks
And Support Vector Machines

One remaining item is Logistic Regression, I am yet to find a library in R that behaves as I want, so that will come at some future date. I've been sitting on this post for ages and got sick of waiting. As an aside I find the documentation in R to be variable at best, which can make it somewhat of a pain to work with. When it is good, yes it can be very good but often it is quite poor ...

R is great for data analysis and exploration, but I have found myself moving back to python for many more mundane tasks.

Anyway for those interested in the code, I have put it on Github. The data is from an exercise in the Stanford course, and by tweaking the parameters I really got a good feel for how the various algorithms work in practise.

Once I finish my backtesting engine I will probably put it up on Github as well, and then I can start digging into the applications of ML techniques for trading systems.


  1. This is really impressive - looking forward to your next posts!

  2. Nice work!--I have watched a couple of those lectures as well and realized that I need to brush up on my Calc & Linear Algebra!

    ML applications in trading is a topic I have gotten quite interested in as well.

    I have not yet done much in R --- Can you (for the most part) accomplish everything in Python that you can in R?

  3. Hey, yes you certainly can. There is a library in python scikit.learn and a book called "Machine Learning in Action" which is all about ML in python, it is on safari if you have an account there.

    R is very niche and I took it up for a bunch of reasons, it's good if you're doing straight statistics on tabular data but it is somewhat difficult to work with. If you're already familiar with python I would just go with that.

  4. Thanks for the tip-- I'll check that book out!

    I have read some of "Programming Collective Intelligence" as well--it has quite a bit of example Pyton code--but is ~5 years old at this point.

  5. Yeah I don't know that one. It is probably fine but ML and the libraries you use are a moving target and always being improved, 5 years is quite a while.

    If you do any programming stuff Safari is well worth it I have a 10 slot bookshelf that is $20/month and I use it every day, they have some great books there on all sorts of topics. They also have some decent trading books as well


Note: Only a member of this blog may post a comment.