通过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. js对象的属性:数据(data)属性和访问器(accessor)属性

    此文为转载,原文: 深入理解对象的数据属性与访问器属性 创建对象的方式有两种:第一种,通过new操作符后面跟Object构造函数,第二种,对象字面量方式.如下 var person = new Obj ...

  2. MEF实现设计上的“松耦合”(一)

    1.什么是MEF 先来看msdn上面的解释:MEF(Managed Extensibility Framework)是一个用于创建可扩展的轻型应用程序的库. 应用程序开发人员可利用该库发现并使用扩展, ...

  3. python 库资源大全

    偶然的机会翻到这篇文章,很全面,来源:  Python 资源大全中文版       哪些 Python 库让你相见恨晚? 环境管理 管理 Python 版本和环境的工具 p:非常简单的交互式 pyth ...

  4. LoadRunner测试ajax框架,回放后系统中没有产生数据解决方法

    1.QTP11 下载地址:http://www.genilogix.com/downloads/unified-functional-testing/quicktest-professional-11 ...

  5. 常用网络命令(windows)

      Ping命令的常用参数选项 ·ping IP –t 连续对IP地址执行Ping命令,直到被用户以Ctrl+C中断. ·ping IP -l 3000 指定Ping命令中的数据长度为3000字节,而 ...

  6. tp5总结(三)

    1.控制器 1-1.加载页面[使用系统函数eg:http://ww:7070/tp5-2/public/admin/test/load] 1-2.加载页面[继承控制器方法eg:http://ww:70 ...

  7. 终端(terminal)、tty、shell、控制台(console)、bash之间的区别与联系

    1.终端(terminal) 终端(termimal)= tty(Teletypewriter, 电传打印机),作用是提供一个命令的输入输出环境,在linux下使用组合键ctrl+alt+T打开的就是 ...

  8. HTML Input 表单校验之datatype

    凡要验证格式的元素均需绑定datatype属性,datatype可选值内置有10类,用来指定不同的验证格式. 如果还不能满足您的验证需求,可以传入自定义datatype,自定义datatype是一个非 ...

  9. webview内部跳转判断

    重写webview内的方法 webView.setWebViewClient(new WebViewClient() { @Override // 在点击请求的是链接是才会调用,重写此方法返回true ...

  10. CodeForces - 725D Contest Balloons 贪心

              D. Contest Balloons          time limit per test 3 seconds         memory limit per test 2 ...