Google preconditions illegal Argument exception

本小妞迷上赌 提交于 2019-12-11 11:12:16

问题


I am using mahout to create a basic recommender for may application. my data set does not have any preferences. here's how my table looks like

Here's how set up 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);

However after running this. it returned this error

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)

回答1:


You are using a Non-preference Item recommendation. Similar to this question

and I do find it weird that it is returning that type of an exception. what I've done is something like this.

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);
  }

Hope this helps.



来源:https://stackoverflow.com/questions/18448189/google-preconditions-illegal-argument-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!