Reputation: 75
I'm using Play framework to create an e-commerce application.I have a table named Rating containing userId,ProductId,rating. Now i'am trying to implement the mahout recommendation system to my application i tried the demo here and it works perfectly.So i'm trying now to get it to work with my actual data which i exported in a csv file here Finally when i run the method i don't get any recommendation , an empty list..., here's my code :
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");
}
Upvotes: 0
Views: 80