Рассмотрим следующий пример иерархической кластеризации , примененной к набору данных Fisher Iris (150 экземпляров, каждая точка 4-мерная):
%# load dataset
load fisheriris
%# Construct agglomerative clusters
NUM = 3;
D = pdist(meas, 'euclid');
T = linkage(D, 'ward');
IDX = cluster(T, 'maxclust',NUM);
%# visualize the hierarchy of clusters
figure
h = dendrogram(T, 0, 'colorthreshold',mean(T(end-NUM+1:end-NUM+2,3)));
set(h, 'LineWidth',2)
set(gca, 'XTickLabel',[], 'TickLength',[0 0])
%# plot scatter of data colored by clusters
figure
scatter3(meas(:,1),meas(:,2),meas(:,3), 100, IDX, 'filled')
xlabel SL, ylabel SW, zlabel PL
![scatter](https://i.stack.imgur.com/n1aic.png)