<s> import sys <EOL> import numpy as np <EOL> from pyspark import SparkConf , SparkContext <EOL> from pyspark . mllib . clustering import KMeans <EOL> def parse_vector ( line , sep = '<STR_LIT:U+002C>' ) : <EOL> """<STR_LIT>""" <EOL> fields = line . strip ( ) . split ( sep ) <EOL> latitude = float ( fields [ <NUM_LIT:1> ] ) <EOL> longitude = float ( fields [ <NUM_LIT:2> ] ) <EOL> return np . array ( [ latitude , longitude ] ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if len ( sys . argv ) != <NUM_LIT:3> : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> exit ( - <NUM_LIT:1> ) <EOL> conf = SparkConf ( ) . setMaster ( "<STR_LIT>" ) . setAppName ( "<STR_LIT>" ) . set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> sc = SparkContext ( conf = conf ) <EOL> earthquakes_file = sys . argv [ <NUM_LIT:1> ] <EOL> training = sc . textFile ( earthquakes_file ) . map ( parse_vector ) <EOL> k = int ( sys . argv [ <NUM_LIT:2> ] ) <EOL> model = KMeans . train ( training , k ) <EOL> print "<STR_LIT>" + str ( model . clusterCenters ) <EOL> sc . stop ( ) </s>
