Playground for collaborative filtering in Ruby using NArray and rb-gsl.
Create a variable to store the ratings as an NArray (number of users x number of tracks).
Set the number of features to learn, lambda (regularization parameter), and the number of iterations of gradient descent.
Call min_cost
ratings = NArray[[5.0,4.0,0.0,0.0],[3.0,0.0,0.0,0.0],[4.0,0.0,0.0,0.0],[3.0,0.0,0.0,0.0],[3.0,0.0,0.0,0.0]] num_features = 2 lambda = 1 iterations = 10 cofi = CofiCost.new(ratings, num_features, lambda, iterations, nil, nil) cofi.min_cost
The cost and predictions (an NArray of the original size of ratings) can then be
returned after running min_cost:
cofi.cost cofi.predictions
rails 3.2
- gem ‘cofi_cost’
in your Gemfile bundle install
from the command line
MIT License 2012 Thomas Wolfe