({{, (RefLink[ClusteringTree, paclet:ref/ClusteringTree])[{(Subscript[e, 1]),(Subscript[e, 2]),…}] 
constructs a weighted tree from the hierarchical clustering of the elements (Subscript[e, 1]), (Subscript[e, 2]), ….}, {, (RefLink[ClusteringTree, paclet:ref/ClusteringTree])[{(Subscript[e, 1])->(Subscript[v, 1]),(Subscript[e, 2])->(Subscript[v, 2]),…}]
represents (Subscript[e, i]) with (Subscript[v, i]) in the constructed graph.}, {, (RefLink[ClusteringTree, paclet:ref/ClusteringTree])[{(Subscript[e, 1]),(Subscript[e, 2]),…}->{(Subscript[v, 1]),(Subscript[v, 2]),…}]
represents (Subscript[e, i]) with (Subscript[v, i]) in the constructed graph.}, {, (RefLink[ClusteringTree, paclet:ref/ClusteringTree])[\[LeftAssociation](Subscript[label, 1])->(Subscript[e, 1]),(Subscript[label, 2])->(Subscript[e, 2…])\[RightAssociation]]
represents (Subscript[e, i]) using labels (Subscript[label, i]) in the constructed graph.}, {, (RefLink[ClusteringTree, paclet:ref/ClusteringTree])[data,h]
constructs a weighted tree from the hierarchical clustering of data by joining subclusters at distance less than h. }})

OpenersNotesSection(Spacer1)Details and Options

The data elements (Subscript[e, i]) can be numbers; numeric lists, matrices, or tensors; lists of Boolean elements; strings or images; geo positions or geographical entities; colors; as well as combinations of these. If the (Subscript[e, i]) are lists, matrices, or tensors, each must have the same dimensions.

The result from (RefLink[ClusteringTree, paclet:ref/ClusteringTree]) is a binary weighted tree, where the weight of each vertex indicates the distance between the two subtrees that have that vertex as root:

(RefLink[ClusteringTree, paclet:ref/ClusteringTree]) has the same options as (RefLink[Graph, paclet:ref/Graph]), with the following additions and changes:

By default, (RefLink[ClusteringTree, paclet:ref/ClusteringTree]) will preprocess the data automatically unless either a (RefLink[DistanceFunction, paclet:ref/DistanceFunction]) or a (RefLink[FeatureExtractor, paclet:ref/FeatureExtractor]) is specified.

(RefLink[ClusterDissimilarityFunction, paclet:ref/ClusterDissimilarityFunction]) defines the intercluster dissimilarity, given the dissimilarities between member elements.

Possible settings for (RefLink[ClusterDissimilarityFunction, paclet:ref/ClusterDissimilarityFunction]) include:

The function f defines a distance from any two clusters.

