Finding the highest-scoring movies
If you're looking for a good movie, you'll often want to see the most popular or best-rated movies overall. Initially, we'll take a naïve approach to compute a movie's aggregate rating by averaging the user reviews for each movie. This technique will also demonstrate how to access the data in our MovieLens
class.
Getting ready
These recipes are sequential in nature. Thus, you should have completed the previous recipes in this chapter before starting with this one.
How to do it...
Follow these steps to output numeric scores for all movies in the dataset and compute a top-10 list:
- Augment the
MovieLens
class with a new method to get all reviews for a particular movie:
In [8]: class MovieLens(object): ...: ...: ...: def reviews_for_movie(self, movieid): ...: """ ...: Yields the reviews for a given movie ...: """ ...: for review in self.reviews.values(): ...: if movieid in review: ...: yield review[movieid] ...:
- Then, add an additional method to compute the top...