在matlab中重新计算质心kmeans

时间:2017-11-07 16:45:38

标签: matlab

我正在尝试使用kmeans在matlab下实现一个id我有一个小问题我想重新计算新集群的质心我试图从包matlab中获取kmeans.m的代码来获取函数我得到了这个: 的 %%%%%%%%%%%%%%%%%%%%%

function [centroids, counts] = gcentroids(X, index, clusts, dist)
%GCENTROIDS Centroids and counts stratified by group.
p = size(X,1);
num = length(clusts);

centroids = NaN(p,num,'like',X);
counts = zeros(1,num,'like',X);

for i = 1:num
    members = (index == clusts(i));
    if any(members)
       counts(i) = sum(members);
       switch dist
           case {'sqeuclidean','cosine','correlation'}
              centroids(:,i) = sum(X(:,members),2) / counts(i);
      end
    end
end
end

0 个答案:

没有答案