Adding custom rules to recommendations

It often happens that some business rules require us to boost the score of the selected items. In the book dataset, for example, if a book is recent, we want to give it a higher score. That's possible by using the IDRescorer interface, as follows:

  • rescore(long, double) takes the itemId and original score as an argument and returns a modified score
  • isFiltered(long) returns true to exclude a specific item from the recommendations, or false, otherwise

Our example can be implemented as follows:

class MyRescorer implements IDRescorer { 
 
  public double rescore(long itemId, double originalScore) { 
    double newScore = originalScore; 
    if(bookIsNew(itemId)){ 
      originalScore *= 1.3; 
    } 
    return newScore; 
  } 
 
  public boolean isFiltered(long arg0) { 
    return false; 
  } 
 
} 

An instance of IDRescorer is provided when invoking recommender.recommend:

IDRescorer rescorer = new MyRescorer(); 
List<RecommendedItem> recommendations =  
recommender.recommend(userID, noItems, rescorer); 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.77.208