This project demonstrates a simple movie recommendation system using Python and Google Colab. The system recommends movies based on user preferences and genres.
- Navigate to the file
MovieRecommender.ipynb
in this repository.- You can find it listed in the file section of this repository.
- Click on the file name
MovieRecommender.ipynb
. - On the notebook's page, click the "Download" button:
- Look for the "Download raw" option, or use the "Download" button in the file viewer.
- Save the file to your computer.
- Go to Google Colab.
- Log in with your Google account if not already logged in.
- In Google Colab, click on "File" in the top-left menu.
- Select "Upload notebook".
- Click "Choose file" and select the
MovieRecommender.ipynb
file you downloaded earlier. - Click "Open". The notebook will now load in Google Colab.
- To execute a cell, click on it and press the Play button (▶) to the left of the cell.
- If prompted, allow Colab to install any required Python libraries (you might see
!pip install
commands). - Follow the instructions in the notebook:
- Input your favorite movies.
- View the recommended movies based on the dataset provided.
The notebook uses a dataset of 100 movies with the following details:
- Genres: Action, Drama, Comedy, Sci-Fi, Horror, Romance, Fantasy, Adventure, Animation, Crime, etc.
- Movies: Titles include "The Shawshank Redemption," "The Godfather," "The Dark Knight," "Forrest Gump," "The Matrix," etc.
- Ratings: Each movie has an average rating between 3.0 and 5.0.
You can customize or expand the dataset directly in the notebook to experiment further.
Assuming the user likes these movies:
- Liked Movies:
The Shawshank Redemption
,The Godfather
,The Dark Knight
The system outputs the following top 5 recommendations:
Title | Genre | Average Rating | Recommendation Score |
---|---|---|---|
Thor: Ragnarok | Action | 4.98 | 5.98 |
The Green Mile | Drama | 4.96 | 5.96 |
Captain America: The Winter Soldier | Action | 4.90 | 5.90 |
Schindler's List | Drama | 4.84 | 5.84 |
Forrest Gump | Drama | 4.84 | 5.84 |
- In the notebook, locate the following code snippet:
liked_movies = ["The Shawshank Redemption", "The Godfather", "The Dark Knight"]
- Replace the movie titles in
liked_movies
with your own preferences. For example:liked_movies = ["Pulp Fiction", "Schindler's List", "Forrest Gump"]
- After modifying the
liked_movies
list, re-run all the cells in the notebook. - The recommendations will update based on the new preferences.
The recommendation system uses the following formula to calculate the Recommendation Score:
RecommendationScore = GenreScore + AverageRating
You can adjust this formula to give more weight to certain factors, such as user preferences (GenreScore) or the movie's general popularity (AverageRating). Below are two examples.
If you want the system to prioritize movies similar to the genres of the user's liked movies, increase the weight of GenreScore
. For example:
RecommendationScore = (2 * GenreScore) + AverageRating
To update the notebook:
- Locate the section where
RecommendationScore
is calculated:movies['RecommendationScore'] = movies['GenreScore'] + movies['Rating']
- Modify it to:
movies['RecommendationScore'] = (2 * movies['GenreScore']) + movies['Rating']
- Re-run all cells in the notebook to apply the new formula.
If you want to recommend movies that are highly rated across all users, increase the weight of AverageRating
. For example:
RecommendationScore = GenreScore + (2 * AverageRating)
To update the notebook:
- Locate the section where
RecommendationScore
is calculated:movies['RecommendationScore'] = movies['GenreScore'] + movies['Rating']
- Modify it to:
movies['RecommendationScore'] = movies['GenreScore'] + (2 * movies['Rating'])
- Re-run all cells in the notebook to apply the new formula.
Feel free to experiment with different weights to balance personalization and popularity. For example:
- Balanced Weighting:
RecommendationScore = (1.5 * GenreScore) + (1.5 * AverageRating)
- Focus on Genre Diversity:
RecommendationScore = (3 * GenreScore) + AverageRating
Update the formula in the notebook and re-run all cells to see how the recommendations change!
You can modify the scoring formula or introduce additional factors to adjust how recommendations are generated. Below are concepts you can add to the notebook, along with step-by-step instructions.
Encourage recommendations from underrepresented genres by penalizing overrepresented ones.
- Locate the section where
RecommendationScore
is calculated:
movies['RecommendationScore'] = movies['GenreScore'] + movies['Rating']
- Replace it with:
movies['DiversityPenalty'] = movies['Genre'].map(liked_genres_count) * -0.1
movies['RecommendationScore'] = movies['GenreScore'] + movies['Rating'] + movies['DiversityPenalty']
DiversityPenalty
adds a small penalty for movies in genres that are already highly represented in the user's liked movies.
This will promote diversity in the recommendations.
Boost the scores of more recent movies to cater to users who prefer newer content.
- Add a
ReleaseYear
column to the dataset (if it doesn't exist) with appropriate values. Locate theRecommendationScore
calculation and replace it with:
current_year = 2024
movies['RecencyBonus'] = (current_year - movies['ReleaseYear']) * -0.01
movies['RecommendationScore'] = movies['GenreScore'] + movies['Rating'] + movies['RecencyBonus']
Movies released in earlier years receive a small penalty, while recent movies get a bonus.
Ensure highly rated movies get an additional boost in recommendations.
Modify the RecommendationScore
calculation:
movies['PopularityBoost'] = movies['Rating'].apply(lambda r: 0.5 if r > 4.5 else 0)
movies['RecommendationScore'] = movies['GenreScore'] + movies['Rating'] + movies['PopularityBoost']
Movies with an average rating greater than 4.5 receive a boost, prioritizing highly rated content.
Include user preferences for specific directors or actors.
- Add a
Director
orCast
column to the dataset. - Locate the
RecommendationScore
calculation and add:
preferred_directors = ["Christopher Nolan", "Steven Spielberg"]
movies['DirectorBonus'] = movies['Director'].apply(lambda d: 0.5 if d in preferred_directors else 0)
movies['RecommendationScore'] = movies['GenreScore'] + movies['Rating'] + movies['DirectorBonus']
Movies directed by the user's favorite directors get a bonus, improving personalization.
Combine multiple factors like genre similarity, recency, and popularity with adjustable weights.
- Modify the RecommendationScore calculation:
movies['RecommendationScore'] = (
2 * movies['GenreScore'] +
1.5 * movies['Rating'] +
1 * movies['RecencyBonus'] +
0.5 * movies['PopularityBoost']
)
- You may try to play around with the weights and see what differences it makes.
The weights for each factor can be adjusted to balance the importance of each feature.
- Google Colab sessions may timeout after periods of inactivity. Save your progress often by downloading the updated notebook or saving a copy to your Google Drive.
- If the notebook shows an error about missing libraries, ensure you run any provided
!pip install
commands.
-
To Save a Copy to Google Drive:
- Click "File" > "Save a copy in Drive".
- This will store the notebook in your Google Drive for future use.
-
To Download the Updated Notebook:
- Click "File" > "Download .ipynb" to save it locally.
If you encounter any issues or have suggestions for improvement, feel free to contact me or open an issue in this repository.
This project is open-source and available under the MIT License. Feel free to use and modify it for personal or educational purposes.