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

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


      throw new IllegalArgumentException("howMany must be at least 1");
    }
    log.debug("Recommending items for user ID '{}'", userID);
    checkAverageDiffsBuilt();

    User theUser = getDataModel().getUser(userID);
    Set<Item> allItems = getAllOtherItems(theUser);

    TopItems.Estimator<Item> estimator = new Estimator(userID);

    List<RecommendedItem> topItems = TopItems.getTopItems(howMany, allItems, rescorer, estimator);
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();
    }
    checkAverageDiffsBuilt();
    return doEstimatePreference(userID, itemID);
View Full Code Here

  @Override
  public void setPreference(Object userID, Object itemID, double value) throws TasteException {
    DataModel dataModel = getDataModel();
    double prefDelta;
    try {
      User theUser = dataModel.getUser(userID);
      Preference oldPref = theUser.getPreferenceFor(itemID);
      prefDelta = oldPref == null ? value : value - oldPref.getValue();
    } catch (NoSuchUserException nsee) {
      prefDelta = value;
    }
    super.setPreference(userID, itemID, value);
View Full Code Here

  }

  @Override
  public void removePreference(Object userID, Object itemID) throws TasteException {
    DataModel dataModel = getDataModel();
    User theUser = dataModel.getUser(userID);
    Preference oldPref = theUser.getPreferenceFor(itemID);
    super.removePreference(userID, itemID);
    if (oldPref != null) {
      double value = oldPref.getValue();
      try {
        buildAveragesLock.writeLock().lock();
View Full Code Here

    }
  }

  @Override
  public Set<Item> getRecommendableItems(Object userID) throws TasteException {
    User user = dataModel.getUser(userID);
    Set<Item> result = allRecommendableItemIDs.clone();
    Iterator<Item> it = result.iterator();
    while (it.hasNext()) {
      if (user.getPreferenceFor(it.next().getID()) != null) {
        it.remove();
      }
    }
    return result;
  }
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);
    Collection<User> theNeighborhood = neighborhood.getUserNeighborhood(userID);
    log.trace("UserNeighborhood is: {}", neighborhood);

    if (theNeighborhood.isEmpty()) {
      return Collections.emptyList();
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();
    }
    Collection<User> theNeighborhood = neighborhood.getUserNeighborhood(userID);
    Item item = model.getItem(itemID);
View Full Code Here

  @Override
  public List<User> mostSimilarUsers(Object userID,
                                     int howMany,
                                     Rescorer<Pair<User, User>> rescorer) throws TasteException {
    User toUser = getDataModel().getUser(userID);
    TopItems.Estimator<User> estimator = new MostSimilarEstimator(toUser, similarity, rescorer);
    return doMostSimilarUsers(howMany, estimator);
  }
View Full Code Here

                       Recommender recommender)
          throws TasteException {
    RunningAverage average = new FullRunningAverage();
    for (Map.Entry<User, Collection<Preference>> entry : testUserPrefs.entrySet()) {
      for (Preference realPref : entry.getValue()) {
        User testUser = entry.getKey();
        try {
          double estimatedPreference =
                  recommender.estimatePreference(testUser.getID(), realPref.getItem().getID());
          if (!Double.isNaN(estimatedPreference)) {
            double diff = realPref.getValue() - estimatedPreference;
            average.addDatum(diff * diff);
          }
        } catch (NoSuchUserException nsee) {
          // It's possible that an item exists in the test data but not training data in which case
          // NSEE will be thrown. Just ignore it and move on.
          log.info("Element exists in test data but not training data: {}", testUser.getID(), nsee);
        }
      }
    }
    return Math.sqrt(average.getAverage());
  }
View Full Code Here

                       Recommender recommender)
          throws TasteException {
    RunningAverage average = new FullRunningAverage();
    for (Map.Entry<User, Collection<Preference>> entry : testUserPrefs.entrySet()) {
      for (Preference realPref : entry.getValue()) {
        User testUser = entry.getKey();
        try {
          double estimatedPreference =
                  recommender.estimatePreference(testUser.getID(), realPref.getItem().getID());
          if (!Double.isNaN(estimatedPreference)) {
            average.addDatum(Math.abs(realPref.getValue() - estimatedPreference));
          }
        } catch (NoSuchUserException nsue) {
          // It's possible that an item exists in the test data but not training data in which case
          // NSEE will be thrown. Just ignore it and move on.
          log.debug("User exists in test data but not training data: {}", testUser.getID(), nsue);
        } catch (NoSuchItemException nsie) {
          log.debug("Item exists in test data but not training data: {}", realPref.getItem().getID(), nsie);
        }
      }
    }
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.