within set sum of squared errors (wsssenowhow do we measure how good our clusters arewellone metric for that is called the within set sum of squared errorswowthat sounds fancyit' such big term that we need an abbreviation for itwssse all it iswe look at the distance from each point to its centroidthe final centroid in each clustertake the square of that error and sum it up for the entire dataset it' just measure of how far apart each point is from its centroid obviouslyif there' lot of error in our model then they will tend to be far apart from the centroids that might applyso for that we need higher value of kfor example we can go ahead and compute that value and print it out with the following codeefgfssps qpjou dfoufs dmvtufstdfoufst sfuvsotrsu tvn ebubnbq mbncebqpjou fssps qpjou sfevdf mbnceby qsjou  juijo fu vnpg rvbsfe&ssps tus first of allwe define this fssps function that computes the squared error for each point it just takes the distance from the point to the centroid center of each cluster and sums it up to do thatwe're taking our source datacalling lambda function on it that actually computes the error from each centroid center pointand then we can chain different operations together here firstwe call nbq to compute the error for each point then to get final total that represents the entire datasetwe're calling sfevdf on that result sowe're doing ebubnbq to compute the error for each pointand then sfevdf to take all of those errors and add them all together and that' what the little lambda function does this is basically fancy way of saying" want you to add up everything in this rdd into one final result sfevdf will take the entire rddtwo things at timeand combine them together using whatever function you provide the function ' providing it above is "take the two rows that ' combining together and just add them up if we do that throughout every entry of the rddwe end up with final summed-up total it might seem like little bit of convoluted way to just sum up bunch of valuesbut by doing it this way we are able to make sure that we can actually distribute this operation if we need to we could actually end up computing the sum of one piece of the data on one machineand sum of different piece over on another machineand then take those two sums and combine them together into final result this sfevdf function is sayinghow do take any two intermediate results from this operationand combine them together