lenskit is a Java-based open-source toolkit for recommendation systems. This example shows how to use lenskit in your Ruby code via JRuby.
Example
$ ruby main.rb
Recommendations for user with id=0:
[score(62) = 4.914649362279286, score(15) = 4.63731255034173, score(49) = 4.607799688330525, score(89) = 4.528461033828778, score(6) = 4.408179843204389]
Recommendations for user with id=1:
[score(66) = 4.931632515735108, score(45) = 4.696943825952708, score(3) = 4.6625575654628335, score(15) = 4.5866827948589135, score(17) = 4.138864980730785]
Recommendations for user with id=2:
[score(45) = 4.41033605687315, score(58) = 4.259395566799698, score(8) = 4.237214609505099, score(83) = 4.188428706960753, score(72) = 4.045670217692879]
Recommendations for user with id=3:
[score(62) = 4.527597077214233, score(45) = 4.2550354023110595, score(49) = 4.220747403265472, score(76) = 4.135953313920664, score(17) = 4.051224458102281]
See example_runner.rb
for implementation details. Note that the sample_data
file is simply provided so that we have some useful output for this example.
Setup
Because we need to run native Java code, we'll need to use the JRuby interpreter. If you have RVM installed, that's easy:
rvm install jruby
Now, set JRuby as your interpreter:
rvm use jruby
We'll be using jbundler to automatically pull in the lenskit JAR files.
gem install jbundler
Finally, download the lenskit JAR files our code depends on:
jbundle
Purpose
Provide a simple starting point for interacting with lenskit in Ruby for those who would prefer working in Ruby to Java. You can clone this repository to bootstrap a new application and make sure that your lenskit dependencies are set up properly. This may be of special interest to those taking the Intro to Recommender Systems course.
Input
The input data defined in sample_data
is a tab-delimited set of user_id
, item_id,
and rating
tuples. This data represents simulated events wherein 20 users rated 100 arbitrary items on a scale from 0 to 5.
License & Notice
Do whatever the hell you want with this. Do not sue me. Be aware that I am not the original author of lenskit nor am I affiliated with grouplens.