码迷,mamicode.com
首页 > 其他好文 > 详细

推荐系统-03-简单基于用户的推荐

时间:2018-05-16 19:41:59      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:ack   cat   int   catch   AC   list   lis   print   pack   

下面是一个基本的JVAVA程序, RecommenderIntro.java

package xyz.pl8.recommenderintro;

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.impl.similarity.PearsonCorrelationSimilarity;
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;
import java.io.File;
import java.util.List;

public class RecommenderIntro {
    public static void main(String[] args){
        try{
            // intro.csv格式 userId,itemId,rating
            DataModel model = new FileDataModel(new File("/home/hadoop/intro.csv"));
            System.out.println(model);
            // 用户相似度
            UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
            // K近邻用户
            UserNeighborhood neighborhood = new NearestNUserNeighborhood(3,  similarity, model );
            // 基于用户的推荐器
            Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);
            //  推荐物品
            List<RecommendedItem> recommendedItems = recommender.recommend(2, 2);
            for (RecommendedItem item : recommendedItems){
                System.out.println(item);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

推荐系统-03-简单基于用户的推荐

标签:ack   cat   int   catch   AC   list   lis   print   pack   

原文地址:https://www.cnblogs.com/freebird92/p/9047488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!