Simple implementation of MAHOUT recommendations

Source: Internet
Author: User

As course project requires, I recently looked at the recommended implementation of Mahout. This article was first seen . There is no problem with the code inside, but it is a mistake to lead the package. So re-write, hoping to help students with the same problem. nonsense not much to say, on the code:

public static void Main (string[] args) throws Exception {System.out.println ("1"); File F = new file ("C:/users/administrator/desktop/test.txt"); System.out.println ("2");//import data, calculate similarity Datamodel model = new Filedatamodel (f); Usersimilarity similarity = new pearsoncorrelationsimilarity (model);//based on data and similarity, then calculate K next to Userneighborhood neighborhood = New Nearestnuserneighborhood (2,similarity, model);//based on the above three data to establish a recommendation engine recommender recommender = new Genericuserbasedrecommender (Model,neighborhood, similarity);//Direct call engine, recommended two Itemid for user 1. List<recommendeditem> recommendations = Recommender.recommend (1, 2); for (Recommendeditem recommendation: Recommendations) {SYSTEM.OUT.PRINTLN (recommendation);}}


On the code point of view, as the student's exactly, I just paste it. The package and results introduced are as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/70/wKiom1X9v0yi8Xh5AACdpIO6Hoo423.jpg "style=" float: none; "title=" qq20150919155952.jpg "alt=" Wkiom1x9v0yi8xh5aacdpio6hoo423.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/6D/wKioL1X9wYmQ9DZkAACEc_cBy_k194.jpg "style=" float: none; "title=" qq20150919160018.jpg "alt=" Wkiol1x9wymq9dzkaacec_cby_k194.jpg "/>


Now that we know how to build the simplest Mahout recommendation model, let's take a look at mahout in a little more detail. Mahout belongs to the Hadoop family and gives me the understanding that the ability to use MapReduce is even a Hadoop family. Mahout can do three things: clustering, classification, and recommendations. The recommended features we use can be recommended in two different strategies. Let's say that we want to recommend some products to the users of Amazon, USERCF is to find people who are similar to Tom's tastes, to see what they like, and to recommend these things to Tom. ITEMCF is to see what Tom likes first and then see if there are any similar items for these things to recommend.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/6D/wKioL1X9xNewGf1rAAFNNndwH_U591.jpg "title=" Mahout-recommendation-process.png "alt=" Wkiol1x9xnewgf1raafnnndwh_u591.jpg "/>

This diagram is a good explanation of the dependencies between the steps in the code you just wrote. I found it from the Mahout learning route. The code for ITEMCF is as follows. The ID of an item is entered, and an ID similar to that of the product is obtained.

1. Import data Datamodel dm = new Filedatamodel (New File ("Data/user_preferences.csv"));//2. Calculate the similarity between items itemsimilarity sim = new Loglikelihoodsimilarity (DM);//3. Build ItemBase recommendation engine Genericitembasedrecommender recommender = new Genericitembasedrecommender (DM, SIM);//4. Get recommended list list<recommendeditem> recommendations = Recommender.mostsimilaritems (ItemID, size); for (Recommendeditem recommendation:recommendations) { SYSTEM.OUT.PRINTLN (recommendation);}
Datamodel dm = new Filedatamodel (f); itemsimilarity sim = new loglikelihoodsimilarity (DM); Recommender recommender = new Genericitembasedrecommender (DM, SIM); Recommender cachingrecommender=new Cachingrecommender (recommender); List<recommendeditem> recommendations = Cachingrecommender.recommend (1, 7); for (Recommendeditem recommendation : Recommendations) {SYSTEM.OUT.PRINTLN (recommendation);}

This code enters the ID of the user and the number of recommendations that are required, taking into account what the current user likes, and then giving a list of recommendations.























This article from "Fingertip Light Fly" blog, declined reprint!

Simple implementation of MAHOUT recommendations

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.