agglomerative
Perform agglomerative hierarchical clustering
Calling Sequence
labels = agglomerative(x, n_clusters) labels = agglomerative(x, n_clusters, method) labels = agglomerative(x, n_clusters, method, metric)
Arguments
- x
A double observation matrix or a condensed distance vector or a linkage matrix returned by linkage.
If
xis a matrix, each row represents one observation and each column represents one feature.When
xis a condensed distance vector, it contains the pairwise distances between observations.When
xis a linkage matrixZ, it must be a matrix with three columns produced by the linkage function.- n_clusters
A positive integer specifying the number of clusters to obtain.
n_clustersmust be between1andn, the number of observations (number of rows ofx).- method
Linkage method. The default value is
"single"."single": minimum distance linkage."complete": maximum distance linkage."average": average linkage unweighted by cluster sizes (UPGMA)."weighted": weighted average linkage (WPGMA)."centroid": centroid method (UPGMC)."median": median method (WPGMC)."ward": Ward minimum variance linkage.
This argument is ignored when
xis already a linkage matrix.- metric
Metric used by pdist when
xis a matrix. Default value:"euclidean".A cell can be used to pass additional arguments to
pdist, for example, to set the Minkowski metric.The methods
"centroid","median"et"ward"require the Euclidean metric.This argument is ignored when
xis already a linkage matrix.- labels
A column vector containing the cluster label assigned to each observation.
Labels are integers ranging from
0ton_clusters - 1.
Description
agglomerative performs agglomerative hierarchical clustering.
Agglomerative clustering is a bottom-up hierarchical clustering method. Initially, each observation belongs to its own cluster. At each iteration, the two closest active clusters are merged. The process continues until the requested number of clusters is reached.
The function can be used directly with an observation matrix, a condensed distance vector, or with a linkage matrix returned by linkage.
When a linkage matrix is provided, no new distances or merges are
computed. The function uses the first
n - n_clusters merges stored in the linkage
hierarchy to reconstruct the requested partition.
Cluster labels are arbitrary identifiers. Two clustering results can represent the same partition even if their numerical labels are different.
For example: [0 0 1 1] and [1 1 0 0] represent the same clustering partition.
When n_clusters is equal to the number of
observations, each observation receives a different label.
When n_clusters is equal to
1, all observations belong to the same
cluster.
When a linkage matrix is supplied, the
method and metric
arguments are not used because the hierarchical clustering has
already been computed.
Examples
data = [0.0 0.0 0.2 0.1 -0.1 0.2 0.1 -0.2 5.0 5.0 5.2 5.1 4.9 5.2 5.1 4.8 10.0 0.0 10.2 0.1 9.9 -0.2 10.1 0.2]; labels = agglomerative(data, 3, "ward")
--> data = [0.0 0.0 > 0.2 0.1 > -0.1 0.2 > 0.1 -0.2 > 5.0 5.0 > 5.2 5.1 > 4.9 5.2 > 5.1 4.8 > 10.0 0.0 > 10.2 0.1 > 9.9 -0.2 > 10.1 0.2]; --> labels = agglomerative(data, 3, "ward") labels = [12x1 double] 1. 1. 1. 1. 2. 2. 2. 2. 0. 0. 0. 0.
See Also
- linkage — Agglomerative hierarchical clustering
- pdist — Pairwise distances between observations
- squareform — Conversion between a distance vector and a symmetric distance matrix
History
| Version | Description |
| 2027.0.0 | Function added. |
| Report an issue | ||
| << Hypothesis Testing | Statistics | dbscan >> |