Vinicius Morais
Vinicius Morais

Reputation: 595

How get the data in Mahout faster?

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());
    }
}
}

Upvotes: 0

Views: 41

Answers (0)

Related Questions