This recipe brings this chapter on recommendation engines to a close. We will now use our new non-negative matrix factorization based model and take a look at some of the predicted reviews.
The final step in leveraging our model is to access the predicted reviews for a movie based on our model:
In [30]: def predict_ranking(self, user, movie):
...: uidx = self.users.index(user)
...: midx = self.movies.index(movie)
...: if self.reviews[uidx, midx] > 0:
...: return None
...: return self.model[uidx, midx]
Computing the ranking is relatively easy; we simply need to look up the index of the user and the index of the movie and look up the predicted rating in our model. This is why it is so essential to save an ordered list of the users and movies in our pickle
module; this way, if the data changes (we add users or movies), but the change isn't reflected in our model, an exception is raised. Because models are historical predictions and...