Presenting django-recommender

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 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.


  1. said:

    I think it’s a great project, really useful, but I’m not sure if it can do what I want.
    Can I get recommendations with get_best_items_for_user even if the users have no tags? The recommended objects have tags, and the users vote on the objects, but the users have no tags. When I use get_best_items_for_user I get an empty list.

    Thanks for writing the pluggable 🙂

    25 March, 2010
  2. Great app!
    Well done. Got interested in this as well. Just checked if someone already did something with Segaran’s book. And someone did. Awesome.

    Just some questions about it though. You state that caching is a must for this app (on the google-code residence it has now). What caching app or middleware would you suggest?
    And can you give any pointers as to how you would utilize such a caching?

    17 August, 2010

Leave a Reply

Your email address will not be published. Required fields are marked *