Learn Django by Building a Collaborative Filtering

thepythontutorz

The Python Tutorial

Posted on May 30, 2023

Learn Django by Building a Collaborative Filtering

Learn Django with this one project! Build a Recommendation Engine in Django. Build a collaborative filtering with Python, Celery, Django, Worker Processes, Batch Predictions, SurpriseML, Keras, and more! Build a recommendation engine using Django & a Machine Learning technique called Collaborative Filtering.

Users will rate movies and the system will automatically recommend new ones. These recommendations will be done in batches (ie not in real time) to unlock a more scalable system for training and helping thousands and thousands of users.

For this course, we'll use a real dataset called MovieLens; this dataset is downloaded in CSV and is used on all kinds of machine learning tutorials. What's special about this course is you'll load this dataset into a SQL database through a Django model. This alone might be worth watching the course as SQL databases are far more powerful than CSV files.

To do the batch inference we implement the incredibly powerful background worker process called Celery. If you haven't used Celery before, this will be an eye opening experience and when you couple it with Django you have a truly powerful worker process that can run tasks in the background, run tasks on a schedule, or a combination of both. Tasks in Celery are simply Python functions with a special decorator.

For rating movies, we'll be using HTMX. HTMX is a way to dynamically update content without reloading the page at all. I am sure you know the experience whenever you click "like" or "subscribe" , that's what HTMX gives us without the overhead of using 1 line of JavaScript. This course shows us a practical implementation of using HTMX not just for rating movies, but also sorting them, loading them, and doing much more.

The recommendation engine in Django is really a collection of 3 parts:

Web Process: Setup up Django to collect user's interest and provide recommendations once available.
Machine Learning Pipeline: Extract data from Django, transform it, and train a Collaborative Filtering model.
Worker Process: This is the glue. We'll use Celery to schedule/run the trained model predictions and update data for Django-related user recommendations.

What you'll learn:

Learn

  • how to integrate Django & Celery
  • Learn how to use HTMX with Django for Dynamic Loading (no JavaScript Needed)
  • Training a Machine Learning Model with SurpriseML and an example in Keras
  • Build a rating system in Django with dynamic rating buttons. These ratings can be used on any Django Model
  • Learn how to run periodic background task and/or schedule functions to run exactly when needed
  • How to perform batch inference effectively using Django for any large workloads and/or ML packages
  • How to load large datasets into a SQL database through Django Models
  • Where to find great datasets online
  • How to implement an "infinite" review page that will always give a new item after rating.
  • So much more!

💖 💪 🙅 🚩
thepythontutorz
The Python Tutorial

Posted on May 30, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related