let' start by printing out the cluster assignments for each one of our points sowe're going to take our original data and transform it using lambda functionsftvmu %ebubnbq mbncebqpjou dmvtufstqsfejdu qpjou dbdif this function is just going to transform each point into the cluster number that is predicted from our model againwe're just taking our rdd of data points we're calling dmvtufstqsfejdu to figure out which cluster our -means model is assigning them toand we're just going to put the results in our sftvmu %nowone thing want to point out here is this cache callin the above code an important thing when you're doing spark is that any time you're going to call more than one action on an rddit' important to cache it firstbecause when you call an action on an rddspark goes off and figures out the dag for itand how to optimally get to that result it will go off and actually execute everything to get that result soif call two different actions on the same rddit will actually end up evaluating that rdd twiceand if you want to avoid all of that extra workyou can cache your rdd in order to make sure that it does not recompute it more than once by doing thatwe make sure these two subsequent operations do the right thingqsjou $pvoutczwbmvf dpvout sftvmu %%dpvou# bmvf qsjou dpvout qsjou $mvtufsbttjhonfout sftvmut sftvmu %%dpmmfdu qsjou sftvmut in order to get an actual resultwhat we're going to do is use dpvou# bmvfand what that will do is give us back an rdd that has how many points are in each cluster remembersftvmu %currently has mapped every individual point to the cluster it ended up withso now we can use dpvou# bmvf to just count up how many values we see for each given cluster id we can then easily print that list out and we can actually look at the raw results of that rdd as wellby calling dpmmfdu on itand that will give me back every single points cluster assignmentand we can print out all of them