Mahout:DataModel doesn't have preference values

简介:

   Mahout in Action 在第3.3节 Coping without preference values 提到了没有偏好值的数据场景,能够得到1~5分偏好评分的场景太难了,这需要有一个略微复杂点的价值判断过程.相比之下,"顶"和"踩"就来的简单的多.看下面的图,对于布尔型数据模型,已经简化成为:喜欢,不喜欢,不知道

  

  作者给出了一个"样例代码",这段样例代码运行到最后是会抛出异常的,这个作者也明确指出来了(P37).

  "You should find that running this code results in an IllegalArgumentException from the PearsonCorrelationSimilarity constructor. This may be surprising at first: isn’t GenericBooleanPrefDataModel also a DataModel, and nearly the same as GenericDataModel except that it doesn’t store distinct preference values?"

 

  但是,这个异常还是被提到了论坛里面: http://www.manning-sandbox.com/thread.jspa?threadID=41765

INFO: Processed 943  users
Feb 5 , 2011  10 : 54 : 31  AM org.slf4j.impl.JCLLoggerAdapter info
INFO: Beginning evaluation using 0.9  of GenericBooleanPrefDataModel[users: 1 , 2 , 3 ...]
Exception in thread "main"  java.lang.IllegalArgumentException: DataModel doesn't have preference values
at com.google.common.base.Preconditions.checkArgument(Preconditions.java: 90 )
at org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity.<init>(PearsonCorrelationSimilarity.java: 74 )
at org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity.<init>(PearsonCorrelationSimilarity.java: 66 )
at mia.recommender.ch02.RecommenderIntro$ 6 .buildRecommender(RecommenderIntro.java: 163 )
at org.apache.mahout.cf.taste.impl.eval.AbstractDifferenceRecommenderEvaluator.evaluate(AbstractDifferenceRecommenderEvaluator.java: 124 )
at mia.recommender.ch02.RecommenderIntro.eg6(RecommenderIntro.java: 175 )
at mia.recommender.ch02.RecommenderIntro.main(RecommenderIntro.java: 38 ) 

 

    这个其实,耐心点往后读一点就能看到作者的解释.不过,话说回来,怎样才能将这段代码运行通过呢?究其原因是选择了PearsonCorrelationSimilarity相似度算法,而这个算法是要求偏好值的,所以抛出了" DataModel doesn't have preference values"的异常,我们只需要选适当的相似度算法(或者说不需要偏好值的算法)就可以解决这个问题.这里可选的方案有: Tanimoto coefficient算法和 log-likelihood算法,对应到具体的类:TanimotoCoefficientSimilarity 和 LogLikelihoodSimilarity

 

 自己动手试一下吧

 

Mahout in Action 书中对应的代码在项目:https://github.com/tdunning/MiA/tree/master/src/main

 

小图一张

 

目录
相关文章
|
算法 Linux Shell
SGAT丨Single Gene Analysis Tool
SGAT丨Single Gene Analysis Tool
|
机器学习/深度学习 自然语言处理 数据可视化
M2E2: Cross-media Structured Common Space for Multimedia Event Extraction 论文解读
我们介绍了一个新的任务,多媒体事件抽取(M2E2),旨在从多媒体文档中抽取事件及其参数。我们开发了第一个基准测试
109 0
|
分布式计算 Apache Spark
《How to Integrate Spark MLlib and Apache Solr to Build Real-Time Entity Type Recognition System for Better Query Understanding》电子版地址
How to Integrate Spark MLlib and Apache Solr to Build Real-Time Entity Type Recognition System for Better Query Understanding
89 0
《How to Integrate Spark MLlib and Apache Solr to Build Real-Time Entity Type Recognition System for Better Query Understanding》电子版地址
|
弹性计算 Linux Docker
PAT (Advanced Level) Practice - 1030 Travel Plan(30 分)
PAT (Advanced Level) Practice - 1030 Travel Plan(30 分)
112 0
PAT (Advanced Level) Practice - 1129 Recommendation System(25 分)
PAT (Advanced Level) Practice - 1129 Recommendation System(25 分)
106 0
PAT (Advanced Level) Practice - 1044 Shopping in Mars(25 分)
PAT (Advanced Level) Practice - 1044 Shopping in Mars(25 分)
126 0
PAT (Advanced Level) Practice - 1143 Lowest Common Ancestor(30 分)
PAT (Advanced Level) Practice - 1143 Lowest Common Ancestor(30 分)
121 0
PAT (Advanced Level) Practice - 1107 Social Clusters(30 分)
PAT (Advanced Level) Practice - 1107 Social Clusters(30 分)
145 0
|
存储 测试技术
PAT (Advanced Level) Practice - 1131 Subway Map(30 分)
PAT (Advanced Level) Practice - 1131 Subway Map(30 分)
115 0