Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

tomz/liblinear-ruby-swig

Open more actions menu

Repository files navigation

This is the Ruby LIBLINEAR SWIG (Simplified Wrapper and Interface Generator) interface. LIBLINEAR is a high performance machine learning library for large scale text mining(www.csie.ntu.edu.tw/~cjlin/liblinear).

A slightly modified version of LIBLINEAR 1.8 is included which allows turning on/off the default debuging/logging messages. You don’t need your own copy of SWIG to use this library - all needed files are generated using SWIG already.

LIBLINEAR is in use at tweetsentiments.com - A Twitter / Tweet sentiment analysis application

Currently the gem is available on linux and OS X, and you will need g++ installed to compile the native code.

sudo gem sources -a http://gems.github.com   (you only have to do this once)
sudo gem install tomz-liblinear-ruby-swig

Try the following multiclass problem in irb:

irb(main):001:0> require 'rubygems'
irb(main):002:0> require 'linear'
irb(main):003:0> pa = LParameter.new
irb(main):004:0> pa.solver_type = MCSVM_CS 
irb(main):005:0> pa.eps = 0.1
irb(main):006:0> bias = 1
irb(main):007:0> labels = [1, 2, 1, 2, 3]
irb(main):008:0> samples = [
irb(main):009:1*            {1=>0,2=>0.1,3=>0.2,4=>0,5=>0},
irb(main):010:1*            {1=>0,2=>0.1,3=>0.3,4=>-1.2,5=>0},
irb(main):011:1*            {1=>0.4,2=>0,3=>0,4=>0,5=>0},
irb(main):012:1*            {1=>0,2=>0.1,3=>0,4=>1.4,5=>0.5},
irb(main):013:1*            {1=>-0.1,2=>-0.2,3=>0.1,4=>1.1,5=>0.1}
irb(main):014:1>           ]
irb(main):016:0> sp = LProblem.new(labels,samples,bias)
irb(main):017:0> m = LModel.new(sp, pa)
irb(main):018:0>  pred = m.predict({1=>1,2=>0.1,3=>0.2,4=>0,5=>0})
=> 1
irb(main):019:0>  pred = m.predict({1=>0,2=>0.1,3=>0.2,4=>0,5=>0})
=> 2
irb(main):020:0>  pred = m.predict({1=>0,2=>0.1,3=>0.2,4=>0,5=>0})
=> 2
irb(main):025:0>  pred = m.predict({1=>0.4,2=>0,3=>0,4=>0,5=>0})
=> 1
irb(main):021:0>  pred = m.predict({1=>-0.1,2=>-0.2,3=>0.1,4=>1.1,5=>0.1})
=> 3
irb(main):022:0> m.save("test.model")

For more examples see test*.rb in the liblinear-ruby-swig/liblinear-1.8/ruby directory

Tom Zeng

About

This is the Ruby interface to LIBLINEAR (much more efficient than LIBSVM for text classification and other large linear classifications)

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.