org.apache.mahout.cf.taste.impl.recommender.slopeone
Class SlopeOneRecommender

java.lang.Object
  extended by org.apache.mahout.cf.taste.impl.recommender.AbstractRecommender
      extended by org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender
All Implemented Interfaces:
Refreshable, Recommender

public final class SlopeOneRecommender
extends AbstractRecommender

A basic "slope one" recommender. (See an excellent summary here for example.) This Recommender is especially suitable when user preferences are updating frequently as it can incorporate this information without expensive recomputation.

This implementation can also be used as a "weighted slope one" recommender.


Constructor Summary
SlopeOneRecommender(DataModel dataModel)
           Creates a default (weighted) based on the given DataModel.
SlopeOneRecommender(DataModel dataModel, Weighting weighting, Weighting stdDevWeighting, DiffStorage diffStorage)
           Creates a based on the given DataModel.
 
Method Summary
 float estimatePreference(long userID, long itemID)
           
 List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer)
           
 void refresh(Collection<Refreshable> alreadyRefreshed)
           Triggers "refresh" -- whatever that means -- of the implementation.
 void removePreference(long userID, long itemID)
           Default implementation which just calls DataModel.removePreference(long, long) (Object, Object)}.
 void setPreference(long userID, long itemID, float value)
           Default implementation which just calls DataModel.setPreference(long, long, float).
 String toString()
           
 
Methods inherited from class org.apache.mahout.cf.taste.impl.recommender.AbstractRecommender
getAllOtherItems, getDataModel, getDefaultCandidateItemsStrategy, recommend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SlopeOneRecommender

public SlopeOneRecommender(DataModel dataModel)
                    throws TasteException

Creates a default (weighted) based on the given DataModel.

Throws:
TasteException

SlopeOneRecommender

public SlopeOneRecommender(DataModel dataModel,
                           Weighting weighting,
                           Weighting stdDevWeighting,
                           DiffStorage diffStorage)

Creates a based on the given DataModel.

If weighted is set, acts as a weighted slope one recommender. This implementation also includes an experimental "standard deviation" weighting which weights item-item ratings diffs with lower standard deviation more highly, on the theory that they are more reliable.

Parameters:
weighting - if Weighting.WEIGHTED, acts as a weighted slope one recommender
stdDevWeighting - use optional standard deviation weighting of diffs
Throws:
IllegalArgumentException - if diffStorage is null, or stdDevWeighted is set when weighted is not set
Method Detail

recommend

public List<RecommendedItem> recommend(long userID,
                                       int howMany,
                                       IDRescorer rescorer)
                                throws TasteException
Parameters:
userID - user for which recommendations are to be computed
howMany - desired number of recommendations
rescorer - rescoring function to apply before final list of recommendations is determined
Returns:
List of recommended RecommendedItems, 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
Parameters:
userID - user ID whose preference is to be estimated
itemID - 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

setPreference

public void setPreference(long userID,
                          long itemID,
                          float value)
                   throws TasteException
Description copied from class: AbstractRecommender

Default implementation which just calls DataModel.setPreference(long, long, float).

Specified by:
setPreference in interface Recommender
Overrides:
setPreference in class AbstractRecommender
Parameters:
userID - user to set preference for
itemID - item to set preference for
value - preference value
Throws:
TasteException - if an error occurs while accessing the DataModel

removePreference

public void removePreference(long userID,
                             long itemID)
                      throws TasteException
Description copied from class: AbstractRecommender

Default implementation which just calls DataModel.removePreference(long, long) (Object, Object)}.

Specified by:
removePreference in interface Recommender
Overrides:
removePreference in class AbstractRecommender
Parameters:
userID - user from which to remove preference
itemID - item for which to remove preference
Throws:
TasteException - if an error occurs while accessing the DataModel

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 should always leave itself in a consistent, operational state, and that the refresh atomically updates internal state from old to new.

Parameters:
alreadyRefreshed - s that are known to have already been refreshed as a result of an initial call to a 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-2012 The Apache Software Foundation. All Rights Reserved.