recommender
recommender copied to clipboard
Build a recommendation engine using Django & a Machine Learning technique called Collaborative Filtering.
Recommender
Build a recommendation engine using Django & a Machine Learning technique called Collaborative Filtering.
Live demo with limited features
Getting Started
- 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"
- Create virtual environment and activate it.
python3.8 -m venv venv
source venv/bin/activate
Use .\venv\Scripts\activate
if on windows
- Install requirements
(venv) python -m pip install pip --upgrade
(venv) python -m pip install -r requirements.txt
- Open VSCode
code .
- 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())'
- 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.
- 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
- Download the Movies Dataset
- Go to this kaggle project
- Login or sign up
- Download The Movies Dataset
- Expand archive.zip (the downloaded file)
- Copy contents into
recommender/src/data
so that you have:
# 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.
- Load in Movie Data Run migrations if needed:
python manage.py makemigrations
python manage.py migrate
Then:
python manage.py loader 200_000 --movies
- Load in Rating Data
python manage.py dataset_ratings
- 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
- Run the Worker
celery -A cfehome worker -l info --beat
-
Rate some movies With the server running (
python manage.py runserver
) open up http://localhost:8000/accounts/login and rate some movies. -
Create recommendation predictions
python manage.py recommend
This can also be done as a periodic task
-
Review Predictions on Dashboard
-
Celebrate!