The Movie Recommendation System is a Flask-based web application that suggests movies based on user preferences, including genres, actors, and directors. It fetches movie data from The Movie Database (TMDb) API and stores it in MongoDB. The recommendation engine uses TF-IDF vectorization and cosine similarity for movie matching.
- Movie Recommendations based on genres, actors, and directors.
- User Authentication using JWT for secure access.
- MongoDB Integration for storing movie and user data.
- API Endpoints for fetching movies, recommendations, and tracking history.
- Machine Learning Model trained on fetched movie data.
- Backend: Flask (Python)
- Database: MongoDB (via PyMongo)
- Machine Learning: Scikit-learn (TF-IDF, Cosine Similarity)
- API Integration: TMDb API
- Authentication: JWT-based authentication
- Containerization: Docker (optional)
TF-IDF (Term Frequency-Inverse Document Frequency) is a statistical measure used to evaluate how important a word is to a document relative to a collection of documents. It helps in understanding the significance of words when analyzing text data.
- Term Frequency (TF): Measures how frequently a word appears in a document.
- Inverse Document Frequency (IDF): Weighs words based on their rarity across all documents.
- In this system, TF-IDF is applied to movie metadata (title, overview, genres, actors, director) to convert text into numerical representations.
Cosine similarity measures the similarity between two vectors based on the cosine of the angle between them.
- If two vectors are perfectly aligned, their cosine similarity is 1 (i.e., they are identical).
- If two vectors are completely different, their cosine similarity is 0.
- In this project, cosine similarity is used to find movies with the most similar metadata representations.
- Convert movie metadata (title, genres, actors, director, and overview) into a numerical format using TF-IDF Vectorization.
- Compute the cosine similarity between the input query and all available movies.
- Retrieve the top Nmovies with the highest similarity scores as recommendations.
 git clone https://github.com/your-username/movie-recommendation-system.git
 cd movie-recommendation-system python -m venv venv
 source venv/bin/activate  # Mac/Linux
 venv\Scripts\activate     # Windows pip install -r requirements.txt- Install MongoDB from MongoDB Official Website.
- Start MongoDB Server:
mongod --dbpath /path/to/data/db 
- Create a database named movie_dband collections:mongo use movie_db db.createCollection("movies") db.createCollection("users") db.createCollection("recommendation_history") 
- Create an account on MongoDB Atlas.
- Create a new cluster and get the connection string.
- Replace MONGO_URIin.envwith:MONGO_URI=mongodb+srv://your_username:[email protected]/movie_db 
Create a .env file in the root directory and add:
MONGO_URI=mongodb://localhost:27017/movie_db  # or MongoDB Atlas URI
TMDB_API_KEY=your_tmdb_api_key
SECRET_KEY=your_secret_key
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin_password python run.pyThe API will start at http://127.0.0.1:5000/.
- 
Register: POST /register- Request Body: { "username": "user", "password": "pass", "email": "[email protected]" }
- Response: { "message": "User registered successfully!" }
 
- Request Body: 
- 
Login: POST /login- Request Body: { "username": "user", "password": "pass" }
- Response: { "message": "Login successful", "token": "jwt_token" }
 
- Request Body: 
- 
Recommend Movies: POST /recommend- Request Body: { "genres": ["Action", "Sci-Fi"], "actor": "Leonardo DiCaprio", "director": "Christopher Nolan" }
- Response: { "recommendations": [{ "title": "Movie Name", "genres": ["Action"] }] }
 
- Request Body: 
- 
Fetch Movies by Actor: POST /fetch_movies- Request Body: { "actor": "Tom Hanks" }
- Response: { "message": "Movies for Tom Hanks fetched successfully!" }
 
- Request Body: 
- View Recommendation History: GET /history- Response: { "history": [{ "query": {"genres": ["Drama"]}, "movies": [...] }] }
 
- Response: 
📂 movie-recommendation-system
│── app.py            # Main Flask app
│── run.py            # Starts the application
│── routes.py         # API routes
│── auth.py           # User authentication
│── db_handler.py     # Database connection
│── fetch_movies.py   # Fetches movies from TMDb API
│── movie_recommender.py  # Recommendation engine
│── .env              # Environment variables
│── requirements.txt  # Dependencies
This project is licensed under the MIT License.
Sayak Mitra Majumder