/* * Here is a user-based Mahout referral program * Take advantage of ready-made data here. * */package byuser;import java.io.file;import java.io.ioexception;import java.util.list;import Org.apache.mahout.cf.taste.common.tasteexception;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.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.UserSimilarity; public class Recommenderintro {public static void main (string[] args) {//TODO auto-generated method stub try {//To load the data datamodel model = new Filedatamodel ("E:\\mahout Project \\EXAMPLES\\INTRO.C SV ")); UsersimilariTy similarity = new org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity (model); Userneighborhood neighborhood = new Nearestnuserneighborhood (2, similarity, model); Generate recommendation engine Recommender recommender = new Genericuserbasedrecommender (model, neighborhood, similarity); For the user has recommended a product recommend (,); where the parameter means: the first few people, and then recommend a few goods list<recommendeditem> recommendations = R Ecommender.recommend (1, 1); for (Recommendeditem recommendation:recommendations) {System.out.println ("depending on your browsing, the product recommended for you is:" + Recommendati ON); }} catch (IOException e) {//TODO auto-generated catch block E.printstacktrace (); } catch (Tasteexception e) {//TODO auto-generated catch block E.printstacktrace (); } }}
Results:
Mahout implementing a user-based Mahout referral program