consensus

consensus

Models for prediction of user ratings of items using collaborative filtering.

The classes DistanceModel , SimpleSimilarityModel , and SMSimilarityModel use different methods for judging the similarity of two users given their rating histories.

The getRecommendations method for the above classes returns a list of items and their scores (how relevant they are to the given user), sorted from most recommended to least recommended. It does this by weighting other users' preferences by their similarity to the user for whom recommendations are being requested.

The example below uses the AudioScrobbler service to obtain preference data, then uses getRecommendations to suggest artists for a given user.

Usage

>>> from consensus import DistanceModel, SimpleSimilarityModel, SMSimilarityModel
>>> def loadPreferences():
...    d = shelve.open("scrobbler.pickle")
...    judgeRatings = {}
...    for user, artistsInfo in d.iteritems():
...        judgeRatings[user] = {}
...        for artistName, playCount in artistsInfo:
...            judgeRatings[user][artistName] = playCount
...    return judgeRatings
>>> judgeRatings = loadPreferences()
>>> distance = DistanceModel(judgeRatings)
>>> similarity = SimpleSimilarityModel(judgeRatings)
>>> sm_similarity = SMSimilarityModel(judgeRatings)
>>> [artist for artist, score in distance.getRecommendations('eggs_again', limit=10)]
[u'Sufjan Stevens', u'Elliott Smith', u'Broken Social Scene', u'Belle and Sebastian',
 u'The Beatles', u'Wilco', u'The Decemberists', u'Interpol', u'Bright Eyes', u'Beck']
>>> [artist for artist, score in similarity.getRecommendations('eggs_again', limit=10)]
[u'Sufjan Stevens', u'Elliott Smith', u'Broken Social Scene', u'The Beatles',
 u'Belle and Sebastian', u'Wilco', u'Interpol', u'The Decemberists', u'Beck',
 u'Bright Eyes']
>>> [artist for artist, score in sm_similarity.getRecommendations('eggs_again', limit=10)]
[u'Sufjan Stevens', u'Elliott Smith', u'Broken Social Scene', u'Belle and Sebastian',
 u'The Beatles', u'Interpol', u'Wilco', u'The Decemberists', u'Bright Eyes',
 u'Death Cab for Cutie']

Classes

C Model(...) ...

The base class for all collaborative filtering models. Not usable unles subclassed.

This class contains 4 members.

C DistanceModel(...) ...

Uses the vector distance in n-dimensional space defined by the users' ratings for n items

This class contains 4 members.

C SimpleSimilarityModel(...) ...

Uses a simple function where a larger intersection of preferred items results in greater similarity

This class contains 4 members.

C SMSimilarityModel(...) ...

Uses the constrained Pearson correlation function (Shardanand & Maes 1995)

This class contains 4 members.

See the source for more information.