通过Mahout构建推荐系统时,假设我们须要添�某些过滤规则(比方:item的创建时间在一年以内),则须要用到IDRescorer接口,该接口源代码例如以下:

package org.apache.mahout.cf.taste.recommender;
/**
 * <p>
 * A {@link Rescorer} which operates on {@code long} primitive IDs, rather than arbitrary {@link Object}s.
 * This is provided since most uses of this interface in the framework take IDs (as {@code long}) as an
 * argument, and so this can be used to avoid unnecessary boxing/unboxing.
 * </p>
 */
public interface IDRescorer {
  
  /**
   * @param id
   *          ID of thing (user, item, etc.) to rescore
   * @param originalScore
   *          original score
   * @return modified score, or {@link Double#NaN} to indicate that this should be excluded entirely
   */
  double rescore(long id, double originalScore);
  
  /**
   * Returns {@code true} to exclude the given thing.
   *
   * @param id
   *          ID of thing (user, item, etc.) to rescore
   * @return {@code true} to exclude, {@code false} otherwise
   */
  boolean isFiltered(long id);
  
}

该接口规定了两个必须实现的方法:
1.rescore方法
功能:定义又一次评分的逻辑。依据新的规则,为指定id的item又一次评分。
返回:重评后的分数
输入參数:item的id,该item原来的评分
调用该方法的方法包含:


2.isFiltered
功能:定义过滤规则。推断指定id的item,依据新的规则,是否该排除在外,返回true就是该item应该排除在结果之外。
返回:true or false
输入參数:指定的id
调用该方法的方法包含:



不管是否须要依据特定规则过滤推荐结果,都必须先创建org.apache.mahout.cf.taste.recommender.Recommender类的对象r,然后通过对象r来运行推荐方法获得针对特定id用户的推荐结果List。

当无需使用特定规则过滤推荐结果时,仅仅需使用Recommender对象的例如以下方法获得推荐结果:
  /**
   * @param userID
   *          user for which recommendations are to be computed
   * @param howMany
   *          desired number of recommendations
   * @return {@link List} of recommended {@link RecommendedItem}s, ordered from most strongly recommend to
   *         least
   * @throws TasteException
   *           if an error occurs while accessing the {@link DataModel}
   */

List<RecommendedItem> recommend(long userID, int howMany) throws TasteException;


当须要依据特定规则过滤推荐结果时,需使用Recommender对象的例如以下方法获得推荐结果:
  /**
   * @param userID
   *          user for which recommendations are to be computed
   * @param howMany
   *          desired number of recommendations
   * @param rescorer
   *          rescoring function to apply before final list of recommendations is determined
   * @return {@link List} of recommended {@link RecommendedItem}s, ordered from most strongly recommend to
   *         least
   * @throws TasteException
   *           if an error occurs while accessing the {@link DataModel}
   */

List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException;

当中,最后一个參数就是本文開始提到的IDRescorer。
所以,当须要通过特定规则过滤推荐结果时,需先实现IDRescorer接口,定义评分逻辑和排除规则。

