1

I am new to python and trying to build a recommendation system following the instruction http://www.yekeren.com/blog/archives/1005,

what confuses me is that :

def reducer3_init(self):
        self.pop = { }

        file = open(self.options.item_pop, "r")

        for line in file.readlines():
            movieid_jstr, pop_jstr = line.strip().split("\t")
            movieid = json.loads(movieid_jstr)
            pop     = json.loads(pop_jstr)

            self.pop[movieid] = pop
        file.close()

    def reducer3(self, key, values):
        yield key, sum(values) / math.sqrt(self.pop[key[0]] * self.pop[key[1]])

The reduce3 has no corresponding mapper,how does it execute ? and what does json.load() do? A Lot Thanks!!

John Vandenberg
  • 474
  • 6
  • 16

1 Answers1

0

The documentation says:

class mrjob.step.MRStep(**kwargs)

Used by MRJob.steps. See Multi-step jobs for sample usage.

Accepts the following keyword arguments. Parameters:

mapper – function with same function signature as mapper(), or None for an identity mapper.

It is an idiom that map defaults to identity and reduce to flatten.

Clément MATHIEU
  • 3,030
  • 23
  • 25