Skip to content

Movie Recommendation System (Basic)

Abstract

An intelligent movie recommendation system that provides personalized movie suggestions using multiple recommendation algorithms including collaborative filtering, content-based filtering, and hybrid approaches. This project demonstrates machine learning concepts, data analysis, and recommendation algorithms.

๐ŸŽฏ Project Overview

This project implements a comprehensive movie recommendation system featuring:

  • User registration and rating system
  • Multiple recommendation algorithms
  • Movie database with genres and ratings
  • Statistical analysis and insights
  • Search and filtering capabilities
  • Data persistence using JSON storage

โœจ Features

Recommendation Algorithms

  • Collaborative Filtering: Recommendations based on similar usersโ€™ preferences
  • Content-Based Filtering: Suggestions based on movie genres and user preferences
  • Hybrid Approach: Combines both methods for better accuracy
  • Pearson Correlation: Measures user similarity for collaborative filtering

User Management

  • User Registration: Create and manage user profiles
  • Rating System: Rate movies on a 1-5 scale
  • Preference Learning: Automatically discover favorite genres
  • Rating History: Track all user ratings and preferences

Movie Database

  • Comprehensive Catalog: Pre-loaded with popular movies
  • Genre Classification: Multi-genre support for accurate categorization
  • Rating Analytics: Average ratings and rating counts
  • Search Functionality: Find movies by title or genre

Analytics & Insights

  • Top Rated Movies: Discover highest-rated films
  • Statistical Dashboard: Database statistics and trends
  • Genre Analysis: Most popular genres and distributions
  • User Profiles: Personal rating history and preferences

๐Ÿ› ๏ธ Technical Implementation

Class Structure

movierecommendationsystem.py
class Movie:
    def __init__(self, movie_id, title, genres, year=None):
        # Movie metadata and rating management
        # Automatic rating calculations
    
    def add_rating(self, rating):
        # Add user rating and update averages
    
    def to_dict(self):
        # Serialize movie data for storage
 
class User:
    def __init__(self, user_id, name):
        # User profile and rating management
        # Favorite genre tracking
    
    def rate_movie(self, movie_id, rating):
        # Rate a movie and update preferences
    
    def update_favorite_genres(self, movies):
        # Analyze ratings to determine favorite genres
 
class MovieRecommendationSystem:
    def __init__(self, data_file="movie_data.json"):
        # Initialize system with data persistence
        # Load existing data or create sample data
movierecommendationsystem.py
class Movie:
    def __init__(self, movie_id, title, genres, year=None):
        # Movie metadata and rating management
        # Automatic rating calculations
    
    def add_rating(self, rating):
        # Add user rating and update averages
    
    def to_dict(self):
        # Serialize movie data for storage
 
class User:
    def __init__(self, user_id, name):
        # User profile and rating management
        # Favorite genre tracking
    
    def rate_movie(self, movie_id, rating):
        # Rate a movie and update preferences
    
    def update_favorite_genres(self, movies):
        # Analyze ratings to determine favorite genres
 
class MovieRecommendationSystem:
    def __init__(self, data_file="movie_data.json"):
        # Initialize system with data persistence
        # Load existing data or create sample data

Key Algorithms

Collaborative Filtering

movierecommendationsystem.py
def calculate_user_similarity(self, user1_id, user2_id):
    # Calculate Pearson correlation coefficient
    # Find users with similar rating patterns
    # Return similarity score between -1 and 1
 
def get_user_based_recommendations(self, user_id, limit=10):
    # Find similar users
    # Aggregate recommendations from similar users
    # Weight recommendations by user similarity
    # Return top-rated movies from similar users
movierecommendationsystem.py
def calculate_user_similarity(self, user1_id, user2_id):
    # Calculate Pearson correlation coefficient
    # Find users with similar rating patterns
    # Return similarity score between -1 and 1
 
def get_user_based_recommendations(self, user_id, limit=10):
    # Find similar users
    # Aggregate recommendations from similar users
    # Weight recommendations by user similarity
    # Return top-rated movies from similar users

Content-Based Filtering

movierecommendationsystem.py
def get_content_based_recommendations(self, user_id, limit=10):
    # Analyze user's favorite genres
    # Score unrated movies based on genre preferences
    # Consider movie ratings and popularity
    # Return movies matching user's taste profile
movierecommendationsystem.py
def get_content_based_recommendations(self, user_id, limit=10):
    # Analyze user's favorite genres
    # Score unrated movies based on genre preferences
    # Consider movie ratings and popularity
    # Return movies matching user's taste profile

