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

 

小图一张

 

目录
相关文章
“Could not find suitable distribution for Requirement.parse(‘XXXX‘)”的问题
“Could not find suitable distribution for Requirement.parse(‘XXXX‘)”的问题
214 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
61 0
《How to Integrate Spark MLlib and Apache Solr to Build Real-Time Entity Type Recognition System for Better Query Understanding》电子版地址
|
云计算
Google Earth Engine(GEE)——Error: Exported bands must have compatible data types; found inconsistent
Google Earth Engine(GEE)——Error: Exported bands must have compatible data types; found inconsistent
444 0
Google Earth Engine(GEE)——Error: Exported bands must have compatible data types; found inconsistent
|
JavaScript
SAP PP使用ECR去修改Recipe主数据,报错:Generation not supported for change object
SAP PP使用ECR去修改Recipe主数据,报错:Generation not supported for change object
SAP PP使用ECR去修改Recipe主数据,报错:Generation not supported for change object
|
测试技术
Note tool
Sent: Monday, March 23, 2015 2:56 PM https://dewdfgwd:2030/sap/bc/ui5_ui5/sap/znotetool/index.html?sap-client=001&sap-ui-language=EN&sap-ui-appcache=false 把Opportunity,(或者lead,Appointment,task)ID输入,点submit,就能看到下面挂着的note全部的technical information了 后台只能连AG3哈,这个是拿来做单元测试的。 GM6/001 tcode SE80:
136 0
Note tool
|
人工智能 Java vr&ar
de.hybris.platform.impex.jalo.ImpExException: incompatible item reference values
de.hybris.platform.impex.jalo.ImpExException: incompatible item reference values
262 0
How to give query view parameter values in APF
How to give query view parameter values in APF
How to give query view parameter values in APF
How to put S4 extension field to CRM WebUI search view in the design time
How to put S4 extension field to CRM WebUI search view in the design time
How to put S4 extension field to CRM WebUI search view in the design time
Cannot find source code based button in SE24 - modification assistant
Cannot find source code based button in SE24 - modification assistant
129 0