-1
在MATLAB中我们如何找出k-均值聚类中每个聚类的质心。数据在本质上是非常不同的。因此,我想写一些MATLAB代码来绘制每个簇的质心,并给出每个质心的坐标。 我用下面的代码clustering-MATLAB中的k均值聚类代码
figure
plot(X(:,1),X(:,2),'.')
opts=statset('Display','final')
[idx,c]=kmeans(x,4,'Distance','cityblock,...
'Replicates',5,'Options',opts)
figure
plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',12)
hold on
plot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',12)
hold on
plot(X(idx==3,1),X(idx==3,2),'g.','MarkerSize',12)
hold on
plot(X(idx==4,1),X(idx==4,2),'y.','MarkerSize',12)
hold on
plot(C(:,1),C(:,2),'Kx',...
'MarkerSize',15,'LineWidth',3)
legend('Cluster 1','Cluster 2','Cluster 3','Cluster 4','Centroids',...
'Location','NW')
title 'Cluster Assignments and centroids '
hold off
你的代码有什么问题?你需要什么样的帮助? – Anton
请不要一再提出同样的问题! –
请更新您的原始问题而不是创建新问题。改进它,你可能会收到答案。 [问] – Daniel