django-recommender is my new pluggable for having recommendation functionality in any django project. The only requierement is to have also django-voting (and to use it…)
The philosophy behind is to be able to make recommendations based on the user’s experience compared with the other user’s one. So instead of getting only the most popular items on the system, the user can also discover the items that can interest him more. The algorithms are based on Toby Segaran’s book “Programming Collective Intelligence“.
It’s pretty easy to use, you just need to use django-voting for vote the model you want to recommend, and the call the available functions on the RecommenderManager class.
For this first release I have included the next functions:
- get_best_items_for_user: This function will return a sorted list of pairs (value, item) containing the recommended items for a given user, based on the votes of the users.
- get_similar_users: This function will tell us which are the most similar users, based on the historical votes for similar items.
- get_best_users_for_item: This function will return the best candidates that may like a given item, based on votes.
- get_similar_items: The closest items, based on the votes of the users.
With this first set of functions we can answer most of the questions for a typicall social net, Which one is the best item for me? Who other users may I be interested on? Which users may be the best potential consumers for a given item? Which other items are similar to this one?
A simple snippet to show a bit of code. For better information, have a look at tests.py file:
users = User.objects.all() movies = Movie.objects.all() user = User.objects.get(id=4) items = Recommender.objects.get_best_items_for_user(user, users, movies)
The items variable contains a list with the next signature:
[(0.5, <TestItem: Animal House>), (0.25, <TestItem: Casablanca>)]
That means you may like Animal House with a 0.5 value (1 is max), and Casablanca with 0.25.