Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed some recommender methods, added more test coverage.

  • Loading branch information...
commit e0f25a75aaef774f0ea24f324258360f51a638d1 1 parent 4409fbd
@vasinov authored
View
2  README.md
@@ -10,7 +10,7 @@ This is an early version of a Jruby gem that only supports Mahout recommendation
First of all you need to download Mahout library from one of the [mirrors](http://www.apache.org/dyn/closer.cgi/mahout/). Jruby Mahout only supports Mahout 0.7 at this point.
## Get Postgres JDBC Adapter
-If you wish to work with a database for recommendations, you'll have to install [JDBC driver for Postgres](http://jdbc.postgresql.org/download.html). Another option is to use file-based recommendation.
+If you wish to work with a database for recommendations, you'll have to install [JDBC 4 driver for Postgres 9.0 and higher](http://jdbc.postgresql.org/download.html). Another option is to use file-based recommendation.
## Installation
### 1. Set environment variable MAHOUT_DIR to point at your Mahout installation.
View
4 jruby_mahout.gemspec
@@ -7,8 +7,8 @@ Gem::Specification.new do |gem|
gem.authors = ["Vasily Vasinov"]
gem.email = ["vasinov@me.com"]
gem.homepage = "https://github.com/vasinov/jruby_mahout"
- gem.summary = "Jruby Mahout is a gem that unleashes the power of Apache Mahout in the world of Jruby."
- gem.description = "Jruby Mahout is a gem that unleashes the power of Apache Mahout in the world of Jruby. Mahout is a superior machine learning library written in Java. It deals with recommendations, clustering and classification machine learning problems at scale. Until now it was difficult to use it in Ruby projects. You'd have to implement Java interfaces in Jruby yourself, which is not quick especially if you just started exploring the world of machine learning."
+ gem.summary = "JRuby Mahout is a gem that unleashes the power of Apache Mahout in the world of JRuby."
+ gem.description = "JRuby Mahout is a gem that unleashes the power of Apache Mahout in the world of JRuby. Mahout is a superior machine learning library written in Java. It deals with recommendations, clustering and classification machine learning problems at scale. Until now it was difficult to use it in Ruby projects. You'd have to implement Java interfaces in Jruby yourself, which is not quick especially if you just started exploring the world of machine learning."
gem.license = "MIT"
gem.files = Dir["lib/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
View
24 lib/jruby_mahout/recommender.rb
@@ -34,18 +34,18 @@ def evaluate(training_percentage, evaluation_percentage)
end
def similar_items(item_id, number_of_items, rescorer)
- if @recommender.nil? or @recommender_name == "GenericItemBasedRecommender"
+ if @recommender.nil? or @recommender_name == "GenericUserBasedRecommender"
nil
else
- @recommender.mostSimilarItems(item_id, number_of_items, rescorer)
+ to_array(@recommender.mostSimilarItems(item_id, number_of_items, rescorer))
end
end
- def similar_users(user_id, number_of_items, rescorer)
- if @recommender.nil? or @recommender_name == "GenericUserBasedRecommender"
+ def similar_users(user_id, number_of_users, rescorer)
+ if @recommender.nil? or @recommender_name == "GenericItemBasedRecommender"
nil
else
- @recommender.mostSimilarUserIDs(user_id, number_of_items, rescorer)
+ to_array(@recommender.mostSimilarUserIDs(user_id, number_of_users, rescorer))
end
end
@@ -58,10 +58,10 @@ def estimate_preference(user_id, item_id)
end
def recommended_because(user_id, item_id, number_of_items)
- if @recommender.nil? or @recommender_name == "GenericItemBasedRecommender"
+ if @recommender.nil? or @recommender_name == "GenericUserBasedRecommender"
nil
else
- @recommender.recommendedBecause(user_id, item_id, number_of_items)
+ to_array(@recommender.recommendedBecause(user_id, item_id, number_of_items))
end
end
@@ -74,5 +74,15 @@ def recommendations_to_array(recommendations)
recommendations_array
end
+
+ private
+ def to_array(things)
+ things_array = []
+ things.each do |thing_id|
+ things_array << thing_id
+ end
+
+ things_array
+ end
end
end
View
48 spec/recommender_spec.rb
@@ -381,4 +381,52 @@
end
end
end
+
+ # TODO: cover all cases
+ describe ".similar_users" do
+ context "with valid arguments" do
+ it "should return an array of users" do
+ recommender = JrubyMahout::Recommender.new("SpearmanCorrelationSimilarity", 5, "GenericUserBasedRecommender", false)
+ recommender.data_model = JrubyMahout::DataModel.new("file", { :file_path => "spec/recommender_data.csv" }).data_model
+
+ recommender.similar_users(1, 10, nil).should be_an_instance_of Array
+ end
+ end
+ end
+
+ # TODO: cover all cases
+ describe ".similar_items" do
+ context "with valid arguments" do
+ it "should return an array of items" do
+ recommender = JrubyMahout::Recommender.new("GenericItemSimilarity", nil, "GenericItemBasedRecommender", false)
+ recommender.data_model = JrubyMahout::DataModel.new("file", { :file_path => "spec/recommender_data.csv" }).data_model
+
+ recommender.similar_items(4, 10, nil).should be_an_instance_of Array
+ end
+ end
+ end
+
+ # TODO: cover all cases
+ describe ".recommended_because" do
+ context "with valid arguments" do
+ it "should return an array of items" do
+ recommender = JrubyMahout::Recommender.new("PearsonCorrelationSimilarity", nil, "GenericItemBasedRecommender", false)
+ recommender.data_model = JrubyMahout::DataModel.new("file", { :file_path => "spec/recommender_data.csv" }).data_model
+
+ recommender.recommended_because(1, 138, 5).should be_an_instance_of Array
+ end
+ end
+ end
+
+ # TODO: cover all cases
+ describe ".estimate_preference" do
+ context "with valid arguments" do
+ it "should return afloat with an estimate" do
+ recommender = JrubyMahout::Recommender.new("PearsonCorrelationSimilarity", nil, "GenericItemBasedRecommender", false)
+ recommender.data_model = JrubyMahout::DataModel.new("file", { :file_path => "spec/recommender_data.csv" }).data_model
+
+ recommender.estimate_preference(1, 138).should be_an_instance_of Float
+ end
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.