Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6127907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:33:58+00:00 2026-05-23T16:33:58+00:00

I’m getting started with using python’s mrjob to convert some of my long running

  • 0

I’m getting started with using python’s mrjob to convert some of my long running python programs into MapReduce hadoop jobs. I’ve gotten the simple word count examples to work and I conceptually understand the ‘text-classification’ example.

However, I’m having a little trouble figuring out the steps I need to do to get my problem working.

I have multiple files (about 6000) each of which have 2 to 800 lines each. In this case each line is a simple space-delimited ‘signal’. I need to compare correlation between each line in each file and EVERY other line in ALL files (including itself). Then based on the correlation coefficient I’ll output the results.

An example of one file:

1 2 3 4 2 3 1 2 3 4 1 2
2 2 3 1 3 3 1 2 3 1 4 1
2 3 4 5 3 2 1 3 4 5 2 1
...

I need to yield each LINE of this file paired with EVERY OTHER LINE from every other file … or I could concatenate all files into one file if that makes things easier, but I would still need the pairwise iteration.

I understand how to do the calculation and how to use the final reduce step to aggregate and filter the results. The difficulty I’m having is how to I yield all pairwise items to successive steps without reading all files in a single setp? I guess I could prepare an input file ahead of time which uses itertools.product but this file would be prohibitively large.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:33:59+00:00Added an answer on May 23, 2026 at 4:33 pm

    Well, since nobody has come up with an answer I’ll post my current work-around in-case anybody else out there needs it. I’m not sure how ‘canocical’ or efficient this is but its worked so far.

    I put the filename as the first item of each line of the file followed by a \t followed by the rest of the data. For this example I’m just using a single number on each line and then averaging them, just as a very trivial example.

    Then I made the following map-reduce step in mrjob.

    class MRAvgPairwiseLines(MRJob):
    
    def input_mapper(self, _, value):
        """Takes each input line and converts it to (fnum, num) and a key of 'ALL'"""
    
        fnum, val = value.split('\t')
        yield 'ALL', (fnum, val)
    
    def input_reducer(self, key, values):
    
        for (fnum1, val1), (fnum2, val2) in product(values, repeat = 2):
            yield fnum1, (fnum1, fnum2, val1, val2)
    
    def do_avg(self, key, value):
    
        fnum1, fnum2, val1, val2 = value
        res = (float(val1)+float(val2))/float(2)
        yield key, (fnum2, res)
    
    def get_max_avg(self, key, values):
    
        max_fnum, max_avg = max(values, key = lambda x: x[1])
        yield key, (max_fnum, max_avg)
    
    def steps(self):
        return [self.mr(mapper=self.input_mapper, reducer=self.input_reducer),
                    self.mr(mapper=self.do_avg, reducer=self.get_max_avg)]
    

    This way all of the output from the input_mapper function gets grouped to the same input_reducer which then yields successive pairs. These then pass through to the proper places to finally return the largest average (which is actually the largest item in all other files).

    Hope that helps someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.