<s> import csv <EOL> from numpy import array <EOL> from StringIO import StringIO <EOL> from pyspark import SparkConf , SparkContext <EOL> from pyspark . mllib . regression import LabeledPoint , LinearRegressionWithSGD <EOL> def parsePoint ( line ) : <EOL> values = csv . reader ( StringIO ( line ) , delimiter = "<STR_LIT:;>" ) . next ( ) <EOL> values = [ float ( x ) for x in values ] <EOL> return LabeledPoint ( values [ - <NUM_LIT:1> ] , values [ : - <NUM_LIT:1> ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> conf = SparkConf ( ) . setMaster ( "<STR_LIT>" ) . setAppName ( "<STR_LIT>" ) <EOL> sc = SparkContext ( conf = conf ) <EOL> wines = sc . textFile ( "<STR_LIT>" ) <EOL> parsedData = wines . map ( parsePoint ) <EOL> model = LinearRegressionWithSGD . train ( parsedData ) <EOL> valuesAndPreds = parsedData . map ( lambda p : ( p . label , model . predict ( p . features ) ) ) <EOL> MSE = valuesAndPreds . map ( lambda ( v , p ) : ( v - p ) ** <NUM_LIT:2> ) . reduce ( lambda x , y : x + y ) . count ( ) / valuesAndPreds . count ( ) <EOL> print ( "<STR_LIT>" + str ( MSE ) ) </s>
