Skip to content

Instantly share code, notes, and snippets.

@benjamintanweihao
Last active January 4, 2016 13:29
Show Gist options
  • Select an option

  • Save benjamintanweihao/8628260 to your computer and use it in GitHub Desktop.

Select an option

Save benjamintanweihao/8628260 to your computer and use it in GitHub Desktop.
# brew install mahout
# export MAHOUT_DIR="/usr/local/Cellar/mahout/0.8/"
puts "#{ENV['MAHOUT_DIR']}libexec/*.jar"
Dir.glob("#{ENV['MAHOUT_DIR']}/libexec/*.jar").each { |d| require d }
MahoutFile = org.apache.mahout.cf.taste.impl.model.file
model = MahoutFile.FileDataModel.new(java.io.File.new("data.csv"))
MahoutSimilarity = org.apache.mahout.cf.taste.impl.similarity
similarity = MahoutSimilarity.TanimotoCoefficientSimilarity.new(model)
MahoutNeighborhood = org.apache.mahout.cf.taste.impl.neighborhood
neighborhood = MahoutNeighborhood.NearestNUserNeighborhood.new(5, similarity, model)
MahoutRecommender = org.apache.mahout.cf.taste.impl.recommender
recommender = MahoutRecommender.GenericBooleanPrefUserBasedRecommender.new(model, neighborhood, similarity)
recommendations = recommender.recommend(8, 5)
puts recommendations
# Data set: Save as data.csv
# 4 1
# 7 2
# 4 4
# 1 4
# 4 3
# 8 1
# 8 3
# 4 5
# 4 6
# 6 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment