<s> """<STR_LIT>""" <EOL> import sys <EOL> import csv <EOL> from framework import Mapper <EOL> class MSEMapper ( Mapper ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( MSEMapper , self ) . __init__ ( * args , ** kwargs ) <EOL> self . coef = [ ] <EOL> self . intercept = None <EOL> with open ( '<STR_LIT>' , '<STR_LIT:r>' ) as params : <EOL> data = params . read ( ) . split ( "<STR_LIT:\n>" ) <EOL> data = [ float ( row . strip ( ) ) for row in data if row . strip ( ) ] <EOL> self . coef = data [ : - <NUM_LIT:1> ] <EOL> self . intercept = data [ - <NUM_LIT:1> ] <EOL> def read ( self ) : <EOL> """<STR_LIT>""" <EOL> reader = csv . reader ( super ( MSEMapper , self ) . read ( ) ) <EOL> for row in reader : <EOL> yield [ float ( x ) for x in row ] <EOL> def compute_error ( self , row ) : <EOL> vals = row [ : - <NUM_LIT:1> ] <EOL> y = row [ - <NUM_LIT:1> ] <EOL> yhat = sum ( [ b * x for ( b , x ) in zip ( self . coef , vals ) ] ) + self . intercept <EOL> return ( y - yhat ) ** <NUM_LIT:2> <EOL> def map ( self ) : <EOL> """<STR_LIT>""" <EOL> for row in self : <EOL> self . emit ( <NUM_LIT:1> , self . compute_error ( row ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> mapper = MSEMapper ( sys . stdin ) <EOL> mapper . map ( ) </s>
