Package org.apache.mahout.cf.taste.recommender

Examples of org.apache.mahout.cf.taste.recommender.RecommendedItem


  public void testMostSimilarToMultiple() throws Exception {
    ItemBasedRecommender recommender = buildRecommender2();
    List<RecommendedItem> similar = recommender.mostSimilarItems(new long[] {0, 1}, 2);
    assertNotNull(similar);
    assertEquals(2, similar.size());
    RecommendedItem first = similar.get(0);
    RecommendedItem second = similar.get(1);
    assertEquals(2, first.getItemID());
    assertEquals(0.85, first.getValue(), EPSILON);
    assertEquals(3, second.getItemID());
    assertEquals(-0.3, second.getValue(), EPSILON);
  }
View Full Code Here


    try {
      do {
        long itemID = in.readLong();
        float value = in.readFloat();
        if (!Float.isNaN(value)) {
          RecommendedItem recommendedItem = new GenericRecommendedItem(itemID, value);
          recommended.add(recommendedItem);
        }
      } while (true);
    } catch (EOFException eofe) {
      // continue; done
View Full Code Here

  public void testRecommendedBecause() throws Exception {
    ItemBasedRecommender recommender = buildRecommender2();
    List<RecommendedItem> recommendedBecause = recommender.recommendedBecause(1, 4, 3);
    assertNotNull(recommendedBecause);
    assertEquals(3, recommendedBecause.size());
    RecommendedItem first = recommendedBecause.get(0);
    RecommendedItem second = recommendedBecause.get(1);
    RecommendedItem third = recommendedBecause.get(2);
    assertEquals(2, first.getItemID());
    assertEquals(0.99, first.getValue(), EPSILON);
    assertEquals(3, second.getItemID());
    assertEquals(0.4, second.getValue(), EPSILON);
    assertEquals(0, third.getItemID());
    assertEquals(0.2, third.getValue(), EPSILON);
  }
View Full Code Here

  public void testRecommender() throws Exception {
    Recommender recommender = new ItemAverageRecommender(getDataModel());
    List<RecommendedItem> recommended = recommender.recommend(1, 1);
    assertNotNull(recommended);
    assertEquals(1, recommended.size());
    RecommendedItem firstRecommended = recommended.get(0);
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.53333336f, firstRecommended.getValue());
    recommender.refresh(null);
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.53333336f, firstRecommended.getValue());
  }
View Full Code Here

    int size = in.readInt();
    recommended = new ArrayList<RecommendedItem>(size);
    for (int i = 0; i < size; i++) {
      long itemID = Varint.readSignedVarLong(in);
      float value = in.readFloat();
      RecommendedItem recommendedItem = new GenericRecommendedItem(itemID, value);
      recommended.add(recommendedItem);
    }
  }
View Full Code Here

    ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
    Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
    List<RecommendedItem> recommended = recommender.recommend(1, 1);
    assertNotNull(recommended);
    assertEquals(1, recommended.size());
    RecommendedItem firstRecommended = recommended.get(0);
    // item one should be recommended because it has a greater rating/score
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.3, firstRecommended.getValue(), EPSILON);
  }
View Full Code Here

  public void testRecommender() throws Exception {
    Recommender recommender = buildRecommender();
    List<RecommendedItem> recommended = recommender.recommend(1, 1);
    assertNotNull(recommended);
    assertEquals(1, recommended.size());
    RecommendedItem firstRecommended = recommended.get(0);
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.1f, firstRecommended.getValue(), EPSILON);
    recommender.refresh(null);
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.1f, firstRecommended.getValue(), EPSILON);
  }
View Full Code Here

  public void testBestRating() throws Exception {
    Recommender recommender = buildRecommender();
    List<RecommendedItem> recommended = recommender.recommend(1, 1);
    assertNotNull(recommended);
    assertEquals(1, recommended.size());
    RecommendedItem firstRecommended = recommended.get(0);
    // item one should be recommended because it has a greater rating/score
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.1f, firstRecommended.getValue(), EPSILON);
  }
View Full Code Here

  public void testRecommender() throws Exception {
    Recommender recommender = buildRecommender();
    List<RecommendedItem> recommended = recommender.recommend(1, 1);
    assertNotNull(recommended);
    assertEquals(1, recommended.size());
    RecommendedItem firstRecommended = recommended.get(0);
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.1f, firstRecommended.getValue(), EPSILON);
    recommender.refresh(null);
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.1f, firstRecommended.getValue(), EPSILON);
  }
View Full Code Here

  public void testBestRating() throws Exception {
    Recommender recommender = buildRecommender();
    List<RecommendedItem> recommended = recommender.recommend(1, 1);
    assertNotNull(recommended);
    assertEquals(1, recommended.size());
    RecommendedItem firstRecommended = recommended.get(0);
    // item one should be recommended because it has a greater rating/score
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.1f, firstRecommended.getValue(), EPSILON);
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.recommender.RecommendedItem

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.