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

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


        if (!relevantItems.contains(pref.getItem())) {
          trainingPrefs.add(pref);
        }
      }
      if (!trainingPrefs.isEmpty()) {
        User trainingUser = new GenericUser<String>(id.toString(), trainingPrefs);
        trainingUsers.add(trainingUser);
      }
    } else {
      trainingUsers.add(user2);
    }
View Full Code Here


    List<RecommendedItem> recommended = topRecsByUserID.get(userID);
    if (recommended == null) {
      return Collections.emptyList();
    }

    User theUser = getDataModel().getUser(userID);
    List<RecommendedItem> rescored = new ArrayList<RecommendedItem>(recommended.size());
    // Only add items the user doesn't already have a preference for.
    // And that the rescorer doesn't "reject".
    for (RecommendedItem recommendedItem : recommended) {
      Item item = recommendedItem.getItem();
      if (rescorer != null && rescorer.isFiltered(item)) {
        continue;
      }
      if (theUser.getPreferenceFor(item.getID()) == null &&
          (rescorer == null || !Double.isNaN(rescorer.rescore(item, recommendedItem.getValue())))) {
        rescored.add(recommendedItem);
      }
    }
    Collections.sort(rescored, new ByRescoreComparator(rescorer));
View Full Code Here

  public double estimatePreference(Object userID, Object itemID) throws TasteException {
    if (userID == null || itemID == null) {
      throw new IllegalArgumentException("userID or itemID is null");
    }
    DataModel model = getDataModel();
    User theUser = model.getUser(userID);
    Preference actualPref = theUser.getPreferenceFor(itemID);
    if (actualPref != null) {
      return actualPref.getValue();
    }
    checkClustersBuilt();
    List<RecommendedItem> topRecsForUser = topRecsByUserID.get(userID);
View Full Code Here

      }
    }
    log.debug("Training against {} preferences", trainingPrefs.size());
    log.debug("Evaluating accuracy of {} preferences", testPrefs.size());
    if (!trainingPrefs.isEmpty()) {
      User trainingUser = new GenericUser<String>(user.getID().toString(), trainingPrefs);
      trainingUsers.add(trainingUser);
      if (!testPrefs.isEmpty()) {
        testUserPrefs.put(trainingUser, testPrefs);
      }
    }
View Full Code Here

  }

  public void testUserRescorer() throws Exception {
    Rescorer<User> rescorer = NullRescorer.getUserInstance();
    assertNotNull(rescorer);
    User user = new GenericUser<String>("test", Collections.<Preference>emptyList());
    assertEquals(1.0, rescorer.rescore(user, 1.0));
    assertEquals(1.0, rescorer.rescore(null, 1.0));
    assertEquals(0.0, rescorer.rescore(user, 0.0));
    assertTrue(Double.isNaN(rescorer.rescore(user, Double.NaN)));
  }
View Full Code Here

    // do nothing
  }

  @Override
  public DataModel getDataModel() {
    User user1 = new GenericUser<String>("1", Collections.<Preference>emptyList());
    User user2 = new GenericUser<String>("2", Collections.<Preference>emptyList());
    User user3 = new GenericUser<String>("3", Collections.<Preference>emptyList());
    List<User> users = new ArrayList<User>(3);
    users.add(user1);
    users.add(user2);
    users.add(user3);
    return new GenericDataModel(users);
View Full Code Here

  public void testMostSimilar() throws Exception {
    UserBasedRecommender recommender = buildRecommender();
    List<User> similar = recommender.mostSimilarUsers("test1", 2);
    assertNotNull(similar);
    assertEquals(2, similar.size());
    User first = similar.get(0);
    User second = similar.get(1);
    assertEquals("test2", first.getID());
    assertEquals("test3", second.getID());
  }
View Full Code Here

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

    log.debug("Recommending items for user ID '{}'", userID);

    User theUser = getDataModel().getUser(userID);
    if (getNumPreferences(theUser) == 0) {
      return Collections.emptyList();
    }

    Set<Item> allItems = getAllOtherItems(theUser);
View Full Code Here

  }

  @Override
  public double estimatePreference(Object userID, Object itemID) throws TasteException {
    DataModel model = getDataModel();
    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

    if (howMany < 1) {
      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) {
      allUserItems.add(pref.getItem());
    }
    allUserItems.remove(recommendedItem);
View Full Code Here

TOP

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

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.