WEB开发网
开发学院软件开发Java Apache Mahout 简介:通过可伸缩、商业友好的机器... 阅读

Apache Mahout 简介:通过可伸缩、商业友好的机器学习来构建智能应用程序

 2009-10-15 00:00:00 来源:WEB开发网   
核心提示: 为了完成此示例,我需要构建一个 UserNeighborhood 和一个 Recommender,Apache Mahout 简介:通过可伸缩、商业友好的机器学习来构建智能应用程序(8),UserNeighborhood 可以识别与相关用户类似的用户,并传递给 Recommender,方法是在包

为了完成此示例,我需要构建一个 UserNeighborhood 和一个 Recommender。UserNeighborhood 可以识别与相关用户类似的用户,并传递给 Recommender,后者将负责创建推荐项目排名表。清单 2 实现了以下想法:

清单 2. 生成推荐

//Get a neighborhood of users 
UserNeighborhood neighborhood = 
    new NearestNUserNeighborhood(neighborhoodSize, userSimilarity, dataModel); 
//Create the recommender 
Recommender recommender = 
    new GenericUserBasedRecommender(dataModel, neighborhood, userSimilarity); 
User user = dataModel.getUser(userId); 
System.out.println("-----"); 
System.out.println("User: " + user); 
//Print out the users own preferences first 
TasteUtils.printPreferences(user, handler.map); 
//Get the top 5 recommendations 
List<RecommendedItem> recommendations = 
    recommender.recommend(userId, 5); 
TasteUtils.printRecs(recommendations, handler.map); 

您可以在命令行中运行整个示例,方法是在包含示例的目录中执行 ant user-demo。运行此命令将打印输出虚构用户 995 的首选项和推荐,该用户只是 Lincoln 的爱好者之一。清单 3 显示了运行 ant user-demo 的输出:

清单 3. 用户推荐的输出

 [echo] Getting similar items for user: 995 with a neighborhood of 5 
   [java] 09/08/20 08:13:51 INFO file.FileDataModel: Creating FileDataModel 
      for file src/main/resources/recommendations.txt 
   [java] 09/08/20 08:13:51 INFO file.FileDataModel: Reading file info... 
   [java] 09/08/20 08:13:51 INFO file.FileDataModel: Processed 100000 lines 
   [java] 09/08/20 08:13:51 INFO file.FileDataModel: Read lines: 111901 
   [java] Data Model: Users: 1000 Items: 2284 
   [java] ----- 
   [java] User: 995 
   [java] Title: August 21 Rating: 3.930000066757202 
   [java] Title: April Rating: 2.203000068664551 
   [java] Title: April 11 Rating: 4.230000019073486 
   [java] Title: Battle of Gettysburg Rating: 5.0 
   [java] Title: Abraham Lincoln Rating: 4.739999771118164 
   [java] Title: History of The Church of Jesus Christ of Latter-day Saints 
       Rating: 3.430000066757202 
   [java] Title: Boston Corbett Rating: 2.009999990463257 
   [java] Title: Atlanta, Georgia Rating: 4.429999828338623 
   [java] Recommendations: 
   [java] Doc Id: 50575 Title: April 10 Score: 4.98 
   [java] Doc Id: 134101348 Title: April 26 Score: 4.860541 
   [java] Doc Id: 133445748 Title: Folklore of the United States Score: 4.4308662 
   [java] Doc Id: 1193764 Title: Brigham Young Score: 4.404066 
   [java] Doc Id: 2417937 Title: Andrew Johnson Score: 4.24178 

上一页  3 4 5 6 7 8 9 10  下一页

Tags:Apache Mahout 简介

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接