Reputation: 1023
When I use Spark's KMeansModel class, I can easily access the centroids of my model's clusters using the KMeansModel.clusterCenters()
function.
I wanted to use StreamingKMeans, but I noticed that it seems to lack a clusterCenters()
function. Is there a way to obtain the centroids of my model's clusters in StreamingKMeans?
Upvotes: 0
Views: 574
Reputation: 331
In batch KMeans, an estimator is trained once and produces a single transformer - the model which contains the clusterCenters()
method. In StreamingKMeans, a model is continuously updated, so you need to use the latestModel()
on the StreamingKMeans object.
val model = new StreamingKMeans()
.setK(5)
.setDecayFactor(1.0)
.setRandomCenters(10, 0.0)
val latestModel = model.latestModel()
println(latestModel.clusterCenters)
Upvotes: 1