【甘道夫】通过Mahout构建推荐系统--通过IDRescorer扩展评分规则的更多相关文章

  1. 【甘道夫】Win7x64环境下编译Apache Hadoop2.2.0的Eclipse小工具

    目标: 编译Apache Hadoop2.2.0在win7x64环境下的Eclipse插件 环境: win7x64家庭普通版 eclipse-jee-kepler-SR1-win32-x86_64.z ...

  2. 【甘道夫】MapReduce实现矩阵乘法--实现代码

    之前写了一篇分析MapReduce实现矩阵乘法算法的文章: [甘道夫]Mapreduce实现矩阵乘法的算法思路 为了让大家更直观的了解程序运行,今天编写了实现代码供大家參考. 编程环境: java v ...

  3. 【甘道夫】通过Mahout构建贝叶斯文本分类器案例具体解释

    背景&目标: 1.sport.tar 是体育类的文章,一共同拥有10个类别.    用这些原始材料构造一个体育类的文本分类器,并測试对照bayes和cbayes的效果:    记录分类器的构造 ...

  4. 【甘道夫】怎样在cdh5.2上执行mahout的itemcf on hadoop

    环境: hadoop-2.5.0-cdh5.2.0 mahout-0.9-cdh5.2.0 步骤: 基本思路是,将mahout下的全部jar包都引入hadoop的classpath就可以,所以改动了$ ...

  5. 【甘道夫】使用HIVE SQL实现推荐系统数据补全

    需求 在推荐系统场景中,假设基础行为数据太少,或者过于稀疏,通过推荐算法计算得出的推荐结果非常可能达不到要求的数量. 比方,希望针对每一个item或user推荐20个item,可是通过计算仅仅得到8个 ...

  6. 【甘道夫】并行化频繁模式挖掘算法FP Growth及其在Mahout下的命令使用

    今天调研了并行化频繁模式挖掘算法PFP Growth及其在Mahout下的命令使用,简单记录下试验结果,供以后查阅: 环境:Jdk1.7 + Hadoop2.2.0单机伪集群 +  Mahout0.6 ...

  7. 【甘道夫】HBase基本数据操作的详细说明【完整版,精绝】

    介绍 之前具体写了一篇HBase过滤器的文章.今天把基础的表和数据相关操作补上. 本文档參考最新(截止2014年7月16日)的官方Ref Guide.Developer API编写. 全部代码均基于& ...

  8. 【甘道夫】HBase连接池 -- HTablePool是Deprecated之后

    说明: 近期两天在调研HBase的连接池,有了一些收获,特此记录下来. 本文先将官方文档(http://hbase.apache.org/book.html)9.3.1.1节翻译,方便大家阅读,然后查 ...

  9. 【甘道夫】HBase基本数据操作详解【完整版,绝对精品】

    引言 之前详细写了一篇HBase过滤器的文章,今天把基础的表和数据相关操作补上. 本文档参考最新(截止2014年7月16日)的官方Ref Guide.Developer API编写. 所有代码均基于“ ...

随机推荐

  1. hdu 4813(2013长春现场赛A题)

    把一个字符串分成N个字符串 每个字符串长度为m Sample Input12 5 // n mklmbbileay Sample Outputklmbbileay # include <iost ...

  2. Two Seals codeforces 837c

    Two Seals 一个矩形a*b,若干子矩形,子矩形中选2个,不重叠能覆盖最大 思路: 枚举: 代码: #include <cstdio> #include <cstring> ...

  3. Web前端开发最佳实践(9):CSS代码太太乱,重复代码太多?你需要精简CSS代码

    前言 提高网站整体加载速度的一个重要手段就是提高代码文件的网络传输速度.之前提到过,所有的代码文件都应该是经过压缩了的,这可提高网络传输速度,提高性能.除了压缩代码之外,精简代码也是一种减小代码文件大 ...

  4. mysql 插入时带判断条件

    INSERT INTO table (f1 ,f2 ,f3) ,'a', FROM DUAL WHERE NOT EXISTS ( FROM table2 where a = b) DUAL 为临时表 ...

  5. Android 最基础生命周期及旋转屏幕问题

    public class MainActivity extends Activity { private static final String TAG ="MainActivity&quo ...

  6. CodeForces - 600C Make Palindrome 贪心

    A string is called palindrome if it reads the same from left to right and from right to left. For ex ...

  7. 【原创】MySQL Replay线上流量压测工具

    一. 背景 去年做过一次mysql trace 重放的测试,由于performance schema本身采集样本的长度等限制,实际回放的成功率比较低. 最近找到一款开源的工具,基于TCPCopy实现了 ...

  8. 深度学习基础系列(五)| 深入理解交叉熵函数及其在tensorflow和keras中的实现

    在统计学中,损失函数是一种衡量损失和错误(这种损失与“错误地”估计有关,如费用或者设备的损失)程度的函数.假设某样本的实际输出为a,而预计的输出为y,则y与a之间存在偏差,深度学习的目的即是通过不断地 ...

  9. Git 统计提交代码行数

    指定用户名 git log --author="your_name_here" --pretty=tformat: --numstat | awk '{ add += $1; su ...

  10. 【WIN10】我的第一個WIN10-UWP應用——古文觀止

    已上架,下載地址:https://www.microsoft.com/store/apps/9nblggh6cc32 特點是:繁體豎排,隱藏/顯示標點符號. 截幾張圖來瞅瞅. 1.主界面 這張圖使用的 ...