在用matlab搞AP算法时最后的图呈现这种情况
有没有知道这是怎么回事呀/(ㄒoㄒ)/~~
是不是我的数据不好呀/(ㄒoㄒ)/~~
感谢感谢🙏
以下是我的代码,希望指正
D = pdist2(locations, locations, 'euclidean');
S = -D;
preference = median(S(:));
[idx, netsim, dpsim, expref] = apcluster(S, preference);
k = numel(unique(idx));
cluster_centers = [];
for i = 1:k
cluster_points = locations(idx == i, :);
center = mean(cluster_points, 1);
cluster_centers = [cluster_centers; center];
end
disp(['实际聚类数量: ', num2str(k)]);
disp('聚类中心坐标:');
disp(cluster_centers);
figure;
hold on;
gscatter(locations(:,1), locations(:,2), idx, 'rgb', 'o', 8);
plot(cluster_centers(:,1), cluster_centers(:,2), 'k*', 'MarkerSize', 10, 'LineWidth', 2);
for i = 1:k
cluster_points = locations(idx == i, :);
center = cluster_centers(i, :);
for j = 1:size(cluster_points, 1)
plot([cluster_points(j,1), center(1)], [cluster_points(j,2), center(2)], 'k--', 'LineWidth', 0.75);
end
end
xlabel('经度');
ylabel('纬度');
title(['AP 聚类结果,聚类数量 k = ', num2str(k)]);
legend('Cluster 1', 'Cluster 2', 'Cluster 3', 'Cluster Centers', 'Location', 'Best');
hold off;
