一般而言再使用mahout recommender來說,都有幾個步驟。
- 建立模型
- 計算相似度
- 找k-nearest neighbor
- build recommender engine
public static void main (String args[])throws Exception{
DataModel model =new FileDataModel(new File("data/intro.csv"));
UserSimilarity similarity =new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood =new NearestNUserNeighborhood(2,similarity,model);
Recommender recommender= new GenericUserBasedRecommender(model,neighborhood,similarity);
List recommendations =recommender.recommend(1, 2);
for(RecommendedItem recommendation :recommendations){
System.out.println(recommendation);
}
}
沒有留言:
張貼留言