DEV Community

Cover image for Creating a Django Movie Recommendation App Using Jaccard Index
James Amattey
James Amattey

Posted on

Creating a Django Movie Recommendation App Using Jaccard Index

My goals for this project

  • Understand the key components of the django framework
  • Describe The Basic Principles of a recommendation system
  • Build a simple movie recommendation app, by applying Jaccard Algorithm based on content filtering mechanism

Github Repository https://github.com/jamattey/Django-Movie-Recommendation

Tech Stack

  • Django Backend
  • HTML Frontend
  • Bootstrap CSS
  • SQLite Database

About Django Framework

Django splits its application logic into the following three Model-View-Controller like components:

Django Model manages data modelling and database mapping as well as business logic to process data

Django View describes which data is presented, but not how it is presented. Typically, Django View delegates and renders an HTML page, which describes how the data is presented

Django Template generates dynamic HTML pages to present data

When a client sends a request, the Django server routes the request to the appropriate view based on the Django URL configuration and acts as a traditional Controller

Django Models
Django uses Django Models to represent database tables and map them to objects, such as process is called ORM. Django Models tries to make the developer’s life easier by abstracting databases and mapping objects and methods into tables and SQL queries automatically.

You just need to define classes as Django Models, and will be later mapped to database tables accordingly. Then you can simply use Django Models API to perform CRUD on the database tables without writing a single line of SQL

Django Views
In Django, a View is essentially a Python function. Such a function takes a Web request and applies the necessary logic to generate a Web response, such as the HTML contents of a Web page, a redirect, a 404 error, an XML document, an image, or any other Web response. Often, View interacts with Django Models to get required data in the form of QuerySet or objects to generate a Web response.

Django Application Development Process

image
First, I created a Django project which is a container for Django apps and settings. Here, I can decide to create and add one or more Django apps to the project.

In Core Development, I created Django models to model the data and created views to determine which data need to be presented to the UI. I also map the request URLs to our views so Django can forward requests to corresponding views via URLs. Then we can start designing and building the UI.

This movies are populated in a CSV. The site does not host actual movies but its is a recommendation engine using regular code and a database.

This recommendation engine does not use Machine Learning.......yet πŸ˜‚πŸ˜‚

To make the recommendation actually work, I needed to first mark the movies a user has watched using Django Admin site. Then I wrote a recommendation algorithm based on watched movies.

Marking Watched Movies In Django Admin

  • Run Django Server
  • visit admin url app_url/admin
  • image
  • Then you click into the movie entry and mark it as watched and press Save.

Run make_recommendations CMD to Generate Recommendations

For any recommendation systems, the key idea is always to come up with a good algorithm/model to predict if a specific user will like or dislike his/her unseen item, as shown in the following screenshot:

image

There are probably hundreds of good recommendation algorithms and can be roughly divided into two categories:

Content filtering based:

The content filtering based recommendation algorithms assume you may like a new movie if you have watched very similar movies before. Or based on your user profile (like age, gender, interests), it will try to find new movies matching your profile.

Collaborative filtering based:

The collaborative filtering algorithms assume you may like a new movie if other users similar to you (similar profile or watched similar movies) have watched this movie.

In this project, we will use content filtering based algorithm, and we will try to recommend unwatched/new movies to you if they are similar to your watched movies.

How do we calculate such movie similarity

Here we will use Jaccard similarity which is probably the simplest but very effective method to calculate similarity between two sets.

Jaccard Similarity is defined as the size of intersection of two sets divided by the size of union of that two sets.

Top comments (1)

Collapse
 
jamattey profile image
James Amattey

I am still working on this project. By the time I am done, I will document my entire thinking process. It helps to understand why i took certain decisions.