Skip to content

codingforentrepreneurs/recommender

Repository files navigation

Recommender Course Image

Recommender

Build a recommendation engine using Django & a Machine Learning technique called Collaborative Filtering.

Live demo with limited features

Getting Started

  1. Clone the project and make it your own. Use branch start initially so we can all start in the same place.
git clone https://github.com/codingforentrepreneurs/recommender
cd recommender

If you're starting in the course, use the following:

git checkout start
rm -rf .git
git init .
git add --all
git commit -m "My recommender project"
  1. Create virtual environment and activate it.
python3.8 -m venv venv
source venv/bin/activate

Use .\venv\Scripts\activate if on windows

  1. Install requirements
(venv) python -m pip install pip --upgrade
(venv) python -m pip install -r requirements.txt
  1. Open VSCode
code .
  1. Create .env file:

In src/.env add:

CELERY_BROKER_REDIS_URL='redis://localhost:6380'
DJANGO_DEBUG='1'
SECRET_KEY='o43ig(nx@1)ae$y6_@lbh95fp@3#lda3!y6agi&r3e+m-z$cu_'

Replace your SECRET_KEY with a new one using this guide or simply:

python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
  1. Start Docker Compose for a Redis Instance

Below will start a docker-based Redis instance that will run at port 6380 on your local machine to match the .env from the previous step.

docker compose up -d

Consider watching my Docker & Docker Compose course if you're new to docker.

  1. Run Django Commands
cd path/to/recommender
source venv/bin/activate
$(venv) cd src

Migrations and Create Superuser

$(venv) python manage.py makemigrations
$(venv) python manage.py migrate
$(venv) python manage.py createsuperuser

Run the server:

$(venv) python manage.py runserver
  1. Download the Movies Dataset
# in recommender projectdir
$(venv) ls src/data
credits.csv             links.csv               movies_metadata.csv     ratings_small.csv
keywords.csv            links_small.csv         ratings.csv

We only need links_small.csv, ratings_small.csv, and movies_metadata.csv at this time.

The entire src/data folder is in .gitignore so you do not accidently commit this data to your git repo.

  1. Load in Movie Data Run migrations if needed:
python manage.py makemigrations
python manage.py migrate

Then:

python manage.py loader 200_000 --movies
  1. Load in Rating Data
python manage.py dataset_ratings
  1. Train your ML Model
python manage.py train --epochs 20

When your worker is running, you can also do python manage.py train --async --epochs 20

  1. Run the Worker
celery -A cfehome worker -l info --beat
  1. Rate some movies With the server running (python manage.py runserver) open up http://localhost:8000/accounts/login and rate some movies.

  2. Create recommendation predictions

python manage.py recommend

This can also be done as a periodic task

  1. Review Predictions on Dashboard

  2. Celebrate!

Helpful Guides