To predict how we might rate a particular movie, we can compute a weighted average of critics who have also rated the same movies as the user. The weight will be the similarity of the critic to the user if a critic has not rated a movie, then their similarity will not contribute to the overall ranking of the movie.
The following steps walk you through the prediction of movie ratings for users:
- First, add the
predict_ranking
function to theMovieLens
class in order to predict the ranking that a user might give a particular movie with similar critics:
In [17]: def predict_ranking(self, user, movie, metric='euclidean', critics=None):
...: """
...: Predicts the ranking a user might give a movie according to the
...: weighted average of the critics that are similar to the that user.
...: """
...:
...: critics = critics or self.similar_critics(user...