How to find cluster centers of Spark's StreamingKMeans?

不想你离开。 提交于 2019-12-12 01:37:24

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/38544777/how-to-find-cluster-centers-of-sparks-streamingkmeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!