org.apache.mahout.cf.taste.impl.recommender
Class GenericUserBasedRecommender
java.lang.Object
org.apache.mahout.cf.taste.impl.recommender.AbstractRecommender
org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender
- All Implemented Interfaces:
- Refreshable, Recommender, UserBasedRecommender
- Direct Known Subclasses:
- GenericBooleanPrefUserBasedRecommender
public class GenericUserBasedRecommender
- extends AbstractRecommender
- implements UserBasedRecommender
A simple Recommender
which uses a given DataModel
and UserNeighborhood
to produce recommendations.
GenericUserBasedRecommender
public GenericUserBasedRecommender(DataModel dataModel,
UserNeighborhood neighborhood,
UserSimilarity similarity)
getSimilarity
public UserSimilarity getSimilarity()
recommend
public List<RecommendedItem> recommend(long userID,
int howMany,
IDRescorer rescorer)
throws TasteException
- Specified by:
recommend
in interface Recommender
- Parameters:
userID
- user for which recommendations are to be computedhowMany
- desired number of recommendationsrescorer
- rescoring function to apply before final list of recommendations is determined
- Returns:
List
of recommended RecommendedItem
s, ordered from most strongly recommend to
least
- Throws:
TasteException
- if an error occurs while accessing the DataModel
estimatePreference
public float estimatePreference(long userID,
long itemID)
throws TasteException
- Specified by:
estimatePreference
in interface Recommender
- Parameters:
userID
- user ID whose preference is to be estimateditemID
- item ID to estimate preference for
- Returns:
- an estimated preference if the user has not expressed a preference for the item, or else the
user's actual preference for the item. If a preference cannot be estimated, returns
Double.NaN
- Throws:
TasteException
- if an error occurs while accessing the DataModel
mostSimilarUserIDs
public long[] mostSimilarUserIDs(long userID,
int howMany)
throws TasteException
- Specified by:
mostSimilarUserIDs
in interface UserBasedRecommender
- Parameters:
userID
- ID of user for which to find most similar other usershowMany
- desired number of most similar users to find
- Returns:
- users most similar to the given user
- Throws:
TasteException
- if an error occurs while accessing the DataModel
mostSimilarUserIDs
public long[] mostSimilarUserIDs(long userID,
int howMany,
Rescorer<LongPair> rescorer)
throws TasteException
- Specified by:
mostSimilarUserIDs
in interface UserBasedRecommender
- Parameters:
userID
- ID of user for which to find most similar other usershowMany
- desired number of most similar users to findrescorer
- Rescorer
which can adjust user-user similarity estimates used to determine most similar
users
- Returns:
- IDs of users most similar to the given user
- Throws:
TasteException
- if an error occurs while accessing the DataModel
doEstimatePreference
protected float doEstimatePreference(long theUserID,
long[] theNeighborhood,
long itemID)
throws TasteException
- Throws:
TasteException
getAllOtherItems
protected FastIDSet getAllOtherItems(long[] theNeighborhood,
long theUserID)
throws TasteException
- Throws:
TasteException
refresh
public void refresh(Collection<Refreshable> alreadyRefreshed)
- Description copied from interface:
Refreshable
Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any
Refreshable
should always leave itself in a consistent, operational state, and that the refresh
atomically updates internal state from old to new.
- Specified by:
refresh
in interface Refreshable
- Parameters:
alreadyRefreshed
- Refreshable
s that are known to have already been
refreshed as a result of an initial call to a Refreshable.refresh(Collection)
method on some
object. This ensure that objects in a refresh dependency graph aren't refreshed twice
needlessly.
toString
public String toString()
- Overrides:
toString
in class Object
Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.