org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood Java Examples

The following examples show how to use org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood. 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 vote down vote up
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: MovieUserEvaluator.java    From hiped2 with Apache License 2.0 5 votes vote down vote up
@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);
}