Mahout推荐返回一个空列表

时间:2017-10-08 14:40:41

标签: java recommendation-engine mahout-recommender

我使用Play框架创建电子商务应用程序。我有一个名为Rating的表,其中包含userId,ProductId,rating。 现在我正在尝试将mahout推荐系统应用到我的应用程序中我尝试了演示here并且它运行良好。所以我现在尝试使用我导出的实际数据在csv文件中here 最后,当我运行该方法时,我没有得到任何推荐,一个空列表......,这是我的代码:

public Result MahoutRecCSV(){
    List<Rating> ratings = Rating.find.all();
    /** From rating datatable to CVS file **/
   try {
       List<String> lines = new ArrayList<>();//Arrays.asList("The first line", "The second line");
       for (Rating r : ratings){
           lines.add(r.user.id+","+r.produit.id+","+r.note);
       }
       Path file = Paths.get("dataToRecommendation.csv");
       Files.write(file, lines, Charset.forName("UTF-8"));

   }catch (IOException e){
       e.printStackTrace();
   }

    /**Get REcommandation From the file created*/
    try {
        DataModel model = new FileDataModel(new File("dataToRecommendation.csv"));
        UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
        UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
        UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);

        List<RecommendedItem> recommendations = recommender.recommend(3, 3);
        for (RecommendedItem recommendation : recommendations) {
            System.out.println(recommendation);
        }
        return ok(Json.toJson(recommendations));
    } catch (IOException e) {
        e.printStackTrace();
    } catch (TasteException e) {
        e.printStackTrace();
    }

    return ok("Erreur");
}

0 个答案:

没有答案