如何找到Spark的StreamingKMeans的集群中心? [英] How to find cluster centers of Spark's StreamingKMeans?

查看:212
本文介绍了如何找到Spark的StreamingKMeans的集群中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Spark的KMeansModel类时,可以使用KMeansModel.clusterCenters()函数轻松访问模型集群的质心.

When I use Spark's KMeansModel class, I can easily access the centroids of my model's clusters using the KMeansModel.clusterCenters() function.

我想使用StreamingKMeans,但我注意到它似乎缺少clusterCenters()函数.有没有办法在StreamingKMeans中获取模型簇的质心?

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?

推荐答案

在批处理KMeans中,估计器接受一次训练并生成一个转换器-该模型包含clusterCenters()方法.在StreamingKMeans中,模型会不断更新,因此您需要在StreamingKMeans对象上使用latestModel().

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)

这篇关于如何找到Spark的StreamingKMeans的集群中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