Package org.apache.mahout.cf.taste.similarity

Examples of org.apache.mahout.cf.taste.similarity.UserSimilarity


    DataModel dataModel = getDataModel();
    FastIDSet neighborhood = new FastIDSet();
    LongPrimitiveIterator usersIterable =
        SamplingLongPrimitiveIterator.maybeWrapIterator(dataModel.getUserIDs(), getSamplingRate());
    UserSimilarity userSimilarityImpl = getUserSimilarity();

    while (usersIterable.hasNext()) {
      long otherUserID = usersIterable.next();
      if (userID != otherUserID) {
        double theSimilarity = userSimilarityImpl.userSimilarity(userID, otherUserID);
        if (!Double.isNaN(theSimilarity) && theSimilarity >= threshold) {
          neighborhood.add(otherUserID);
        }
      }
    }
View Full Code Here


      throws TasteException {
    if (theNeighborhood.length == 0) {
      return Float.NaN;
    }
    DataModel dataModel = getDataModel();
    UserSimilarity similarity = getSimilarity();
    float totalSimilarity = 0.0f;
    boolean foundAPref = false;
    for (long userID : theNeighborhood) {
      if (userID != theUserID) {
        // See GenericItemBasedRecommender.doEstimatePreference() too
        if (dataModel.getPreferenceValue(userID, itemID) != null) {
          foundAPref = true;
          totalSimilarity += similarity.userSimilarity(theUserID, userID);
        }
      }
    }
    return foundAPref ? totalSimilarity : Float.NaN;
  }
View Full Code Here

  protected float doEstimatePreference(long theUserID, long[] theNeighborhood, long itemID) throws TasteException {
    if (theNeighborhood.length == 0) {
      return Float.NaN;
    }
    DataModel dataModel = getDataModel();
    UserSimilarity similarity = getSimilarity();
    float totalSimilarity = 0.0f;
    boolean foundAPref = false;
    for (long userID : theNeighborhood) {
      // See GenericItemBasedRecommender.doEstimatePreference() too
      if (userID != theUserID && dataModel.getPreferenceValue(userID, itemID) != null) {
        foundAPref = true;
        totalSimilarity += similarity.userSimilarity(theUserID, userID);
      }
    }
    return foundAPref ? totalSimilarity : Float.NaN;
  }
View Full Code Here

    model = new FileDataModel(testFile);
  }

  @Test
  public void testFile() throws Exception {
    UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(model);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(3, userSimilarity, model);
    Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, userSimilarity);
    assertEquals(1, recommender.recommend(123, 3).size());
    assertEquals(0, recommender.recommend(234, 3).size());
    assertEquals(1, recommender.recommend(345, 3).size());
View Full Code Here

    assertEquals(model.getItemIDsFromUser(456).size(), 4);
  }

  @Test
  public void testFile() throws Exception {
    UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(model);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(3, userSimilarity, model);
    Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, userSimilarity);
    assertEquals(1, recommender.recommend(123, 3).size());
    assertEquals(0, recommender.recommend(234, 3).size());
    assertEquals(1, recommender.recommend(345, 3).size());
View Full Code Here

    model = new FileDataModel(testFile);
  }

  @Test
  public void testFile() throws Exception {
    UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(model);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(3, userSimilarity, model);
    Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, userSimilarity);
    assertEquals(1, recommender.recommend(123, 3).size());
    assertEquals(0, recommender.recommend(234, 3).size());
    assertEquals(1, recommender.recommend(345, 3).size());
View Full Code Here

  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);
View Full Code Here

  public static class MyRecommendBuilder implements RecommenderBuilder {
    @Override
    public Recommender buildRecommender(DataModel model)
        throws TasteException {
      UserSimilarity similarity =
          new PearsonCorrelationSimilarity(model);

      UserNeighborhood neighborhood =
          new NearestNUserNeighborhood(
              100,
View Full Code Here

                    {0.2, 0.3, 0.3, 0.6},
                    {0.4, 0.4, 0.5, 0.9},
                    {0.1, 0.4, 0.5, 0.8, 0.9, 1.0},
                    {0.2, 0.3, 0.6, 0.7, 0.1, 0.2},
            });
    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, dataModel);
    Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
    List<RecommendedItem> fewRecommended = recommender.recommend(1, 2);
    List<RecommendedItem> moreRecommended = recommender.recommend(1, 4);
    for (int i = 0; i < fewRecommended.size(); i++) {
View Full Code Here

            new Double[][] {
                    {0.1, 0.2},
                    {0.2, 0.3, 0.3, 0.6},
                    {0.4, 0.5, 0.5, 0.9},
            });
    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, dataModel);
    Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
    List<RecommendedItem> originalRecommended = recommender.recommend(1, 2);
    List<RecommendedItem> rescoredRecommended =
        recommender.recommend(1, 2, new ReversingRescorer<Long>());
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.similarity.UserSimilarity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.