Reputation: 897
I trained a k means model with my dataset and now I would like to get a few elements from each clusters along with the cluster id
val clusters = KMeans.train(data, numClusters, numIterations)
val vectorsAndClusterIdx = data.map{ point =>
val prediction = clusters.predict(point)
(point.toString, prediction)
}
But then once I have that, I don't know how to print these elements with their clusters ids
Upvotes: 1
Views: 480
Reputation: 46
If I understood you, you want to print each point with its assigned cluster id.
You could try something like this:
vectorsAndClusterIdx.collect().foreach(println(_))
Or maybe it would be better:
println(dataClustered.collect().mkString("\n"))
Upvotes: 1