0

I'm making a recommender in java using mahout. The recommendation is working fine but this line List<RecommendedItem> recommendations = recommender.recommend(id, 20); is taking me about 1,7 seconds. I have about 822 users and about 677.000 scores to various products. There's a way to acellerate this or store the data more eficienty?

public class App {
public static void main(String[] args) throws Exception {
    DataModel model = new FileDataModel(new File("data/data.csv"));
    UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
    UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
    UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);
    Mongo m = new Mongo();
    LongPrimitiveIterator ids = model.getUserIDs();
    while(ids.hasNext()) {

        Long id = ids.next();
        Document recs = new Document();
        long tempoInicio = System.currentTimeMillis();
        List<RecommendedItem> recommendations = recommender.recommend(id, 20);
        System.out.println("Time: "+(System.currentTimeMillis()-tempoInicio));
        for (RecommendedItem recommendation : recommendations) {
            Long item = recommendation.getItemID();
            Float value = recommendation.getValue();
            recs.append(item.toString(),new Document("result",value));
        }
        m.insere(new Document("uid",id.intValue()).append("recs",recs),id.intValue());
    }
}
}
Vinicius Morais
  • 565
  • 1
  • 5
  • 22
  • May I suggest you post the code of the method that's slow not the method calling it?! – dnickless Jan 16 '18 at 13:58
  • But the method is from Mahout `import org.apache.mahout.cf.taste.recommender.RecommendedItem;` – Vinicius Morais Jan 16 '18 at 14:25
  • Riiight. I'm sorry for my lack of knowledge. What I would suggest is that you turn query logging on and see what query/queries this call results in. https://stackoverflow.com/questions/15204341/mongodb-logging-all-queries – dnickless Jan 16 '18 at 18:47

0 Answers0