Apache Mahout。推荐的限制或抵消

时间:2013-05-16 05:13:31

标签: java apache pagination mahout recommendation-engine

我想用mahout(specfying,offset和max results)实现分页,我如何使用Mahout实现这一目标?所以,假设我有这个代码可以生成建议

 File ratingsFile = new File("audio-dummy-bool.csv");                        
 DataModel model = new FileDataModel(ratingsFile);

    CachingRecommender cachingRecommender2 = new CachingRecommender(new SlopeOneRecommender(model));





// for all users
for (LongPrimitiveIterator it = model.getUserIDs(); it.hasNext();){
    long userId = it.nextLong();

    // get the recommendations for the user
    List<RecommendedItem> recommendations = cachingRecommender.recommend(userId, 10);

    // if empty write something
    if (recommendations.size() == 0){
        System.out.print("User ");
        System.out.print(userId);
        System.out.println(": no recommendations");
    }

    // print the list of recommendations for each 
    for (RecommendedItem recommendedItem : recommendations) {
        System.out.print("User ");
        System.out.print(userId);
        System.out.print(": ");
        System.out.println(recommendedItem);
    }
}

我想为此实现分页,因为该建议可能会为用户生成一千个结果,这会在内存中花费很多。无论如何,我可以指定mahout中生成建议的最大结果和偏移量吗?

1 个答案:

答案 0 :(得分:2)

您想通过结果“翻页”吗?没有办法做到这一点。您可以请求N,存储并提供这些结果,然后返回并在需要时请求2N等。但是,这不是'抵消'。