Sunday, November 1, 2009

LibSVM and Ruby

LibSVM is the standard library for using Support Vector Machines, a powerful machine-learning tool. Installing LibSVM can be done through your usual package manager system, or through the LibSVM download page. There is Ruby-LibSVM library, available from http://rubysvm.cilibrar.com/download/. If you download the library, you will find the installation instructions do not work for Ruby 1.9. However, the fix is relatively simple. After downloading and unpacking Ruby-LibSVM, run ./configure. Before compiling, modify the main.cpp file to allow for the change between Ruby 1.8 and Ruby 1.9. I had to make three changes:
  1. remove the line #include "node.h"
  2. change RARRAY(xs)->len on line 50 to RARRAY_LEN(xs)
  3. change RARRAY(xs)->len on line 579 to RARRAY_LEN(xs)
(Thanks to Lee Hinman for the clue as to what to do.) After those changes, I could finally run 'make' and then 'sudo make install' to install the LibSVM library for Ruby. Ilya Grigorik has a nice example of using Ruby-LibSVM, which I used to check everything was working.

0 comments:

Post a Comment