怎样用matlab实现多维k-means聚类算法
1个回答
展开全部
function [ labels ] = kmeans_clustering( data, k )
[num,~]=size(data);
ind = randperm(num);
ind = ind(1:k);
centers = data(ind,:);
d=inf;
labels = nan(num,1);
while d>0
labels0 = labels;
dist = pdist2(data, centers);
[~,labels] = min(dist,[],2);
d= sum(labels0 ~= labels);
for i=1:k
centers(i,:)=mean(data(labels == i,:),1);
end
end
end
[num,~]=size(data);
ind = randperm(num);
ind = ind(1:k);
centers = data(ind,:);
d=inf;
labels = nan(num,1);
while d>0
labels0 = labels;
dist = pdist2(data, centers);
[~,labels] = min(dist,[],2);
d= sum(labels0 ~= labels);
for i=1:k
centers(i,:)=mean(data(labels == i,:),1);
end
end
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询