I want this map reduce job (code below) to output the top 10 most rated products. It keeps giving me the following error message:
it = izip(iterable, count(0,-1)) # decorate TypeError: izip argument #1 must support iteration.
I'm thinking it has to do with the nlargest function I am trying to apply.
Any pointers?
Thank you!
from mrjob.job import MRJob
from mrjob.step import MRStep
from heapq import nlargest
class MostRatedProduct(MRJob):
def steps(self):
return [
MRStep(mapper = self.mapper_get_ratings,
reducer = self.reducer_count_ratings),
MRStep(reducer = self.reducer_find_top10)
]
def mapper_get_ratings(self, _, line):
(userID, itemID, rating, timestamp) = line.split(',')
yield itemID, 1
def reducer_count_ratings(self, itemID, ratingCount):
yield None, (sum(ratingCount), itemID)
def top_10(self, ratingPair):
for ratingTotal, itemID in ratingPair:
top_rated = nlargest(10, ratingTotal)
for top_rated in ratingTotal:
return (ratingTotal, itemID)
def reducer_find_top10(self, key, ratingPair):
ratingTotal, itemID = self.top_10(ratingPair)
yield ratingTotal, itemID
if __name__ == '__main__':
MostRatedProduct.run()