SHARE
TWEET

Untitled

a guest May 26th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package zad2;
  2.  
  3. import org.apache.mahout.cf.taste.eval.RecommenderBuilder;
  4. import org.apache.mahout.cf.taste.eval.RecommenderEvaluator;
  5. import org.apache.mahout.cf.taste.impl.eval.RMSRecommenderEvaluator;
  6. import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
  7. import org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender;
  8. import org.apache.mahout.cf.taste.impl.similarity.file.FileItemSimilarity;
  9. import org.apache.mahout.cf.taste.model.DataModel;
  10. import org.apache.mahout.cf.taste.recommender.ItemBasedRecommender;
  11. import org.apache.mahout.cf.taste.recommender.RecommendedItem;
  12. import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
  13. import org.apache.mahout.common.RandomUtils;
  14.  
  15. import java.io.File;
  16. import java.util.List;
  17.  
  18. import static zad2.UserRecommender.EVALUATION_PERCENTAGE;
  19. import static zad2.UserRecommender.TRAINING_PERCENTAGE;
  20.  
  21. public class ItemRecommender {
  22.  
  23.     public static void main(String[] args) throws Exception {
  24.         RandomUtils.useTestSeed();
  25.         DataModel model = new FileDataModel(
  26.                 new File("/home/marin/Dropbox/fax/4. godina/rovkp/dz3/jester_ratings.dat"), "\t+");
  27.         ItemSimilarity similarity = new FileItemSimilarity(
  28.                 new File("/home/marin/Dropbox/fax/4. godina/rovkp/dz3/item_similarity.csv"));
  29.         ItemBasedRecommender recommender = new
  30.                 GenericItemBasedRecommender(model, similarity);
  31.  
  32.  
  33. //izračunaj i ispiši 10 preporuka za korisnika s ID-jem 22
  34.         List<RecommendedItem> recommendations = recommender.recommend(22, 10);
  35.         for (RecommendedItem recommendation : recommendations) {
  36.             System.out.println(recommendation);
  37.         }
  38.  
  39.         RecommenderBuilder builder = dataModel -> {
  40.             return new GenericItemBasedRecommender(dataModel, similarity);
  41.         };
  42.  
  43.         RecommenderEvaluator recommenderEvaluator = new RMSRecommenderEvaluator();
  44.         double score = recommenderEvaluator.evaluate(builder, null, model, TRAINING_PERCENTAGE, EVALUATION_PERCENTAGE);
  45.         System.out.println("Score is " + score);
  46.     }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top