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

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


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

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


    Recommender recommender = buildRecommender();
    assertEquals(0.3f, recommender.estimatePreference(1, 2));
  }

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

/** <p>Tests {@link CachingRecommender}.</p> */
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...
    IDRescorer 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(1, 1);
    assertEquals(10, recommendCount.get());
    cachingRecommender.estimatePreference(1, 2);
    assertEquals(11, recommendCount.get());
    cachingRecommender.estimatePreference(1, 2);
    assertEquals(11, recommendCount.get());
  }
View Full Code Here

import java.util.List;

public final class ItemUserAverageRecommenderTest extends TasteTestCase {

  public void testRecommender() throws Exception {
    Recommender recommender = new ItemUserAverageRecommender(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.35151517f, firstRecommended.getValue());
    recommender.refresh(null);
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.35151517f, firstRecommended.getValue());
  }
View Full Code Here

                    {0.2, 0.6},
                    {0.4, 0.9},
            });
    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
    Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
    List<RecommendedItem> recommended = recommender.recommend(1, 1);
    assertNotNull(recommended);
    assertEquals(0, recommended.size());
    recommender.refresh(null);
    assertNotNull(recommended);
    assertEquals(0, recommended.size());
  }
View Full Code Here

                    {0.2, 0.3, 0.6, 0.7, 0.1, 0.2},
            });

    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
    Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
    List<RecommendedItem> fewRecommended = recommender.recommend(1, 2);
    List<RecommendedItem> moreRecommended = recommender.recommend(1, 4);
    for (int i = 0; i < fewRecommended.size(); i++) {
      assertEquals(fewRecommended.get(i).getItemID(), moreRecommended.get(i).getItemID());
    }
    recommender.refresh(null);
    for (int i = 0; i < fewRecommended.size(); i++) {
      assertEquals(fewRecommended.get(i).getItemID(), moreRecommended.get(i).getItemID());
    }
  }
View Full Code Here

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

  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.34803885284992736, firstRecommended.getValue(), EPSILON);
    recommender.refresh(null);
    assertEquals(2, firstRecommended.getItemID());
    assertEquals(0.34803885284992736, firstRecommended.getValue(), EPSILON);
  }
View Full Code Here

                    {0.4, 0.4, 0.5, 0.9},
            });

    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity);
    Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2);
    List<RecommendedItem> originalRecommended = recommender.recommend(1, 2);
    List<RecommendedItem> rescoredRecommended =
        recommender.recommend(1, 2, new ReversingRescorer<Long>());
    assertNotNull(originalRecommended);
    assertNotNull(rescoredRecommended);
    assertEquals(2, originalRecommended.size());
    assertEquals(2, rescoredRecommended.size());
    assertEquals(originalRecommended.get(0).getItemID(), rescoredRecommended.get(1).getItemID());
View Full Code Here

                    {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},
            });

    Recommender recommender = new SlopeOneRecommender(dataModel);
    List<RecommendedItem> fewRecommended = recommender.recommend(1, 2);
    List<RecommendedItem> moreRecommended = recommender.recommend(1, 4);
    for (int i = 0; i < fewRecommended.size(); i++) {
      assertEquals(fewRecommended.get(i).getItemID(), moreRecommended.get(i).getItemID());
    }
    recommender.refresh(null);
    for (int i = 0; i < fewRecommended.size(); i++) {
      assertEquals(fewRecommended.get(i).getItemID(), moreRecommended.get(i).getItemID());
    }
  }
View Full Code Here

                    {0.1, 0.2},
                    {0.2, 0.3, 0.3, 0.6},
                    {0.4, 0.4, 0.5, 0.9},
            });

    Recommender recommender = new SlopeOneRecommender(dataModel);
    List<RecommendedItem> originalRecommended = recommender.recommend(1, 2);
    List<RecommendedItem> rescoredRecommended =
        recommender.recommend(1, 2, new ReversingRescorer<Long>());
    assertNotNull(originalRecommended);
    assertNotNull(rescoredRecommended);
    assertEquals(2, originalRecommended.size());
    assertEquals(2, rescoredRecommended.size());
    assertEquals(originalRecommended.get(0).getItemID(), rescoredRecommended.get(1).getItemID());
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.