A complete end-to-end Content-based recommendation system that recommends similar movies based on the user’s input.
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.
Popularity-based: Recommending the top products from their website to every user. This method will not consider the user’s interest. Eg, the Trending section on Youtube, IMDB top 250 movies.
This is based on the similarity between the products. Eg, If a user had 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.
This is based on the similarity of users. Eg, If person A and B had watched and liked the movie M, next if person A watches the movie Z and likes 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.
Hybrid filtering: This makes use of all or some of the above-mentioned methods to form a hybrid model.
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 in this project.
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 columns ‘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 name 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. Eg: 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.
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.