Hybrid Approach

movierecommendationsystem.py
def get_hybrid_recommendations(self, user_id, limit=10):
    # Combine collaborative and content-based recommendations
    # Apply weighted scoring (70% collaborative, 30% content-based)
    # Merge and rank final recommendations
    # Return diverse, personalized suggestions
movierecommendationsystem.py
def get_hybrid_recommendations(self, user_id, limit=10):
    # Combine collaborative and content-based recommendations
    # Apply weighted scoring (70% collaborative, 30% content-based)
    # Merge and rank final recommendations
    # Return diverse, personalized suggestions

๐Ÿš€ How to Run

  1. Install Python: Ensure Python 3.7+ is installed

  2. Run the System:

    python movierecommendationsystem.py
    python movierecommendationsystem.py
  3. Getting Started:

    • Register as a new user or login with existing ID
    • Browse and rate some movies to build your profile
    • Get personalized recommendations
    • Explore different recommendation types

๐Ÿ’ก Usage Examples

Basic Usage

movierecommendationsystem.py
# Create recommendation system
system = MovieRecommendationSystem()
 
# Add a new user
user = system.add_user("John Doe")
 
# Rate some movies
system.rate_movie(user.id, 1, 5.0)  # Love "The Shawshank Redemption"
system.rate_movie(user.id, 3, 4.5)  # Really like "The Dark Knight"
system.rate_movie(user.id, 6, 4.0)  # Enjoy "Inception"
 
# Get recommendations
recommendations = system.get_hybrid_recommendations(user.id, 5)
for movie in recommendations:
    print(f"Recommended: {movie}")
movierecommendationsystem.py
# Create recommendation system
system = MovieRecommendationSystem()
 
# Add a new user
user = system.add_user("John Doe")
 
# Rate some movies
system.rate_movie(user.id, 1, 5.0)  # Love "The Shawshank Redemption"
system.rate_movie(user.id, 3, 4.5)  # Really like "The Dark Knight"
system.rate_movie(user.id, 6, 4.0)  # Enjoy "Inception"
 
# Get recommendations
recommendations = system.get_hybrid_recommendations(user.id, 5)
for movie in recommendations:
    print(f"Recommended: {movie}")

Advanced Features

movierecommendationsystem.py
# Find similar users
similarity = system.calculate_user_similarity(user1_id, user2_id)
print(f"User similarity: {similarity:.2f}")
 
# Get genre-specific movies
action_movies = system.get_movies_by_genre("Action")
 
# Search for movies
search_results = system.search_movies("dark knight")
 
# Get top-rated movies
top_movies = system.get_top_rated_movies(10, min_ratings=5)
movierecommendationsystem.py
# Find similar users
similarity = system.calculate_user_similarity(user1_id, user2_id)
print(f"User similarity: {similarity:.2f}")
 
# Get genre-specific movies
action_movies = system.get_movies_by_genre("Action")
 
# Search for movies
search_results = system.search_movies("dark knight")
 
# Get top-rated movies
top_movies = system.get_top_rated_movies(10, min_ratings=5)

Analytics

movierecommendationsystem.py
# Get comprehensive statistics
stats = system.get_movie_statistics()
print(f"Total movies: {stats['total_movies']}")
print(f"Most popular genres: {stats['most_common_genres']}")
movierecommendationsystem.py
# Get comprehensive statistics
stats = system.get_movie_statistics()
print(f"Total movies: {stats['total_movies']}")
print(f"Most popular genres: {stats['most_common_genres']}")

๐ŸŽจ Interactive Features

  1. Register/Login User - User account management
  2. Browse Movies - View all movies or filter by genre
  3. Search Movies - Find movies by title
  4. Rate Movie - Add ratings to build your profile
  5. Get Recommendations - Choose from different recommendation types
  6. View Top Rated Movies - Discover highly-rated films
  7. Add New Movie - Expand the movie database
  8. View Statistics - Database analytics and insights
  9. User Profile - View your ratings and preferences

Recommendation Types

  • User-based: โ€œUsers like you also enjoyedโ€ฆโ€
  • Content-based: โ€œBecause you liked [Genre]โ€ฆโ€
  • Hybrid: โ€œPersonalized for youโ€

๐Ÿ“Š Sample Data

The system comes pre-loaded with 20 popular movies including:

  • The Shawshank Redemption (1994) - Drama, Crime
  • The Dark Knight (2008) - Action, Crime, Drama
  • Inception (2010) - Action, Sci-Fi, Thriller
  • Pulp Fiction (1994) - Crime, Drama
  • The Matrix (1999) - Action, Sci-Fi

