From the course: Machine Learning with ML.NET

Build an ML model for movie recommendations - .NET Tutorial

From the course: Machine Learning with ML.NET

Build an ML model for movie recommendations

- In this video, we will take a look at how to build a custom machine learning model for movie recommendations. Let's go and understand how does movie recommendation work and what are the different ways of recommending movies? The most common way of recommending movies is by rating. So let's assume you have a website where people can browse and see movies and they can rate all the movies. And so the simplest recommendation system is recommend me movies if the rating is higher than eight and so that's one way of recommending movies. The second way of recommending movies is by content-based filtering. So this is around movies of certain genre are very popular. So for example, recommend me action movies based on my browsing history if I like a lot of action movies or recommend me superhero movies if I like lot of superhero movies. The third approach is around collaborative filtering which combines the first two approaches. What this approach comes down to is, let's say there are different users who have different browsing or viewing habits. In this case, what's happening here is we have three users Ankit, Gal and Cesar. And they have three different patterns for "Heat," "Mission Impossible" and "Home Alone." And the question over here is, what's the probability of Gal liking "Home Alone?" Collaborative filtering is observing the behaviors of users who have common likes and comment dislikes. And so for example in this case, we know that Cesar likes "Heat" and "Mission Impossible" and Gal also likes "Heat" and "Mission Impossible." So if Cesar and Gal have similar viewing habits and Cesar doesn't like "Home Alone" then it's more likely that Gal also doesn't like "Home Alone." And so this is collaborative filtering and this is what we can use in our movie recommendation example. Let's understand what the data looks like for a typical scenario for recommending movies. This is a typical data set which also becomes your features or your input to your model in terms of how do you want to recommend movies. We have user IDs, we have movie IDs and movie names or movie genres and ratings and time stamp. And this data set is directly capturing, what were the viewing habits of these set of users? And then what did they actually like in terms of ratings and what did they actually see in terms of movies which has information around what was the genre of the movie and other sort of characteristics as well. The output or the column that you want to predict or the output of your machine learning model becomes the rating, which means what's the likelihood of this user liking the movie or not? And so you're going to recommend a set of movies to a user based on their browsing history or their likes and dislikes using the collaborative filtering approach that we just saw. Now that you've understood the basics of movie recommendation, let's see how movie recommendation model can be built and used in your applications. So I have two projects in my solution, one is on how the model was trained and the other is a web application where I'm going to use the model. So let's look at how the model was trained as well. We know that in a typical machine learning workflow, the first steps are around sort of loading your data, so in this case I have loaded data from my ratings data set which has the ratings for all the users along with the movie that they saw and the rating that they gave. And I'm going to featurize all the values of the movies, and I'm going to use this as input features. So my user ID and movie ID are going to become my input features. And for my training algorithm I'm going to use field aware factorization machine, where I'm going to input all the features and I'm going to train the model. Then I'm going to evaluate the model by trying out that model on a specific user and then seeing what the top five movies that I can recommend to the user as well. So let's go ahead and run this application first. And so let's launch it. What this will do is it will load the data set, it will extract all the features, it will train the model, evaluate the model and then try the model as well. So in this case, it evaluated the model with around 60% accuracy. And for a user ID six with movie ID 10, the probability of me liking movie ID is about 45%. So that's an example of building a recommendation model. Let's switch over to our web application and see this model in practice. So this is ASP.NET web application. You can imagine that this is your movie site, where I have three users Ankit, Amy and Cesar. And if I click Ankit, you can see that this is the browsing history for Ankit where he's watched "Heat," "Terminator 2," "Independence Day." And these are the all-time Box-Office movies that are popular all up. So when I click recommend, what I want to find out is of all the top Box-Office movies, which are the ones that Ankit is most likely to see. So if I click recommend, you would see that is a 56% chance that Ankit will like "Face Off," 88% chance that Ankit will like "Casino Royale" and 85% chance that Ankit might like "Gladiator." If I go back to my side and switch to Cesar, and recommend movies for Cesar as well. You will see that Cesar has about 70% likelihood of liking "Gladiator." And if you look at how this was built, I can go over to my movies controller and I can go to the recommended action. Where what we're doing over here is we are loading the machine learning model that we just built and we are calling the prediction engine for that particular user and getting the list of movies that the user is going to like, and we're going to update the view with that particular information as well. So, that's how you can start incorporating recommendation into your application. So what we saw over here was how to build a custom machine learning model for movie recommendation. In the next video, we will take a look at how to build a machine learning model for classifying images.

Contents