推荐系统-03-简单基于用户的推荐
Posted 心飞翔<
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了推荐系统-03-简单基于用户的推荐相关的知识,希望对你有一定的参考价值。
下面是一个基本的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-简单基于用户的推荐的主要内容,如果未能解决你的问题,请参考以下文章