org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender Java Examples
The following examples show how to use
org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MovieUserRecommender.java From hiped2 with Apache License 2.0 | 6 votes |
private static void recommend(String ratingsFile, int ... userIds) throws TasteException, IOException { DataModel model = new FileDataModel(new File(ratingsFile)); UserSimilarity similarity = new PearsonCorrelationSimilarity(model); UserNeighborhood neighborhood = new NearestNUserNeighborhood( 100, similarity, model); Recommender recommender = new GenericUserBasedRecommender( model, neighborhood, similarity); Recommender cachingRecommender = new CachingRecommender(recommender); for(int userId: userIds) { System.out.println("UserID " + userId); List<RecommendedItem> recommendations = cachingRecommender.recommend(userId, 2); for(RecommendedItem item: recommendations) { System.out.println(" item " + item.getItemID() + " score " + item.getValue()); } } }
Example #2
Source File: GenericRecommenderBuilderTest.java From rival with Apache License 2.0 | 6 votes |
@Test public void testBuildKNNRecommender() { GenericRecommenderBuilder rb = new GenericRecommenderBuilder(); FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>(); userData.put(1, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1, 1, 1), new GenericPreference(1, 2, 1), new GenericPreference(1, 3, 1)))); userData.put(2, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2, 1, 1), new GenericPreference(2, 2, 1), new GenericPreference(2, 4, 1)))); DataModel dm = new GenericDataModel(userData); Recommender rec = null; String recommenderType = "org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender"; String similarityType = "org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity"; try { rec = rb.buildRecommender(dm, recommenderType, similarityType); } catch (RecommenderException e) { e.printStackTrace(); } assertTrue(rec instanceof GenericUserBasedRecommender); }
Example #3
Source File: UserbasedRecommender.java From Building-Recommendation-Engines with MIT License | 5 votes |
public static void main( String[] args ) throws IOException, TasteException { //user based recommender model DataModel model = new FileDataModel(new File("data/dataset.csv")); UserSimilarity similarity = new PearsonCorrelationSimilarity(model); UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model); UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity); List<RecommendedItem> recommendations = recommender.recommend(2, 3); for (RecommendedItem recommendation : recommendations) { System.out.println(recommendation); } }
Example #4
Source File: MovieUserEvaluator.java From hiped2 with Apache License 2.0 | 5 votes |
@Override public Recommender buildRecommender(DataModel model) throws TasteException { UserSimilarity similarity = new PearsonCorrelationSimilarity(model); UserNeighborhood neighborhood = new NearestNUserNeighborhood( 100, similarity, model); return new GenericUserBasedRecommender( model, neighborhood, similarity); }