Mahout recommendation 13-item-based recommendation

Source: Internet
Author: User
Tags file info

Item-based recommendation is based on item similarity. In mahout, it means that itemsimilarity is used to implement similarity measurement, rather than usersimilarity. They use similar users and similar items.

Item-based: understanding users' preferences and searching for similar items

User-based: find similar users and learn what they like.

If the number of items is much smaller than the number of users, item-based recommendations will improve performance.

Code:

Package mahout; import Java. io. file; import Java. util. list; import Org. apache. mahout. cf. taste. impl. model. file. filedatamodel; import Org. apache. mahout. cf. taste. impl. neighborhood. nearestnuserneighborhood; import Org. apache. mahout. cf. taste. impl. recommender. genericitembasedrecommender; import Org. apache. mahout. cf. taste. impl. recommender. genericuserbasedrecommender; import Org. apache. mahout. cf. taste. model. datamodel; import Org. apache. mahout. cf. taste. neighborhood. userneighborhood; import Org. apache. mahout. cf. taste. recommender. recommendeditem; import Org. apache. mahout. cf. taste. recommender. recommender; import Org. apache. mahout. cf. taste. similarity. itemsimilarity; import Org. apache. mahout. cf. taste. similarity. usersimilarity; import Org. apache. mahout. cf. taste. impl. similarity. pearsoncorrelationsimilarity;/*** user-based recommendation Program * @ author administrator **/public class recommenderintro {public static void main (string [] ARGs) throws exception {// load data files for storage and provide all the preferences required for computing, user and item data datamodel model = new filedatamodel (new file ("Data/intro.csv"); // user similarity, which gives the similarity between two users and has multiple measurement methods, you can change itemsimilarity similarity = new pearsoncorrelationsimilarity (model) directly from a user to an item; // user neighbor, A group of users that are most similar to a given user // userneighborhood neighborhood = new nearestnuserneighborhood (2, // similarity, model); /// recommendation engine, merge these components, recommendation Implementation // recommender = new genericuserbasedrecommender (model, // neighborhood, similarity); // recommender recommender1 = new recommendation (model, similarity) based on items ); // recommended item 1, 1, list <recommendeditem> recommendeditems = recommender1.recommend (1, 1); // output for (recommendeditem item: recommendeditems) {system. out. println (item );}}}

1 item recommended for user 1:

Output result:

14/08/05 12:26:44 INFO file.FileDataModel: Creating FileDataModel for file data\intro.csv14/08/05 12:26:44 INFO file.FileDataModel: Reading file info...14/08/05 12:26:44 INFO file.FileDataModel: Read lines: 2114/08/05 12:26:44 INFO model.GenericDataModel: Processed 5 usersRecommendedItem[item:104, value:5.0]

Compared with user-based recommendations, 104 items are recommended.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.