- Linkage: https://www.mathworks.com/help/stats/linkage.html
- Cluster: https://www.mathworks.com/help/stats/cluster.html
Find number of clusters remaining after doing agglomerative hierarchical clustering
2 次查看(过去 30 天)
显示 更早的评论
I used agglomerative hierarchical clustering and stopeed clutering by giving a cutoff value. now I need to get the number of clusters in that particular image in order to proceed. Can someone help me?
0 个评论
回答(1 个)
Mann Baidi
2024-4-29
I am assuming that you would like to get the number of clusters present in the data after using cutoff value in the agglomerative hierarchical clustering in MATLAB.
You can check the number of clusters in the data by using the code below for reference.
% Sample data
rng default;
data = randn(50, 2);
% Perform hierarchical clustering
Z = linkage(data, 'ward'); % 'ward' linkage method is used here, but other methods are available
idx = cluster(Z,'cutoff',0.4)
histogram(idx) % Plot histogram for the idx
figure;
% Plot data points colored by cluster
gscatter(data(:,1), data(:,2), idx);
hold on;
legend('off')
% Count the number of clusters
num_clusters = max(idx);
fprintf('Number of clusters: %d\n', num_clusters);
If you would like to know more about these functions we can go throught their documentation, using the following link.
Hoping this will help in resloving your query!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!