Each movie includes:

  • Multiple genres for accurate categorization
  • Release year for temporal analysis
  • Pre-generated ratings for immediate functionality

๐Ÿ”ง Advanced Features

Similarity Calculation

movierecommendationsystem.py
# Pearson correlation coefficient for user similarity
def calculate_user_similarity(self, user1_id, user2_id):
    # Find movies rated by both users
    # Calculate correlation between rating patterns
    # Return similarity score (-1 to 1)
movierecommendationsystem.py
# Pearson correlation coefficient for user similarity
def calculate_user_similarity(self, user1_id, user2_id):
    # Find movies rated by both users
    # Calculate correlation between rating patterns
    # Return similarity score (-1 to 1)

Preference Learning

movierecommendationsystem.py
# Automatic genre preference detection
def update_favorite_genres(self, movies):
    # Analyze highly-rated movies (4.0+)
    # Calculate average rating per genre
    # Rank genres by preference strength
movierecommendationsystem.py
# Automatic genre preference detection
def update_favorite_genres(self, movies):
    # Analyze highly-rated movies (4.0+)
    # Calculate average rating per genre
    # Rank genres by preference strength

Weighted Recommendations

movierecommendationsystem.py
# Hybrid scoring system
score = (collaborative_score * 0.7) + (content_score * 0.3)
movierecommendationsystem.py
# Hybrid scoring system
score = (collaborative_score * 0.7) + (content_score * 0.3)

๐Ÿ“ˆ Data Structure

Movie Format

{
  "id": 1,
  "title": "The Shawshank Redemption",
  "genres": ["Drama", "Crime"],
  "year": 1994,
  "ratings": [5.0, 4.5, 5.0, 4.0],
  "average_rating": 4.6,
  "rating_count": 4
}
{
  "id": 1,
  "title": "The Shawshank Redemption",
  "genres": ["Drama", "Crime"],
  "year": 1994,
  "ratings": [5.0, 4.5, 5.0, 4.0],
  "average_rating": 4.6,
  "rating_count": 4
}

User Format

{
  "id": 1,
  "name": "John Doe",
  "ratings": {"1": 5.0, "3": 4.5, "6": 4.0},
  "favorite_genres": ["Drama", "Action", "Sci-Fi"]
}
{
  "id": 1,
  "name": "John Doe",
  "ratings": {"1": 5.0, "3": 4.5, "6": 4.0},
  "favorite_genres": ["Drama", "Action", "Sci-Fi"]
}

๐Ÿ›ก๏ธ Error Handling

  • Data Validation: Validate ratings (1.0-5.0 range)
  • File Operations: Handle JSON file errors gracefully
  • User Input: Validate all user inputs and provide feedback
  • Missing Data: Handle cases with insufficient data for recommendations

๐Ÿ“š Learning Objectives

  • Recommendation Systems: Understanding different recommendation approaches
  • Machine Learning Concepts: Collaborative and content-based filtering
  • Data Analysis: Statistical analysis and correlation calculation
  • User Interface Design: Interactive command-line applications
  • Data Persistence: JSON storage and data management

๐ŸŽฏ Algorithm Insights

Collaborative Filtering Strengths:

  • Discovers unexpected connections
  • Works well with sufficient user data
  • Finds niche preferences

Content-Based Filtering Strengths:

  • Works for new users with few ratings
  • Transparent reasoning for recommendations
  • Consistent with user preferences

Hybrid Approach Benefits:

  • Combines strengths of both methods
  • More robust recommendations
  • Better coverage of different scenarios

๐Ÿš€ Potential Enhancements

  1. Machine Learning: Implement matrix factorization algorithms
  2. Web Interface: Create Flask/Django web application
  3. Database Integration: Use PostgreSQL or MongoDB
  4. Real-time Updates: Live recommendation updates
  5. Social Features: Friend recommendations and reviews
  6. Advanced Analytics: Recommendation effectiveness metrics
  7. External APIs: Integration with TMDB or IMDB
  8. Deep Learning: Neural collaborative filtering

๐Ÿ† Project Completion

This Movie Recommendation System demonstrates:

  • โœ… Multiple recommendation algorithms implementation
  • โœ… User profiling and preference learning
  • โœ… Data persistence and management
  • โœ… Statistical analysis and insights
  • โœ… Interactive user interface
  • โœ… Comprehensive error handling

Perfect for beginners learning recommendation systems and intermediate developers exploring machine learning concepts!

Was this page helpful?

Let us know how we did