在 MATLAB 中获取 Kmeans 聚类中最接近质心的数据点的索引
我正在 MATLAB 中使用 K-means 进行一些聚类。您可能知道用法如下:
[IDX,C] = kmeans(X,k)
其中 IDX 给出 X 中每个数据点的簇号,C 给出每个簇的质心。我需要获取该簇的索引(实际数据集 X 中的行号)距离质心最近的数据点。有谁知道我该怎么做? 谢谢
I am doing some clustering using K-means in MATLAB. As you might know the usage is as below:
[IDX,C] = kmeans(X,k)
where IDX gives the cluster number for each data point in X, and C gives the centroids for each cluster.I need to get the index(row number in the actual data set X) of the closest datapoint to the centroid. Does anyone know how I can do that?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 @Dima 将如下所示
要获取最接近聚类中心
k
的点的坐标,请使用The "brute-force approach", as mentioned by @Dima would go as follows
To get the coordinates of the point that is closest to the cluster center
k
, use强力方法是运行 k 均值,然后将簇中的每个数据点与质心进行比较,并找到最接近它的一个。这在 matlab 中很容易做到。
另一方面,您可能想尝试 k-medoids 聚类算法,该算法给出您将一个数据点作为每个簇的“中心”。这是一个 matlab 实现。
The brute force approach would be to run k-means, and then compare each data point in the cluster to the centroid, and find the one closest to it. This is easy to do in matlab.
On the other hand, you may want to try the k-medoids clustering algorithm, which gives you a data point as the "center" of each cluster. Here is a matlab implementation.
实际上,如果我理解正确的话,kmeans 已经给了你答案:
Actually, kmeans already gives you the answer, if I understand you right: