[mahout in action] 调通第一个例子
2014-09-25 19:49
375 查看
第一个例子是给出了5个用户对物品的评分,基于用户的协同过滤,采用Pearson相似度来找到最相近的用户,并提供推荐。
程序输出
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.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; public class RecommenderIntro { public static void main(String[] args) throws IOException, TasteException { 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<RecommendedItem> recommendations = recommender.recommend(1, 1); for (RecommendedItem recommendation : recommendations) { System.out.println(recommendation); } } }
程序输出
14/09/25 19:47:01 INFO file.FileDataModel: Creating FileDataModel for file .\data\intro.csv 14/09/25 19:47:01 INFO file.FileDataModel: Reading file info... 14/09/25 19:47:01 INFO file.FileDataModel: Read lines: 21 14/09/25 19:47:01 INFO model.GenericDataModel: Processed 5 users RecommendedItem[item:104, value:4.257081]
相关文章推荐
- 用Eclipse调通第一个Struts2例子
- Struts in action 的第一个例子调试心得
- ActiveMQ In Action 第一章 消息传递和ActiveMQ简介 1.4 运行你的第一个ActiveMQ例子
- hadoop in action第一个例子编译错误处理
- Mahout in action分析维基百科数据例子(二)
- Mahout in action分析维基百科数据例子(一)
- OGRE步步惊心 - 第002天:第一个小例子
- EXT JS认识EXTJS,第一个EXTJS例子
- Autofac 解释第一个例子 《第一篇》
- Three.JS 添加灯光、材质和阴影(第一个例子)
- Scala by Example: 第一个例子
- Mahout基于用户的协同过滤算法的例子
- Opencv4Android环境搭建及第一个例子
- OpenGL红宝书8th第一个例子triangles
- 第一个Lucene.Net 例子
- pdf转txt第一个小例子(PDFBOX)
- Netty In Action中文版 - 第二章:第一个Netty程序
- Solr入门之(2)快速启动:第一个例子
- Ruby on rails开发从头来(windows)(四)-第一个添删查改例子 (修正原版错误)
- 成功运行RMI的第一个例子