Example
Compare Cluster Assignments to Clusters
Import the sample data.
Load Fisheriris
From the Anderson Iris Floral Data set, the ward linkage calculates four clusters and ignores the type information.
Z = Linkage (MEAs, ' Ward ', ' Euclidean ');
c = Cluster (Z, ' Maxclust ', 4);
The relationship between cluster results and three species was observed.
Crosstab (c,species)
Print the first 5 lines of Z.
firstfive = Z (1:5,:)
Generates a system tree graph of Z.
Dendrogram (Z)
Clustering the data and plotting the results
Randomly generate sample data for 20,000 observation points.
RNG (' default ')% for reproducibility
X = rand (20000,3);
Use Ward's linkage to generate a hierarchical tree.
Z = Linkage (X, ' Ward ', ' Euclidean ', ' savememory ', ' on ');
If you set savememory to ' off ', you will receive a memory overflow error if your computer does not have enough memory to hold the distance matrix.
Cluster data into 4 groups and print the results.
c = Cluster (Z, ' Maxclust ', 4);
Scatter3 (X (:, 1), X (:, 2), X (:, 3), 10,c)
Help documentation-Translation-statistics toolbox-exploratory Data analysis-cluster analysis-hierarchical Clustering (linkage) (6)