zoukankan      html  css  js  c++  java
  • mahout过滤推荐结果 Recommender.recommend(long userID, int howMany, IDRescorer rescorer)

    Recommender.recommend(uid, RECOMMENDER_NUM, rescorer);
    Recommender.recommend(long userID, int howMany, IDRescorer rescorer): 获得推荐结果,给userID推荐howMany个Item,凡rescorer中包含的Item都过滤掉。

    其中源码中调用了以下方法 TopItems.getTopItems

    TopItems类的.getTopItems

    public static List<RecommendedItem> getTopItems(int howMany,
                                                      LongPrimitiveIterator possibleItemIDs,
                                                      IDRescorer rescorer,
                                                      Estimator<Long> estimator) throws TasteException {
        Preconditions.checkArgument(possibleItemIDs != null, "argument is null");
        Preconditions.checkArgument(estimator != null, "argument is null");
    
        Queue<RecommendedItem> topItems = new PriorityQueue<RecommendedItem>(howMany + 1,
          Collections.reverseOrder(ByValueRecommendedItemComparator.getInstance()));
        boolean full = false;
        double lowestTopValue = Double.NEGATIVE_INFINITY;
        while (possibleItemIDs.hasNext()) {
          long itemID = possibleItemIDs.next();
          if (rescorer == null || !rescorer.isFiltered(itemID)) {
            double preference;
            try {
              preference = estimator.estimate(itemID);
            } catch (NoSuchItemException nsie) {
              continue;
            }
            double rescoredPref = rescorer == null ? preference : rescorer.rescore(itemID, preference);
            if (!Double.isNaN(rescoredPref) && (!full || rescoredPref > lowestTopValue)) {
              topItems.add(new GenericRecommendedItem(itemID, (float) rescoredPref));
              if (full) {
                topItems.poll();
              } else if (topItems.size() > howMany) {
                full = true;
                topItems.poll();
              }
              lowestTopValue = topItems.peek().getValue();
            }
          }
        }
        int size = topItems.size();
        if (size == 0) {
          return Collections.emptyList();
        }
        List<RecommendedItem> result = Lists.newArrayListWithCapacity(size);
        result.addAll(topItems);
        Collections.sort(result, ByValueRecommendedItemComparator.getInstance());
        return result;
      }



    recommend(long userID, int howMany): 获得推荐结果,给userID推荐howMany个Item

    estimatePreference(long userID, long itemID): 当打分为空,估计用户对物品的打分
    setPreference(long userID, long itemID, float value): 赋值用户,物品,打分
    removePreference(long userID, long itemID): 删除用户对物品的打分
    getDataModel(): 提取推荐数据

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Win7系统怎样防止注册表被篡改【系统天地】
    Win10总是自动安装应用怎么办【系统天地】
    win10系统更新完不能开机怎么办【系统天地】
    Win7系统系统还原被禁用怎么办【系统天地】
    Win7系统如何删除远程访问功能?【系统天地】
    win10系统如何修复防火墙【系统天地】
    win10如何扩大c盘空间【系统天地】
    PHP redis扩展安装
    redis的安装部署与测试
    Nginx和PHP如何配合工作
  • 原文地址:https://www.cnblogs.com/jamesf/p/4751595.html
Copyright © 2011-2022 走看看