See the results of your work.
- [Instructor] Now that we have a working product recommendation system let's see what results we get for different users. Let's take a look at make_recommendations.py. First we'll read in the data set using panda's read csv command. We'll also load the movie list using read csv so we have access to the movie titles as well. Then we'll use panda's pivot table function to create the review matrix, then we'll factor the review matrix to get the U and M matrices. Then we'll multiply U and M to create the predicted ratings for each user. Now that we have predicted ratings we can make predictions.
Here we'll prompt for a user ID that way the user can type in any user ID to see recommendations for different users. Before we print out the users recommended movies, let's print out the movies the user has already rated themself. We can look them up in the raw data set df data frame. We'll ask pandas to filter down the list to the entries where the user ID is the same one as the user just typed in. Next let's join this list of reviews with the movie df data frame so we can display the tile of each movie. We can do that with panda's join function.
The join function takes in the data to join and then the field to use to join the two tables. Now we'll print out the list of reviewed movies with the title, the genre, and the value, or rating that the user gave the movie. Now let's get the list of movies we want to recommend to this user. First let's pull out the predicted ratings for this specific user from the predicted ratings array. We need to subtract one here because this array is zero index but the user IDs start at one. Now we can save the predicted rating for each movie back to the list of movies to make it easy to print out.
At this point we have a list of movies with a score for every movie based on how much the user would like it, but we don't want to show the movies that the user has already rated. So we need to exclude those movies from the list. We can get the list of movie IDs that the user's already reviewed and save those to a variable called already reviewed. Then we'll look at the movies that are not in that list. This line is a little complex. First we're using the is in function to find the movies that are in the list then we're comparing that list with false to invert it and find the movies that are not in that list.
Then we can use sort values to sort the list so that the highest rated movie is first. And then finally we can use panda's head function to print out the first five movies in the list. Let's run the code and try it out. Right-click, choose run. It asks us for a user ID. Let's type in user 2 and hit enter. These are the movies that user ID 2 has already rated. We can see the user gave five stars to sci-fi, mystery, thriller, and drama movies. Notice that this user gave five stars to both The Big City Judge 1 and The Sheriff 1.
Now let's hit enter and see what recommendations our system generated. Alright, these five movies look like pretty good recommendations. Three of these recommendations are even sequels to movies the user had rated highly. The Big City Judge Parts 2 and 3 and The Sheriff 3. Let's run the program again for different user. Right-click, choose run. Let's try user 54. Notice that this user gave five stars to The Sheriff 4. I'm not exactly sure why the user only watched Part 4, but let's see what recommendations they get.
Not surprisingly the system thinks the user might enjoy The Sheriff Part 1 and Part 3 as well. It looks like everything's working pretty well. You can try out the system for different user IDs and see what kinds of results you get.
Recommendation systems are a key part of almost every modern consumer website. The systems help drive customer interaction and sales by helping customers discover products and services they might not ever find themselves. The course uses the free, open source tools Python 3.5, pandas, and numpy. By the end of the course, you'll be equipped to use machine learning yourself to solve recommendation problems. What you learn can then be directly applied to your own projects.
- Building a machine learning system
- Training a machine learning system
- Refining the accuracy of the machine learning system
- Evaluating the recommendations received