1

我正在使用 mahout 为可能的应用程序创建一个基本推荐器。我的数据集没有任何偏好。这是我的桌子的样子在此处输入图像描述

这是设置 mahout 的方法

  MySQLJDBCDataModel jdbcModel2 = new MySQLJDBCDataModel(dataSource,"user_viewed_song_statistics",
                "AUDIO_FK","USER_PROFILE_FK","AUDIO_FK","UVSS_DATE_CREATED");


        ItemSimilarity similarity = new LogLikelihoodSimilarity(jdbcModel2);
        Recommender recommender = 
            new GenericBooleanPrefItemBasedRecommender(jdbcModel2, similarity);

       for(RecommendedItem item: recommender.recommend(1, 1))
           System.out.println(item);

然而,在运行这个之后。它返回了这个错误

Exception in thread "main" java.lang.IllegalArgumentException
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:72)
    at org.apache.mahout.math.stats.LogLikelihood.logLikelihoodRatio(LogLikelihood.java:101)
    at org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity.doItemSimilarity(LogLikelihoodSimilarity.java:102)
    at org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity.itemSimilarities(LogLikelihoodSimilarity.java:90)
    at org.apache.mahout.cf.taste.impl.recommender.GenericBooleanPrefItemBasedRecommender.doEstimatePreference(GenericBooleanPrefItemBasedRecommender.java:54)
    at org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender$Estimator.estimate(GenericItemBasedRecommender.java:312)
    at org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender$Estimator.estimate(GenericItemBasedRecommender.java:300)
    at org.apache.mahout.cf.taste.impl.recommender.TopItems.getTopItems(TopItems.java:65)
    at org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender.recommend(GenericItemBasedRecommender.java:131)
    at org.apache.mahout.cf.taste.impl.recommender.AbstractRecommender.recommend(AbstractRecommender.java:63)
    at Starter.main(Starter.java:53)
4

1 回答 1

1

您正在使用非偏好项目推荐。类似于这个问题

我确实觉得它返回那种类型的异常很奇怪。我所做的是这样的。

MySQLBooleanPrefJDBCDataModel jdbc = new MySQLBooleanPrefJDBCDataModel(dataSource, TABLE_NAME, USER_ID, ITEM_ID);
CachingRecommender cachingRecommender = new CachingRecommender( new SlopeOneRecommender(jdbc));

// Get 5 recommendations for user 3
 List<RecommendedItem> items = cachingRecommender.recommend(3, 5);
  for (RecommendedItem item : items) {
        System.out.println(item);
  }

希望这可以帮助。

于 2013-08-29T00:45:26.503 回答