Cluster analysis is a fundamental task in unsupervised learning: the goal is to group observations into clusters such that within-cluster similarity is high and between-cluster similarity is low. Unlike supervised methods, there are no labels to guide the process — the algorithm must discover structure in the data on its own.
Applications include:
The choice of distance metric fundamentally determines what "similar" means. Common measures include:
The most common distance in continuous spaces:
\[ d(\mathbf{x}, \mathbf{y}) = \sqrt{\sum_{i=1}^{p} (x_i - y_i)^2} \]
Sum of absolute differences along each dimension:
\[ d(\mathbf{x}, \mathbf{y}) = \sum_{i=1}^{p} |x_i - y_i| \]
A generalization of both Euclidean (\(q=2\)) and Manhattan (\(q=1\)):
\[ d(\mathbf{x}, \mathbf{y}) = \left( \sum_{i=1}^{p} |x_i - y_i|^q \right)^{1/q} \]
Measures the angle between two vectors, ignoring magnitude:
\[ \text{cos}(\mathbf{x}, \mathbf{y}) = \frac{\mathbf{x} \cdot \mathbf{y}}{\|\mathbf{x}\| \, \|\mathbf{y}\|} = \frac{\sum_{i=1}^p x_i y_i}{\sqrt{\sum_{i=1}^p x_i^2} \sqrt{\sum_{i=1}^p y_i^2}} \]
The cosine distance is then \(1 - \text{cos}(\mathbf{x}, \mathbf{y})\).
\[ d(\mathbf{x}, \mathbf{y}) = 1 - \text{corr}(\mathbf{x}, \mathbf{y}) \]
Useful when the pattern of variation matters more than absolute values.
The choice of distance depends on data type and scale. When features have different units or scales, standardization (e.g. z-score normalization) is critical — otherwise features with larger ranges will dominate the distance computation.
K-Means partitions \(n\) observations into \(K\) clusters by iterating:
K-Means minimizes the total within-cluster sum of squares:
\[ W(C) = \sum_{k=1}^{K} \sum_{\mathbf{x} \in C_k} \|\mathbf{x} - \boldsymbol{\mu}_k\|^2 \]
where \(\boldsymbol{\mu}_k = \frac{1}{|C_k|}\sum_{\mathbf{x} \in C_k} \mathbf{x}\) is the centroid of cluster \(C_k\).
Start with \(n\) clusters (one per observation). At each step, merge the two closest clusters. Repeat until a single cluster remains.
Start with one cluster containing all observations. At each step, split a cluster into two. Less common in practice.
The definition of "distance between clusters" varies by linkage:
A tree diagram representing the nested sequence of merges. The height at which two clusters merge reflects the dissimilarity between them. Cut the dendrogram at a desired height to obtain \(K\) clusters.
Density-Based Spatial Clustering of Applications with Noise.
For each observation \(i\):
\[ s(i) = \frac{b(i) - a(i)}{\max\{a(i),\, b(i)\}} \]
where:
Range: \([-1, 1]\). Values near 1 indicate well-clustered points; near 0 means on the boundary; negative values suggest misclassification.