List of usage examples for org.apache.mahout.cf.taste.impl.recommender GenericUserBasedRecommender recommend
@Override public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException
Default implementation which just calls Recommender#recommend(long,int,org.apache.mahout.cf.taste.recommender.IDRescorer) , with a org.apache.mahout.cf.taste.recommender.Rescorer that does nothing.
From source file:de.apaxo.bedcon.AnimalFoodRecommender.java
License:Open Source License
public void initRecommender() { try {/*www. jav a 2 s .co m*/ PearsonCorrelationSimilarity pearsonSimilarity = new PearsonCorrelationSimilarity(model); // Java: Similarity between Wolf and Bear: 0.8196561646738477 // R: corr(c(8,3,1),c(8,7,2)): 0.8196562 System.out.println("Similarity between Wolf and Bear: " + pearsonSimilarity.userSimilarity(id2thing.toLongID("Wolf"), id2thing.toLongID("Bear"))); // Similarity between Wolf and Rabbit: -0.6465846072812313 // R: cor(c(8,3,1),c(2,1,10)): -0.6465846 System.out.println("Similarity between Wolf and Rabbit: " + pearsonSimilarity.userSimilarity(id2thing.toLongID("Wolf"), id2thing.toLongID("Rabbit"))); // Similarity between Wolf and Pinguin: -0.24019223070763077 // R: cor(c(8,3,1),c(2,10,2)): -0.2401922 System.out.println("Similarity between Wolf and Pinguin: " + pearsonSimilarity.userSimilarity(id2thing.toLongID("Wolf"), id2thing.toLongID("Pinguin"))); GenericUserBasedRecommender recommender = new GenericUserBasedRecommender(model, new NearestNUserNeighborhood(3, pearsonSimilarity, model), pearsonSimilarity); for (RecommendedItem r : recommender.recommend(id2thing.toLongID("Wolf"), 3)) { // Pork: // (0.8196561646738477 * 8 + (-0.6465846072812313) * 1) / (0.8196561646738477 + (-0.6465846072812313)) = 34,15157 ~ 10 // Grass: // (2*(-0.24019223070763077)+7*(-0.6465846072812313)) / ((-0.24019223070763077) + (-0.6465846072812313)) = 5,65 // Corn: // (2*(-0.24019223070763077)+2*(0.8196561646738477)) / (-0.24019223070763077+0.8196561646738477) = 2 System.out.println("UserBased: Wolf should eat: " + id2thing.toStringID(r.getItemID()) + " Rating: " + r.getValue()); } SVDRecommender svdrecommender = new SVDRecommender(model, new SVDPlusPlusFactorizer(model, 4, 1000)); for (RecommendedItem r : svdrecommender.recommend(id2thing.toLongID("Sheep"), 3)) { System.out.println("SVD: Sheep should eat: " + id2thing.toStringID(r.getItemID()) + " Rating: " + r.getValue()); } } catch (TasteException e) { e.printStackTrace(); } }
From source file:edu.carleton.comp4601.cf.dao.SimpleDataRecommender.java
License:Open Source License
public void initRecommender() { try {//from ww w.j av a2 s. c o m PearsonCorrelationSimilarity pearsonSimilarity = new PearsonCorrelationSimilarity(model); System.out.println("Similarity between Alice and User1: " + pearsonSimilarity.userSimilarity(id2thing.toLongID("Alice"), id2thing.toLongID("User1"))); System.out.println("Similarity between Alice and User2: " + pearsonSimilarity.userSimilarity(id2thing.toLongID("Alice"), id2thing.toLongID("User2"))); System.out.println("Similarity between Alice and User3: " + pearsonSimilarity.userSimilarity(id2thing.toLongID("Alice"), id2thing.toLongID("User3"))); GenericUserBasedRecommender recommender = new GenericUserBasedRecommender(model, new NearestNUserNeighborhood(3, pearsonSimilarity, model), pearsonSimilarity); for (RecommendedItem r : recommender.recommend(id2thing.toLongID("Alice"), 3)) { System.out.println("UserBased: Alice should like: " + id2thing.toStringID(r.getItemID()) + " Rating: " + r.getValue()); } SVDRecommender svdrecommender = new SVDRecommender(model, new SVDPlusPlusFactorizer(model, 4, 1000)); for (RecommendedItem r : svdrecommender.recommend(id2thing.toLongID("User1"), 3)) { System.out.println("SVD: User1 should like: " + id2thing.toStringID(r.getItemID()) + " Rating: " + r.getValue()); } } catch (TasteException e) { e.printStackTrace(); } }
From source file:hr.fer.tel.rovkp.homework03.task02.Program.java
public static void main(String[] args) throws Exception { String fileItemsSimilarity = "./src/main/resources/item_similarity.csv"; String fileDataModel = "./src/main/resources/jester_ratings.dat"; DataModel model = new FileDataModel(new File(fileDataModel)); GenericUserBasedRecommender userBased = RecommenderUtils.userBasedRecommender(model); GenericItemBasedRecommender itemBased = RecommenderUtils.itemBasedRecommender(model, fileItemsSimilarity); System.out.println("user based:"); List<RecommendedItem> recommendationsU = userBased.recommend(220, 10); for (RecommendedItem recommendation : recommendationsU) { System.out.println(recommendation); }//from w w w. j av a 2s. c om System.out.println("item based:"); List<RecommendedItem> recommendationsI = itemBased.recommend(220, 10); for (RecommendedItem recommendation : recommendationsI) { System.out.println(recommendation); } }
From source file:hr.fer.tel.rovkp.homework03.task02.UserBasedJokesRecommender.java
public static void main(String[] args) throws Exception { String fileDataModel = "./src/main/resources/jester_ratings.dat"; String users = "./src/main/resources/users.txt"; String outFile = "./target/user_based_recommendations.txt"; int CNT = 100; DataModel model = new FileDataModel(new File(fileDataModel)); GenericUserBasedRecommender recommender = RecommenderUtils.userBasedRecommender(model); List<RecommendedItem> recommendations = recommender.recommend(220, 10); for (RecommendedItem recommendation : recommendations) { System.out.println(recommendation); }/* w ww . j a v a 2 s .c o m*/ writeTopN(CNT, users, recommender, outFile); }
From source file:hr.fer.tel.rovkp.homework03.task02.UserBasedJokesRecommender.java
public static String printRecommendations(String id, GenericUserBasedRecommender recommender) { try {/* w w w . j a va 2 s . co m*/ String ret = ""; int i = Integer.parseInt(id); ret += "User " + i + "\n"; List<RecommendedItem> recommendations = recommender.recommend(i, 10); for (RecommendedItem recommendation : recommendations) { ret += recommendation + "\n"; } return ret; } catch (TasteException ex) { return ""; } }