Movie Recommender with TMDB

Seth Jackson
Posted on Oct 6, 2020

A classic problem people have is finding a good movie to watch without doing a lot of research. To overcome this problem, recommender systems based on Machine Learning or Deep Learning are used to find movies that users are most likely to enjoy. There are 2 main types of recommender systems: Content Filtering (finds similarities between movies by their data), and Collaborative Filtering (finds similar movies by ratings and other data from users). This project uses Django to create a web application that allows the user to choose a movie and uses Content Filtering to recommend movies that are most similar to the one chosen by the user.

Content Filtering

Content Filtering is performed on The Movies Dataset, which contains metadata for over 45,000 movies. The main idea behind Content Filtering is that if a user likes a movie, then they will probably like other movies that are similar to it. Movie similarity is determined by the following metadata: Cast, Director, Keywords, and Genre. The metadata is text based, so some basic natural language processing is required before it can compare movies.

Processing the data involves the following steps:

  1. Removing stop words such as the, and, or, etc. They add no relevant information, so they are not useful for most types of analysis.
  2. Finding the director of the movie from the cast so the director has their own category.
  3. Removing spaces between words. This is done so that names and other multiple word terms like "Johnny Depp" and "Johnny Galecki" are not treated the same.
  4. Creating a metadata soup by appending each processed category to each other.

After the data is processed, Scikit-learn's CountVectorizer function is used to compute the similarity between movies by their metadata soup. Essentially, it takes the words in the soup and converts them into word vectors. Then, it performs a Cosine Similarity algorithm to compute the angle between word vectors. The smaller the angle between vectors, the more similar they are. The CountVectorizer creates a matrix with similarity scores for each pair of movies. For each movie, the scores were sorted to find the 10 most similar movies, which were added as a column to the dataframe, so they would not need to be calculated at runtime.

Django Application

Python has many libraries for creating a web application. Django is the most popular, thus it was chosen for this project. The app starts with a textbox where the user types a movie title. The textfield has autocomplete to make finding the desired movie quick and easy. Users can also select a random movie to find recommendations by clicking the "Surprise Me" button. Once the desired movie is selected, the "Get Selected Movies" button will get the 6 most similar movies, download their posters, and clicking on a poster will take the user to that movies' TMDB Page. The similarity scores and IMDB scores for each recommended movie are also displayed.


The Movie Database, also known as TMDB, is a database that contains detailed information on over 500,000 movies. The Movies dataframe has links to the movie posters in it, but the vast majority of them are outdated and no longer work. In order to find the poster links, the tmdbsimple library, which acts as a Python wrapper for the TMDB API was used. The ID of the movie is all that it takes to obtain that movie's updated information. The TMDB website has a simple structure to its URLs, therefore getting the link to each movie's page involves taking the base site link and adding the id of the movie, a dash, and the movie title.

Web Deployment

Heroku is a service that allows web applications from many languages to be deployed to a server for free. Heroku supports Django, and has Github integration, consequently each push onto the associated Github project will recompile the app and deploy it within minutes. There are some extra steps that need to be taken so that the Heroku server can install and run the libraries used in the application, but once it worked, it performed really well. A link to the Heroku server hosting the application can be found here.


It is difficult to determine the effectiveness of a recommendation system, especially without data from active users. To find some measure to evaluate, I plotted some data related to the similarity scores.

What these plots reveal is that the average of the similarity scores for each movie's recommendations is normally distributed, with most movies having scores between 0.3 and 0.5. The Ranges between the highest and lowest similarity scores is not normally distributed. Most values are between 0.1 and 0.2, but there are a surprising number of movies with a score range between 0.4 and 0.6. This seems to indicate that there are some movies that have recommendations that don't fit very well. There are 20 recommendations stored per movie, so perhaps after some point, the recommended movies are a poor fit.

Future Work

If given more time, I would include Collaborative Filtering in my recommender, which would include obtaining reviews and other user generated data by using the millions of reviews in the movies dataset to find similarities between users that make it more effective at recommending movies.

Another option is to avoid using The Movies Dataset altogether and having my app use the TMDB database itself as the source of its data. This would allow the recommender to increase the number of movies by an order of magnitude.

Finally, I would add additional features to the application to allow the user to restrict the types of movies that can be randomly selected by rating, year, foreign/domestic, etc. 

About Author

Seth Jackson

Seth Jackson

Seth Jackson is an expert in logic, economics, and philosophy with over 10 years of experience writing software. After getting a BA in Computer Science, he completed NYCDSA's Data Science program in order to obtain insights from data...
View all posts by Seth Jackson >

Related Articles

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp