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.
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?
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:
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:
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.
Following are the steps we will be performing.
- Let us import basic libraries, read the dataset and create the data frames. The dataset can be downloaded from the linkβββdataset
- 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.
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