[mahout in action] 调通第一个例子
来源:互联网 发布:淘宝差评怎么办 编辑:程序博客网 时间:2024/06/05 07:45
第一个例子是给出了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.csv14/09/25 19:47:01 INFO file.FileDataModel: Reading file info...14/09/25 19:47:01 INFO file.FileDataModel: Read lines: 2114/09/25 19:47:01 INFO model.GenericDataModel: Processed 5 usersRecommendedItem[item:104, value:4.257081]
0 0
- [mahout in action] 调通第一个例子
- Spring in Action 书的第一个例子GreetingService...疑问
- Struts in action 的第一个例子调试心得
- hadoop in action第一个例子编译错误处理
- mahout in action[中文] 第一部分 推荐
- 5、第一个例子
- opengl 第一个例子
- hibernate第一个例子
- ajax 第一个例子
- JavaBeans第一个例子
- SiteMesh第一个例子
- Mina第一个例子
- Hibernate---->第一个例子
- Servlet第一个例子
- struts2第一个例子
- struts2第一个例子
- zTree第一个例子
- AJAX 第一个例子
- Android开发入门:样式和主题(Styles and Themes)
- 8086汇编语言入门之数据和前奏
- 使用Golang实现的快速排序
- 图片转base64字符串
- How to tune a new closeloop vcm, for instance, LC898214?
- [mahout in action] 调通第一个例子
- OCaml安装
- 科研之路2
- 详细的推送(APNS)文档与本地推送
- LINUX下的LIB
- svm学习
- Java正则表达式匹配多行
- hadoop一代集群运行代码案例
- volatile用法