Item-based collaborative filtering

User-based collaborative filtering finds the similarities between users, and then using these similarities between users, a recommendation is made.

Item-based collaborative filtering finds the similarities between items. This is then used to find new recommendations for a user.

To begin with item-based collaborative filtering, we'll first have to invert our dataset by putting the movies in the first layer, followed by the users in the second layer:

>>> def transform_prefs(prefs):
       for person in prefs:
           for item in prefs[person]:
               # Flip item and person
       return result

{'Avenger: Age of Ultron': {'Jill': 7.0,'Julia': 10.0,
 'Max': ...

Get Mastering Python for Data Science now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.