我正在使用MATLAB中的K-means进行一些聚类。如你所知,它的用法如下:
[IDX,C] = kmeans(X,k)其中IDX给出了X中每个数据点的簇号,C给出了每个簇的质心。我需要获得最接近质心的数据点的索引(实际数据集X中的行号)。有人知道我是怎么做到的吗?谢谢
发布于 2010-12-10 00:01:36
@Dima提到的“蛮力方法”如下所示
%# loop through all clusters
for iCluster = 1:max(IDX)
    %# find the points that are part of the current cluster
    currentPointIdx = find(IDX==iCluster);
    %# find the index (among points in the cluster)
    %# of the point that has the smallest Euclidean distance from the centroid
    %# bsxfun subtracts coordinates, then you sum the squares of
    %# the distance vectors, then you take the minimum
    [~,minIdx] = min(sum(bsxfun(@minus,X(currentPointIdx,:),C(iCluster,:)).^2,2));
    %# store the index into X (among all the points)
    closestIdx(iCluster) = currentPointIdx(minIdx);
end要获取距离聚类中心k最近的点的坐标,请使用
X(closestIdx(k),:)发布于 2010-12-09 23:48:03
暴力方法是运行k-means,然后将集群中的每个数据点与质心进行比较,并找到最接近它的数据点。在matlab中很容易做到这一点。
另一方面,您可能希望尝试k-medoids聚类算法,该算法提供一个数据点作为每个集群的“中心”。这是一个matlab implementation。
发布于 2016-12-12 16:03:28
实际上,如果我没理解错的话,kmeans已经给了你答案:
[IDX,C, ~, D] = kmeans(X,k); % D is the distance of each datapoint to each of  the clusters
[minD, indMinD] = min(D); % indMinD(i) is the index (in X) of closest point to the i-th centroidhttps://stackoverflow.com/questions/4400070
复制相似问题