开发者

How to structure data in order to use item preference recommendation in mahout

开发者 https://www.devze.com 2023-04-06 04:50 出处:网络
first of all new to mahout, apache, maven etc - so apologies if some if this is obvious. I have a typical market basket data set ie

first of all new to mahout, apache, maven etc - so apologies if some if this is obvious.

I have a typical market basket data set ie

user1, item1

user1, item2

user2, item1

user2, item3

user3, item2

my query - what are recommendations for user3 ? (Yes I know the answer i开发者_如何学Pythons item1!).

How do I structure this for use in Mahout ? I have looked at the page - https://cwiki.apache.org/MAHOUT/recommender-documentation.html - which is very useful - but just when I want the interesting bit - ie how to build the correlation data - it says :

// Construct the list of pre-computed correlations
Collection<GenericItemSimilarity.ItemItemSimilarity> correlations =
          ...;
ItemSimilarity itemSimilarity =
          new GenericItemSimilarity(correlations);

and the bit I want to calculate is the missing ... !!!

Although this is completely the wrong way of doing it, I massaged my dataset to look identical to the movielens structure (giving a 5 as a rating, but really it should be a binary true), but all recommendations for all users are always the same list of products.

Any advice please ?


(This data is so sparse that I don't know that a recommender would actually recommend item 1, by the way.)

The code snippet you reference would be what you use if you already had precomputed item-item similarities. You don't have that here; you have user-item associations. Surely you mean to compute those similarities from this data, and use that for recommendations?

While you can do this programmatically, I suggest it's faster to craft a simple text file with your data...

1,1
1,2
2,1
2,3
3,2

Then to make your item-based recommender with a log-likelihood similarity:

DataModel model = new FileDataModel(new File("yourdata.txt"));
ItemSimilarity similarity = new LogLikelihoodSimilarity(model);
Recommender recommender = 
    new GenericBooleanPrefItemBasedRecommender(similarity, model);

and to recommend 1 item for user 3:

recommender.recommend(3, 1);

(This is covered in fair detail in Mahout in Action.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号