以下代码有什么问题?为什么它不会为匿名用户提供任何建议? 我无法弄清楚出了什么问题,但我无法通过PlusAnonymousUserDataModel获得匿名用户的建议。 这是示例代码,它没有显示匿名用户的建议,但为模型中的用户提供了具有完全相似偏好的建议:
public static void main(String[] args) throws Exception {
DataModel model = new GenericBooleanPrefDataModel(
GenericBooleanPrefDataModel.toDataMap(new FileDataModel(
new File(args[0]))));
PlusAnonymousUserDataModel plusAnonymousModel = new PlusAnonymousUserDataModel(model);
UserSimilarity similarity = new LogLikelihoodSimilarity(model);
UserNeighborhood neighborhood =
new NearestNUserNeighborhood(
Integer.parseInt(args[1]), similarity, model);
//new ThresholdUserNeighborhood(Float.parseFloat(args[1]), similarity, model);
System.out.println("Neighborhood=" + args[1]);
System.out.println("");
Recommender recommender = new GenericBooleanPrefUserBasedRecommender(model,
neighborhood, similarity);
PreferenceArray anonymousPrefs =
new BooleanUserPreferenceArray(12);
anonymousPrefs.setUserID(0,
PlusAnonymousUserDataModel.TEMP_USER_ID);
anonymousPrefs.setItemID(0, 1105L);
anonymousPrefs.setItemID(1, 1201L);
anonymousPrefs.setItemID(2, 1301L);
anonymousPrefs.setItemID(3, 1401L);
anonymousPrefs.setItemID(4, 1502L);
anonymousPrefs.setItemID(5, 1602L);
anonymousPrefs.setItemID(6, 1713L);
anonymousPrefs.setItemID(7, 1801L);
anonymousPrefs.setItemID(8, 1901L);
anonymousPrefs.setItemID(9, 2002L);
anonymousPrefs.setItemID(10, 9101L);
anonymousPrefs.setItemID(11, 9301L);
synchronized(anonymousPrefs){
plusAnonymousModel.setTempPrefs(anonymousPrefs);
List<RecommendedItem> recommendations1 = recommender.recommend(PlusAnonymousUserDataModel.TEMP_USER_ID, 20);
plusAnonymousModel.clearTempPrefs();
System.out.println("Recm for anonymous:");
for (RecommendedItem recommendation : recommendations1) {
System.out.println(recommendation);
}
System.out.println("");
}
List<RecommendedItem> recommendations = recommender.recommend(
Integer.parseInt(args[2]), 20);
System.out.println("Recomedation for user_id="
+ Integer.parseInt(args[2]) + ":");
for (RecommendedItem recommendation : recommendations) {
System.out.println(recommendation);
}
System.out.println("");
此代码生成的输出如下: 附近= 100
Recm for anonymous:
user_id = 1680604的Recomedation: RecommendedItem [item:1701,value:24.363672] ... 等等。所以没有匿名用户的建议! :(
事实证明,要获得建议,您必须使用非“真实”(在我的情况下基于文件),持久性DataModel模型,而是使用PlusAnonymousUserDataModel plusAnonymousModel来构建相似性,邻域和推荐者!
因此,关于Mahout(https://builds.apache.org/job/Mahout-Quality/javadoc/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.html)的基本文档是错误的陈述ItemSimilarity similarity = new LogLikelihoodSimilarity(realModel); // not plusModel
之前,SO上的其他人遇到了同样的问题,但没有得到任何答案:Model creation for User User collanborative filtering 所以我想我应该去那里回答他。 Sean Owen,谢谢你的兴趣,你能批准我找到的解决方案是正确的吗?