Building recommendation systems through Mahout: Extended scoring rules through idrescorer

Source: Internet
Author: User
Tags filter

If we need to add some filtering rules (such as item creation time within one year) when building a recommendation system through mahout, we need to use the Idrescorer interface, which is the source code as follows:

Package org.apache.mahout.cf.taste.recommender; /** * <p> * A {@link Rescorer} which operates on {@code long} primitive IDs, rather than {@link arbitrary  
 Ct}s. * This is provided since most uses the ' this interface ' framework take IDs (as {@code long}) as an * argument, and  
 So this can is used to avoid unnecessary boxing/unboxing. * </p>/public interface Idrescorer {/** * @param ID * ID of thing (user, item , etc.)  To Rescore * @param originalscore * Original Score * @return modified score, or {@link Double#nan}  
        
  To indicate the This should is excluded entirely/double rescore (long ID, double originalscore);  
   /** * Returns {@code true} to exclude the given thing. * @param ID * ID of thing (user, item, etc.) to Rescore * @return {@code true} to exclude, {@cod  
        
E false} otherwise */Boolean isfiltered (long ID); }

The interface sets out two methods that must be implemented:

1.rescore method

Function: Defines the logic for a new score. According to the new rule, the item for the specified ID is graded again.

Return: The score after the revaluation

Input parameter: ID of item, original rating of item

The methods that are invoked include the following:

2.isFiltered

Function: Define filter rules. Determines whether the item of the specified ID, according to the new rule, is excluded, and returns true that the item should be excluded from the result.

Return: TRUE or False

Input parameter: The specified ID

The methods that are invoked include the following:

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/tools/

Whether or not you need to filter the recommended results according to specific rules, You must first create an object R for the Org.apache.mahout.cf.taste.recommender.Recommender class, and then use the object R to perform the recommended method of obtaining the recommended results list for a specific ID user.

When you do not need to use specific rules to filter recommended results, you only need to use the following methods of the Recommender object to obtain the recommended results:

/**  
 * @param userID  
 *          user for which recommendations are * computed  
 * @param howmany          * Desire  D Number of recommendations  
 * @return {@link List} of recommended {@link Recommendeditem}s, ordered from most strongly Recommend to  
 *         least  
 * @throws tasteexception  
 *           If a error occurs while accessing the {@link Data Model}  
 *
/list<recommendeditem> recommend (long UserID, int howmany) throws tasteexception;

When you need to filter recommendation results based on specific rules, use the following methods of the Recommender object to obtain the recommended results:

/**  
 * @param userID  
 *          user for which recommendations are * computed  
 * @param howmany          * Desire D Number of recommendations  
 * @param rescorer  
 *          rescoring function to apply before final list of Recommendatio  NS is determined  
 * @return {@link List} of recommended {@link Recommendeditem}s, ordered from most strongly To  
 *         least  
 * @throws tasteexception  
 *           If a error occurs while accessing the {@link datamodel}< c16/>*/
list<recommendeditem> recommend (long UserID, int howmany, Idrescorer rescorer) throws Tasteexception;

One of the last parameters is the idrescorer mentioned in this article.

Therefore, when you need to filter the recommended results through specific rules, you need to implement the Idrescorer interface, define the scoring logic and exclusion rules.

CSDN Blog Gandalf_lee

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.