0

I use RecommenderEvaluator to estimate Mahout's recommendation efficiency. Currently, I try to improve recommendation results with IDRescorer which will do some post-processing boost of the searched items.

RecommenderEvaluator evaluator = 
    new AverageAbsoluteDifferenceRecommenderEvaluator();
double evaluation = evaluator.evaluate(builder, myModel, 0.9, 0.9);

Is there any way in Mahout to tell RecommenderEvaluator to use my custom IDRescorer?

Dragan Milcevski
  • 776
  • 7
  • 17
kikulikov
  • 2,512
  • 4
  • 29
  • 45
  • @DraganMilcevski thank you very much for your answer. It is not exactly what I was looking for as my 'CustomRescorer' depends on the other parameters, like 'new CustomRescorer(requestParams: Seq[String])'. For all other cases your answer might be suitable. – kikulikov Jul 07 '14 at 21:09
  • There is a way to fix this as well. You will have the customRescorrer as variable in your Recommender class, and you can even refresh it with setting new values, and then when the recommendation process start it will use the new rescorer. Maybe if you send the whole class, I might be abel to help you. – Dragan Milcevski Aug 01 '14 at 10:52

1 Answers1

1

You can create your own implementation of the Recommender class

class CustomRecommender implements Recommender{
....
public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException {
 IDRescorer rescorer = new CustomResorer();
 return delegate.recommend(userID, howMany, rescorer);
 }
 public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
    return delegate.recommend(userID, howMany, rescorer);
 }
 public float estimatePreference(long userID, long itemID) throws TasteException {
   IDRescorer rescorer = new CustomResorer();
   return (float) rescorer.rescore( itemID, delegate.estimatePreference(userID, itemID));
 }
...
}

Here even if the recommendation is called without rescorer, you will incorporate it in the recommend and estimatePreference methods.

And then when you build the RecommenderBuilder you will create an instance of your recommender:

RecommenderBuilder recommenderBuilder = new RecommenderBuilder() {
   @Override
   public Recommender buildRecommender(DataModel model) throws TasteException {
    Similarity similarity = new ...             
    return new CustomRecommender(model, similarity);                    
   }

};
Dragan Milcevski
  • 776
  • 7
  • 17