Ruby interface to LIBSVM (using SWIG)
C++ Java C Python Ruby Matlab
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib fixed #3 Mar 31, 2012
libsvm-3.1 svm_check_probability_model should be compared to 1. 0 evaluates to t… Apr 25, 2012
.gitignore Follow naming conventions so requiring gem load extensions properly Mar 22, 2009
AUTHORS merged in the gem packaging from feedbackmine(thanks) Mar 4, 2009
COPYING rearranged some texts Mar 4, 2009
History.txt Upgraded to LIBSVM 2.89 May 15, 2009
Manifest.txt Renamed README.txt to README.rdoc May 15, 2009
README.rdoc upgraded to LIBSVM 2.9 Mar 27, 2010
Rakefile upgraded to LIBLINEAR 1.8 and OS X enabled Oct 28, 2011
libsvm-ruby-swig-0.4.0.gem upgraded to LIBLINEAR 1.8 and OS X enabled Oct 28, 2011
libsvm-ruby-swig.gemspec upgraded to LIBSVM 2.9 Mar 27, 2010




This is the Ruby port of the LIBSVM Python SWIG (Simplified Wrapper and Interface Generator) interface.

A slightly modified version of LIBSVM 2.9 is included, it allows turrning on/off the debug log. You don't need your own copy of SWIG to use this library - all needed files are generated using SWIG already.

Look for the README file in the ruby subdirectory for instructions. The binaries included were built under Ubuntu Linux 2.6.28-18-generic x86_64, you should run make under the libsvm-2.9 and libsvm-2.9/ruby directories to regenerate the executables for your environment.

LIBSVM is in use at - A Twitter / Tweet sentiment analysis application


Currently the gem is available on linux only(tested on Ubuntu 8-9 and Fedora 9-12, and on OS X by danielsdeleo), and you will need g++ installed to compile the native code.

sudo gem sources -a   (you only have to do this once)
sudo gem install tomz-libsvm-ruby-swig


Quick Interactive Tutorial using irb (adopted from the python code from Toby Segaran's “Programming Collective Intelligence” book):

irb(main):001:0> require 'svm'
=> true
irb(main):002:0> prob =[1,-1],[[1,0,1],[-1,0,-1]])
irb(main):003:0> param = => LINEAR, :C => 10)
irb(main):004:0> m =,param)
irb(main):005:0> m.predict([1,1,1])
=> 1.0
irb(main):006:0> m.predict([0,0,1])
=> 1.0
irb(main):007:0> m.predict([0,0,-1])
=> -1.0
irb(main):009:0> m2 ="test.model")
irb(main):010:0> m2.predict([0,0,-1])
=> -1.0


Tom Zeng