Search code examples
javaalgorithmscalahadoopmahout

Mahout - run als-wr recommender evaluator


I'm trying to get the precision and recall of the als-wr algorithm on my input using mahout.

The problem is the only way I've found to use als-wr algorithm is from mahout command line - https://mahout.apache.org/users/recommender/intro-als-hadoop.html

I don't see any example in web for using this algorithm in code.

Any example or help for running it in scala/java with an evaluator will be strongly appreciated.


Solution

  •     RecommenderIRStatsEvaluator user_eval = new GenericRecommenderIRStatsEvaluator();
        RecommenderBuilder user_rb = new RecommenderBuilder() 
        {
        @Override
            public Recommender buildRecommender(DataModel model) throws TasteException 
            {
                UserSimilarity user_ll_sim = new LogLikelihoodSimilarity(model);
                UserNeighborhood user_ll_nbhd = new NearestNUserNeighborhood(5, user_ll_sim, model);
                return new GenericUserBasedRecommender(model, user_ll_nbhd, user_ll_sim);
            }
        };
    
        IRStatistics user_ll_stats = user_eval.evaluate(user_ll_rb, null, model, null, 2, GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 0.8);
        System.out.println(user_ll_stats.getPrecision()+" "+user_ll_stats.getRecall());
    

    Replace the User Based LogLikelihood model with the SVD one.