On this page, we show how to first set up recommenders in Ruby, and then use them to make predictions.
To use the examples on this page,
download the MovieLens 100k ratings dataset from the
GroupLens Research website and unzip it.
Of course you can also use your own data ;-)
IronRuby
IronRuby lets you run Ruby programs on the .NET platform. It also lets you use .NET libraries (.dlls) like MyMediaLite.
To run a program with IronRuby, type ir program.rb in the command line, where program.rb is your program.
You may also enter just ir, so that you can use IronRuby's REPL interactively.
Rating Prediction
#!/usr/bin/env ir require 'MyMediaLite' # load the data train_data = MyMediaLite::IO::RatingData.Read("u1.base") test_data = MyMediaLite::IO::RatingData.Read("u1.test") # set up the recommender recommender = MyMediaLite::RatingPrediction::UserItemBaseline.new() recommender.Ratings = train_data recommender.Train() # measure the accuracy on the test data set eval_results = MyMediaLite::Eval::Ratings::Evaluate(recommender, test_data) eval_results.each do |entry| puts "#{entry}" end # make a prediction for a certain user and item puts recommender.Predict(1, 1)
Item Prediction from Positive-Only Feedback
#!/usr/bin/env ir require 'MyMediaLite' using_clr_extensions MyMediaLite # load the data train_data = MyMediaLite::IO::ItemData.Read("u1.base") test_data = MyMediaLite::IO::ItemData.Read("u1.test") # set up the recommender recommender = MyMediaLite::ItemRecommendation::MostPopular.new() recommender.Feedback = train_data; recommender.Train() # measure the accuracy on the test data set eval_results = MyMediaLite::Eval::Items.Evaluate(recommender, test_data, train_data) eval_results.each do |entry| puts "#{entry}" end # make a prediction for a certain user and item puts recommender.Predict(1, 1)