title: Kmeans with Spark
body: <p>The following is a part of Kmeans algorithm which is written with Apache Spark:</p>
  
  <pre><code>closest = data.map(lambda p: (closestPoint(p, kPoints), (p, 1)))
  pointStats = closest.reduceByKey(lambda (x1, y1), (x2, y2): (x1 + x2, y1 + y2))
  newPoints = pointStats.map(lambda (x, (y, z)): (x, y / z)).collect()
  </code></pre>
  
  <p>Can anyone explain to me how does it work? Assuming we have two clusters and 1000 points and we want to run it in cluster with two slave nodes and one master node. I think the first function (closest) can be considered as mapper and the second one would be combiner but what about the last  function what it is suppose to do? and which one act as reducer? </p>