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

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


    random = RandomUtils.getRandom();
  }

  public void testSlopeOneLoad() throws Exception {
    DataModel model = createModel();
    Recommender recommender = new CachingRecommender(new SlopeOneRecommender(model));
    doTestLoad(recommender, 60);
  }
View Full Code Here


  }

  public void testItemLoad() throws Exception {
    DataModel model = createModel();
    ItemSimilarity itemSimilarity = new PearsonCorrelationSimilarity(model);
    Recommender recommender = new CachingRecommender(new GenericItemBasedRecommender(model, itemSimilarity));
    doTestLoad(recommender, 240);
  }
View Full Code Here

  public void testUserLoad() throws Exception {
    DataModel model = createModel();
    UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(model);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(10, userSimilarity, model);
    Recommender recommender =
            new CachingRecommender(new GenericUserBasedRecommender(model, neighborhood, userSimilarity));
    doTestLoad(recommender, 40);
  }
View Full Code Here

  }

  public void testFile() throws Exception {
    UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(model);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, userSimilarity, model);
    Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, userSimilarity);
    assertEquals(2, recommender.recommend("A123", 3).size());
    assertEquals(2, recommender.recommend("B234", 3).size());
    assertEquals(1, recommender.recommend("C345", 3).size());

    // Make sure this doesn't throw an exception
    model.refresh(null);
  }
View Full Code Here

* <p>Tests {@link GenericUserBasedRecommender}.</p>
*/
public final class GenericUserBasedRecommenderTest extends TasteTestCase {

  public void testRecommender() throws Exception {
    Recommender recommender = buildRecommender();
    List<RecommendedItem> recommended = recommender.recommend("test1", 1);
    assertNotNull(recommended);
    assertEquals(1, recommended.size());
    RecommendedItem firstRecommended = recommended.get(0);
    assertEquals(new GenericItem<String>("2"), firstRecommended.getItem());
    assertEquals(0.3, firstRecommended.getValue());
    recommender.refresh(null);
    assertEquals(new GenericItem<String>("2"), firstRecommended.getItem());
    assertEquals(0.3, firstRecommended.getValue());
  }
View Full Code Here

    users.add(getUser("test4", 0.1, 0.4, 0.5, 0.8, 0.9, 1.0));
    users.add(getUser("test5", 0.2, 0.3, 0.6, 0.7, 0.1, 0.2));
    DataModel dataModel = new GenericDataModel(users);
    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, dataModel);
    Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
    List<RecommendedItem> fewRecommended = recommender.recommend("test1", 2);
    List<RecommendedItem> moreRecommended = recommender.recommend("test1", 4);
    for (int i = 0; i < fewRecommended.size(); i++) {
      assertEquals(fewRecommended.get(i).getItem(), moreRecommended.get(i).getItem());
    }
    recommender.refresh(null);
    for (int i = 0; i < fewRecommended.size(); i++) {
      assertEquals(fewRecommended.get(i).getItem(), moreRecommended.get(i).getItem());
    }
  }
View Full Code Here

    users.add(getUser("test2", 0.2, 0.3, 0.3, 0.6));
    users.add(getUser("test3", 0.4, 0.4, 0.5, 0.9));
    DataModel dataModel = new GenericDataModel(users);
    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(1, similarity, dataModel);
    Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
    List<RecommendedItem> originalRecommended = recommender.recommend("test1", 2);
    List<RecommendedItem> rescoredRecommended =
            recommender.recommend("test1", 2, new ReversingRescorer<Item>());
    assertNotNull(originalRecommended);
    assertNotNull(rescoredRecommended);
    assertEquals(2, originalRecommended.size());
    assertEquals(2, rescoredRecommended.size());
    assertEquals(originalRecommended.get(0).getItem(), rescoredRecommended.get(1).getItem());
View Full Code Here

    assertEquals(originalRecommended.get(0).getItem(), rescoredRecommended.get(1).getItem());
    assertEquals(originalRecommended.get(1).getItem(), rescoredRecommended.get(0).getItem());
  }

  public void testEstimatePref() throws Exception {
    Recommender recommender = buildRecommender();
    assertEquals(0.3, recommender.estimatePreference("test1", "2"));
  }
View Full Code Here

    Recommender recommender = buildRecommender();
    assertEquals(0.3, recommender.estimatePreference("test1", "2"));
  }

  public void testBestRating() throws Exception {
    Recommender recommender = buildRecommender();
    List<RecommendedItem> recommended = recommender.recommend("test1", 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(new GenericItem<String>("2"), firstRecommended.getItem());
View Full Code Here

*/
public final class CachingRecommenderTest extends TasteTestCase {

  public void testRecommender() throws Exception {
    AtomicInteger recommendCount = new AtomicInteger();
    Recommender mockRecommender = new MockRecommender(recommendCount);

    Recommender cachingRecommender = new CachingRecommender(mockRecommender);
    cachingRecommender.recommend("1", 1);
    assertEquals(1, recommendCount.get());
    cachingRecommender.recommend("2", 1);
    assertEquals(2, recommendCount.get());
    cachingRecommender.recommend("1", 1);
    assertEquals(2, recommendCount.get());
    cachingRecommender.recommend("2", 1);
    assertEquals(2, recommendCount.get());
    cachingRecommender.refresh(null);
    cachingRecommender.recommend("1", 1);
    assertEquals(3, recommendCount.get());
    cachingRecommender.recommend("2", 1);
    assertEquals(4, recommendCount.get());
    cachingRecommender.recommend("3", 1);
    assertEquals(5, recommendCount.get());

    // Results from this recommend() method can be cached...
    Rescorer<Item> rescorer = NullRescorer.getItemInstance();
    cachingRecommender.refresh(null);
    cachingRecommender.recommend("1", 1, rescorer);
    assertEquals(6, recommendCount.get());
    cachingRecommender.recommend("2", 1, rescorer);
    assertEquals(7, recommendCount.get());
    cachingRecommender.recommend("1", 1, rescorer);
    assertEquals(7, recommendCount.get());
    cachingRecommender.recommend("2", 1, rescorer);
    assertEquals(7, recommendCount.get());

    // until you switch Rescorers
    cachingRecommender.recommend("1", 1, null);
    assertEquals(8, recommendCount.get());
    cachingRecommender.recommend("2", 1, null);
    assertEquals(9, recommendCount.get());

    cachingRecommender.refresh(null);
    cachingRecommender.estimatePreference("test1", "1");
    assertEquals(10, recommendCount.get());
    cachingRecommender.estimatePreference("test1", "2");
    assertEquals(11, recommendCount.get());
    cachingRecommender.estimatePreference("test1", "2");
    assertEquals(11, recommendCount.get());
  }
View Full Code Here

TOP

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

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.