Master LLMs with our FREE course in collaboration with Activeloop & Intel Disruptor Initiative. Join now!

Publication

Practical Implementation of Content-Based Recommendation System
Latest

Practical Implementation of Content-Based Recommendation System

Last Updated on January 7, 2023 by Editorial Team

Author(s): Gowtham S R

Originally published on Towards AI the World’s Leading AI and Technology News and Media Company. If you are building an AI-related product or service, we invite you to consider becoming an AI sponsor. At Towards AI, we help scale AI and technology startups. Let us help you unleash your technology to the masses.

A complete end-to-end Content-based recommendation system that recommends similar movies based on the user’s input.

Image from Unsplash uploaded by Krists Luhaers

What is a recommendation system?

Whenever we visit a shopping mall to buy a new pair of shoes or clothes, we find a dedicated person who helps us with the kind of products we should buy based on our preferences and makes our job simpler. In simple words, he is a recommendation system. But in this modern world, everything is online, and there is so much content on the internet, there are crores of videos on Youtube and crores of products on Amazon, which makes it difficult for the user to choose. There comes the recommendation system, which makes the user’s life simple by recommending the next video to watch or a similar product to buy.

A recommendation system is a piece of code that is intelligent enough to understand the user’s preferences and recommend things based on his/her interest, the goal is to increase profitability. For Eg, Youtube and NetFlix want you to spend more time on their platform, so they recommend the videos based on the user’s preferences. Amazon wants you to buy products from their website so that they can make more profit.

What are the different types of Recommendation systems?

Image by author

Popularity-based: Recommending the top products from their website to every user. This method will not consider the user’s interest. E.g., the Trending section on Youtube, IMDB top 250 movies.

Content-based:

Image by author

This is based on the similarity between the products. E.g., If a user has watched a movie and liked it, he may like to watch similar movies in the future. This can be based on the genre, actor, actress, or director.

Collaborative filtering:

Image by author

This is based on the similarity of users. E.g., If person A and B had watched and liked the movie M, next if person A watched the movie Z and liked it, we can recommend the movie Z to person B since A and B are similar users.

If you are keen to know how we can build a popularity-based and collaborative-filtering-based recommendation system, consider reading the below blog.

A Complete end to end Machine Learning based Recommendation Project

Hybrid filtering: This makes use of all or some of the above-mentioned methods to form a hybrid model.

Content-based Movie Recommendation System:

Let us look at how we can build a content-based book recommendation system. Below is the image of the final model that we are going to build for this project.

Image by author

Following are the steps we will be performing.

  • Merge the data frames ‘movies’ and ‘credits’ to get the final data frame.
  • Consider only the required columns.
  • working on the column — genres:

The column ‘genres’ is the list of dictionaries, it has both keys and values, but we need only the genre values, so let us make a function to get only the required data.

The ‘genres’ column now contains only the required data.

  • Let us apply the same function to column ‘keywords.’
  • Let us modify the above function to get only the first 3 cast names.
  • Let us get the director’s name from the column ‘crew’ by modifying the above function.
  • Let us convert the column ‘overview’ from string to list
  • We need to modify the names of the crew and cast members in such a way that there should not be any space between the names because when we convert words into vectors, our machine learning model will get impacted. E.g., James Cameron should be converted to ‘JamesCameron’ and Johnny Depp to be converted to JohnnyDepp and Science Fiction to be converted to ScienceFiction.
  • Let us make a new column called tags by concatenating the features ‘keywords’, ‘overview’, ‘genres’, ‘cast’, and ‘crew’.
  • Let us make a new data frame new_df by taking only the features ‘movie_id’, ‘title’, and ‘tags’.
  • Let us convert the feature ‘tags’ from a list to a string.
  • Convert the feature ‘tags’ into lowercase.
  • Apply stemming for converting the words into their base forms.
  • Now let us convert the tags into a Bag of words while removing all the stop words, and now the movie vectors will be ready. Each movie is a vector with 5000 dimensions.
  • Let us calculate the similarity score between each movie vector.
  • Let us make a function that takes a movie name as the input and recommends 5 movies based on the similarity scores.

Take a look at some of the recommendations from the model.

  • Model Deployment: Let's make use of the ‘streamlit’ library to make a simple GUI and deploy the model.

We have successfully completed the front end of the app, and you can deploy it to any of the cloud platforms. Take a look at some of the recommendations below.

Image by author
Image by author
Image by author

We have successfully completed all the steps, and our model is ready. You can try and build a similar model. The complete code can be found on my Github page.


Practical Implementation of Content-Based Recommendation System was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

Join thousands of data leaders on the AI newsletter. It’s free, we don’t spam, and we never share your email address. Keep up to date with the latest work in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