问题
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