The function f needs to be a real-valued function of the (RefLink[DistanceMatrix, paclet:ref/DistanceMatrix]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (16)

OpenersExampleSection0(Spacer1)Basic Examples  (5)

Obtain a cluster hierarchy from a list of numbers:

ClusteringTree[{1,2,5}]

Unify clusters at distance less than 2:

ClusteringTree[{1,2,5}, 1.3]

Obtain a cluster hierarchy from a list of strings:

ClusteringTree[{"a", "abba", "ababa", "abcdefg"}]

Obtain a cluster hierarchy from a list of images:

ClusteringTree[{, , , }]

Obtain a cluster hierarchy from a list of cities:

ClusteringTree[{(Entity["Paris", Entity["City",{"Paris","IleDeFrance","France"}], "Entity[\"City\", {\"Paris\", \"IleDeFrance\", \"France\"}]", "city"]),(Entity["Sydney", Entity["City",{"Sydney","NewSouthWales","Australia"}], "Entity[\"City\", {\"Sydney\", \"NewSouthWales\", \"Australia\"}]", "city"]),(Entity["Boston", Entity["City",{"Boston","Massachusetts","UnitedStates"}], "Entity[\"City\", {\"Boston\", \"Massachusetts\", \"UnitedStates\"}]", "city"]),(Entity["San Francisco", Entity["City",{"SanFrancisco","California","UnitedStates"}], "Entity[\"City\", {\"SanFrancisco\", \"California\", \"UnitedStates\"}]", "city"])}]

Obtain a cluster hierarchy from a list of Boolean entries:

ClusteringTree[{{False, False}, {True, False}, {True, True}}]

OpenersExampleSection1(Spacer1)Scope  (8)

Obtain a cluster hierarchy from a list of numbers:

g = ClusteringTree[{0.1,2.2,3.4,5.6,8.9}]

Obtain the leaves' labels:

PropertyValue[g,"LeafLabels"]

Look at the distance between subclusters by looking at the (RefLink[VertexWeight, paclet:ref/VertexWeight]):

PropertyValue[g,VertexWeight]

Find the shortest path from the root vertex to the leaf 3.4:

FindShortestPath[g,1, 7 ]

Obtain a cluster hierarchy from a heterogeneous dataset:

data = {{, "brown"},{, "light blue"},{, "blue"},{, "violet"},{, "light blue"},{, "yellow"},{, "light violet"}};

ClusteringTree[data]

Compare it with the cluster hierarchy of the colors:

ClusteringTree[data[[All, 1]]]

Generate a list of random colors:

data = RandomColor[20]

Obtain a cluster hierarchy from the list using the "Centroid" linkage:

ClusteringTree[data, ClusterDissimilarityFunction->"Centroid"]

Compute the hierarchical clustering from an (RefLink[Association, paclet:ref/Association]):

association = <|"Red"->, "Blue"->, "Pink"->, "Yellow"->|>;

ClusteringTree[association]

Compare it with the hierarchical clustering of its (RefLink[Values, paclet:ref/Values]):

ClusteringTree[Values[association]]

Compare it with the hierarchical clustering of its (RefLink[Keys, paclet:ref/Keys]):

ClusteringTree[Keys[association]]

Obtain a cluster hierarchy by merging clusters at distance less than 0.4:

data = RandomColor[20]

ClusteringTree[data,0.4, ClusterDissimilarityFunction->"Centroid"]

Change the style and the layout of the (RefLink[ClusteringTree, paclet:ref/ClusteringTree]):

data = RandomInteger[{0, 100}, 50];

disk = Graphics[{GrayLevel[.45], Disk[]}]

ClusteringTree[data, VertexSize->0.2, VertexShape->disk]

ClusteringTree[data,GraphLayout->"RadialEmbedding"]

Obtain a cluster hierarchy from a list of three-dimensional vectors and label the leaves with the total of the corresponding element:

r = RandomReal[1, {7, 3}];

g = ClusteringTree[r->Total/@r]

Compare it with the cluster hierarchy of the total of each vector:

ClusteringTree[Total/@r]

Obtain a cluster hierarchy from a list of integers:

data = RandomSample[Range[3,10], 6];

g = ClusteringTree[data]

Change the vertex labels by using regular polygons:

labels = Graphics[{Blue, RegularPolygon[#]}, ImageSize->20]&/@data

g = ClusteringTree[data->labels]

OpenersExampleSection2(Spacer1)Options  (3)

OpenersExampleSubsection0(Spacer1)ClusterDissimilarityFunction  (1)

Generate a list of random colors:

data = RandomColor[80]

Obtain a cluster hierarchy from the list using the "Centroid" linkage:

ClusteringTree[data, ClusterDissimilarityFunction->"Centroid"]

Obtain a cluster hierarchy from the list using the "Single" linkage:

ClusteringTree[data, ClusterDissimilarityFunction->"Single"]

Obtain a cluster hierarchy from the list using a different "ClusterDissimilarityFunction":

ClusteringTree[data, ClusterDissimilarityFunction->(Max[#]&)]

OpenersExampleSubsection1(Spacer1)DistanceFunction  (1)

Generate a list of random vectors:

data =RandomReal[{10, 20}, {10, 2}];

Obtain a cluster hierarchy using different (RefLink[DistanceFunction, paclet:ref/DistanceFunction]):

ClusteringTree[data, DistanceFunction->ManhattanDistance]

ClusteringTree[data, DistanceFunction->ChessboardDistance]

OpenersExampleSubsection2(Spacer1)FeatureExtractor  (1)

Obtain a cluster hierarchy from a list of pictures:

flowers ={ ,,,,,,,,,, ,,,,,,,,};

ClusteringTree[flowers]

Use a different (RefLink[FeatureExtractor, paclet:ref/FeatureExtractor]) to extract features:

fe = FeatureExtraction[flowers, "ImageFeatures"]

ClusteringTree[flowers, FeatureExtractor->fe]

Use the (RefLink[Identity, paclet:ref/Identity]) (RefLink[FeatureExtractor, paclet:ref/FeatureExtractor]) to leave the data unchanged:

ClusteringTree[flowers, FeatureExtractor->Identity]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Dendrogram, paclet:ref/Dendrogram])  ▪  (RefLink[FindClusters, paclet:ref/FindClusters])  ▪  (RefLink[ClusteringComponents, paclet:ref/ClusteringComponents])  ▪  (RefLink[NearestNeighborGraph, paclet:ref/NearestNeighborGraph])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Graph Construction & Representation, paclet:guide/GraphConstructionAndRepresentation])}, {▪(RefLinkPlain[Cluster Analysis, paclet:guide/ClusterAnalysis])}, {▪(RefLinkPlain[Data Visualization, paclet:guide/DataVisualization])}, {▪(RefLinkPlain[Distance and Similarity Measures, paclet:guide/DistanceAndSimilarityMeasures])}, {▪(RefLinkPlain[Statistical Data Analysis, paclet:guide/Statistics])}, {▪(RefLinkPlain[Discrete Mathematics, paclet:guide/DiscreteMathematics])}, {▪(RefLinkPlain[Machine Learning, paclet:guide/MachineLearning])}, {▪(RefLinkPlain[Text Analysis, paclet:guide/TextAnalysis])}, {▪(RefLinkPlain[Sequence Alignment & Comparison, paclet:guide/SequenceAlignmentAndComparison])}})}})