Package org.apache.mahout.cf.taste.model

Examples of org.apache.mahout.cf.taste.model.Item


    User theUser = model.getUser(userID);
    Preference actualPref = theUser.getPreferenceFor(itemID);
    if (actualPref != null) {
      return actualPref.getValue();
    }
    Item item = model.getItem(itemID);
    return doEstimatePreference(theUser, item);
  }
View Full Code Here


  @Override
  public List<RecommendedItem> mostSimilarItems(Object itemID,
                                                int howMany,
                                                Rescorer<Pair<Item, Item>> rescorer) throws TasteException {
    Item toItem = getDataModel().getItem(itemID);
    TopItems.Estimator<Item> estimator = new MostSimilarEstimator(toItem, similarity, rescorer);
    return doMostSimilarItems(itemID, howMany, estimator);
  }
View Full Code Here

      throw new IllegalArgumentException("howMany must be at least 1");
    }

    DataModel model = getDataModel();
    User user = model.getUser(userID);
    Item recommendedItem = model.getItem(itemID);
    TopItems.Estimator<Item> estimator = new RecommendedBecauseEstimator(user, recommendedItem, similarity);

    Collection<Item> allUserItems = new FastSet<Item>();
    Preference[] prefs = user.getPreferencesAsArray();
    for (Preference pref : prefs) {
View Full Code Here

  private List<RecommendedItem> doMostSimilarItems(Object itemID,
                                                   int howMany,
                                                   TopItems.Estimator<Item> estimator) throws TasteException {
    DataModel model = getDataModel();
    Item toItem = model.getItem(itemID);
    Collection<Item> allItems = new FastSet<Item>(model.getNumItems());
    for (Item item : model.getItems()) {
      allItems.add(item);
    }
    allItems.remove(toItem);
View Full Code Here

*/
public final class AveragingPreferenceInferrerTest extends TasteTestCase {

  public void testInferrer() throws TasteException {
    User user1 = getUser("test1", 3.0, -2.0, 5.0);
    Item item = new GenericItem<String>("3");
    DataModel model = new GenericDataModel(Collections.singletonList(user1));
    PreferenceInferrer inferrer = new AveragingPreferenceInferrer(model);
    double inferred = inferrer.inferPreference(user1, item);
    assertEquals(2.0, inferred);
  }
View Full Code Here

    List<User> users = new ArrayList<User>(3);
    users.add(getUser("test1", 0.1, 0.2));
    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);
    Item item1 = new GenericItem<String>("0");
    Item item2 = new GenericItem<String>("1");
    Item item3 = new GenericItem<String>("2");
    Item item4 = new GenericItem<String>("3");
    Collection<GenericItemSimilarity.ItemItemSimilarity> similarities =
            new ArrayList<GenericItemSimilarity.ItemItemSimilarity>(6);
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item2, 1.0));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item3, 0.5));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item4, 0.2));
View Full Code Here

  private static ItemBasedRecommender buildRecommender() {
    DataModel dataModel = new GenericDataModel(getMockUsers());
    Collection<GenericItemSimilarity.ItemItemSimilarity> similarities =
            new ArrayList<GenericItemSimilarity.ItemItemSimilarity>(2);
    Item item1 = new GenericItem<String>("0");
    Item item2 = new GenericItem<String>("1");
    Item item3 = new GenericItem<String>("2");
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item2, 1.0));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item3, 0.5));
    ItemSimilarity similarity = new GenericItemSimilarity(similarities);
    return new GenericItemBasedRecommender(dataModel, similarity);
  }
View Full Code Here

    users.add(getUser("test3", 0.4, 0.3, 0.5, 0.1, 0.1));
    users.add(getUser("test4", 0.7, 0.3, 0.8, 0.5, 0.6));
    DataModel dataModel = new GenericDataModel(users);
    Collection<GenericItemSimilarity.ItemItemSimilarity> similarities =
            new ArrayList<GenericItemSimilarity.ItemItemSimilarity>(10);
    Item item1 = new GenericItem<String>("0");
    Item item2 = new GenericItem<String>("1");
    Item item3 = new GenericItem<String>("2");
    Item item4 = new GenericItem<String>("3");
    Item item5 = new GenericItem<String>("4");
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item2, 1.0));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item3, 0.8));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item4, -0.6));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item5, 1.0));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item2, item3, 0.9));
View Full Code Here

* <p>Tests {@link GenericItemSimilarity}.</p>
*/
public final class GenericItemSimilarityTest extends SimilarityTestCase {

  public void testSimple() {
    Item item1 = new GenericItem<String>("1");
    Item item2 = new GenericItem<String>("2");
    Item item3 = new GenericItem<String>("3");
    Item item4 = new GenericItem<String>("4");
    List<GenericItemSimilarity.ItemItemSimilarity> similarities =
            new ArrayList<GenericItemSimilarity.ItemItemSimilarity>(4);
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item2, 0.5));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item2, item1, 0.6));
    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(item1, item1, 0.5));
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.model.Item

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.