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

 

小图一张

 

目录
相关文章
|
8月前
|
消息中间件 Oracle 关系型数据库
Note_Logistics_Day03
Note_Logistics_Day03
52 0
|
8月前
|
canal 消息中间件 关系型数据库
Note_Logistics_Day04
Note_Logistics_Day04
58 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
92 0
《How to Integrate Spark MLlib and Apache Solr to Build Real-Time Entity Type Recognition System for Better Query Understanding》电子版地址
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
133 0
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
PAT (Advanced Level) Practice - 1143 Lowest Common Ancestor(30 分)
PAT (Advanced Level) Practice - 1143 Lowest Common Ancestor(30 分)
129 0
PAT (Advanced Level) Practice - 1030 Travel Plan(30 分)
PAT (Advanced Level) Practice - 1030 Travel Plan(30 分)
115 0
PAT (Advanced Level) Practice - 1076 Forwards on Weibo(30 分)
PAT (Advanced Level) Practice - 1076 Forwards on Weibo(30 分)
119 0
PAT (Advanced Level) Practice - 1044 Shopping in Mars(25 分)
PAT (Advanced Level) Practice - 1044 Shopping in Mars(25 分)
133 0
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
108 0
PAT (Advanced Level) Practice - 1129 Recommendation System(25 分)
PAT (Advanced Level) Practice - 1129 Recommendation System(25 分)
110 0