Cluster analysis, or clustering, is a data analysis technique aimed at partitioning a set of objects into groups such that objects within the same group (called a cluster) exhibit greater similarity to one another (in some specific sense defined by the analyst) than to those in other groups (clusters). It is a main task of exploratory data analysis, and a common technique for statistical data analysis, used in many fields, including pattern recognition, image analysis, information retrieval, bioinformatics, data compression, computer graphics and machine learning.

Cluster analysis refers to a family of algorithms and tasks rather than one specific algorithm. It can be achieved by various algorithms that differ significantly in their understanding of what constitutes a cluster and how to efficiently find them. Popular notions of clusters include groups with small distances between cluster members, dense areas of the data space, intervals or particular statistical distributions. Clustering can therefore be formulated as a multi-objective optimization problem. The appropriate clustering algorithm and parameter settings (including parameters such as the distance function to use, a density threshold or the number of expected clusters) depend on the individual data set and intended use of the results. Cluster analysis as such is not an automatic task, but an iterative process of knowledge discovery or interactive multi-objective optimization that involves trial and failure. It is often necessary to modify data preprocessing and model parameters until the result achieves the desired properties.

Besides the term clustering, there are a number of terms with similar meanings, including automatic classification, numerical taxonomy, botryology (from ), typological analysis, and community detection. The subtle differences are often in the use of the results: while in data mining, the resulting groups are the matter of interest, in automatic classification the resulting discriminative power is of interest.

Cluster analysis originated in anthropology by Driver and Kroeber in 1932 and introduced to psychology by Joseph Zubin in 1938 and Robert Tryon in 1939 and famously used by Cattell beginning in 1943 for trait theory classification in personality psychology.

Definition

The notion of a "cluster" cannot be precisely defined, which is one of the reasons why there are so many clustering algorithms. There is a common denominator: a group of data objects. However, different researchers employ different cluster models, and for each of these cluster models again different algorithms can be given. The notion of a cluster, as found by different algorithms, varies significantly in its properties. Understanding these "cluster models" is key to understanding the differences between the various algorithms. Typical cluster models include: s: for example, hierarchical clustering builds models based on distance connectivity. s: for example, the k-means algorithm represents each cluster by a single mean vector. s: clusters are modeled using statistical distributions, such as multivariate normal distributions used by the expectation-maximization algorithm. s: for example, DBSCAN, OPTICS and HDBSCAN defines clusters as connected dense regions in the data space. s: in biclustering (also known as co-clustering or two-mode-clustering), clusters are modeled with both cluster members and relevant attributes. s: some algorithms do not provide a refined model for their results and just provide the grouping information. s: a clique, that is, a subset of nodes in a graph such that every two nodes in the subset are connected by an edge can be considered as a prototypical form of cluster. Relaxations of the complete connectivity requirement (a fraction of the edges can be missing) are known as quasi-cliques, as in the HCS clustering algorithm. Signed graph models: Every path in a signed graph has a sign from the product of the signs on the edges. Under the assumptions of balance theory, edges may change sign and result in a bifurcated graph. The weaker "clusterability axiom" (no cycle has exactly one negative edge) yields results with more than two clusters, or subgraphs with only positive edges.James A. Davis (May 1967) "Clustering and structural balance in graphs", Human Relations 20:181–7 s: the most well-known unsupervised neural network is the self-organizing map and these models can usually be characterized as similar to one or more of the above models, and including subspace models when neural networks implement a form of Principal Component Analysis or Independent Component Analysis.

A "clustering" is essentially a set of such clusters, usually containing all objects in the data set. Additionally, it may specify the relationship of the clusters to each other, for example, a hierarchy of clusters embedded in each other. Clusterings can be roughly distinguished as: : each object belongs to a cluster or not (also: ): each object belongs to each cluster to a certain degree (for example, a likelihood of belonging to the cluster)

There are also finer distinctions possible, for example:

: each object belongs to exactly one cluster : objects can also belong to no cluster; in which case they are considered outliers (also: alternative clustering, multi-view clustering): objects may belong to more than one cluster; usually involving hard clusters : objects that belong to a child cluster also belong to the parent cluster : while an overlapping clustering, within a uniquely defined subspace, clusters are not expected to overlap

Algorithms

As listed above, clustering algorithms can be categorized based on their cluster model. The following overview will only list the most prominent examples of clustering algorithms, as there are possibly over 100 published clustering algorithms. Not all provide models for their clusters and can thus not easily be categorized. An overview of algorithms explained in Wikipedia can be found in the list of statistics algorithms.

There is no objectively "correct" clustering algorithm, but as it was noted, "clustering is in the eye of the beholder." In fact, an axiomatic approach to clustering demonstrates that it is impossible for any clustering method to meet three fundamental properties simultaneously: scale invariance (results remain unchanged under proportional scaling of distances), richness (all possible partitions of the data can be achieved), and consistency between distances and the clustering structure. The most appropriate clustering algorithm for a particular problem often needs to be chosen experimentally, unless there is a mathematical reason to prefer one cluster model over another. An algorithm that is designed for one kind of model will generally fail on a data set that contains a radically different kind of model. For example, k-means cannot find non-convex clusters. Most traditional clustering methods assume the clusters exhibit a spherical, elliptical or convex shape.

Connectivity-based clustering (hierarchical clustering)

Connectivity-based clustering, also known as hierarchical clustering, is based on the idea that objects are more related to nearby objects than to those farther away. These algorithms form clusters by connecting objects based on their distance. A cluster can be understood in terms of the maximum distance required to connect its elements.

At different distance thresholds, different cluster groupings appear. These groupings can be visualized using a dendrogram, a tree-like diagram that shows how clusters merge as the distance increases. This explains the term "hierarchical clustering": instead of producing a single partition of the data set, the algorithm builds a hierarchy of clusters that merge at different distances. In a dendrogram, the y-axis shows the distance at which clusters merge, while the x-axis arranges objects so that clusters appear as continuous branches.

Connectivity-based clustering is a family of methods that differ in how distances between clusters are computed. In addition to choosing a distance function, the user must also select a linkage criterion, which determines how the distance between clusters is calculated. Common linkage criteria include single-linkage clustering (minimum distance between points), complete linkage clustering (maximum distance), and UPGMA or WPGMA (average linkage based on mean distances). Hierarchical clustering can be either agglomerative (starting with individual elements and merging them) or divisive (starting with the full data set and splitting it).

In agglomerative hierarchical clustering, the algorithm typically proceeds as follows: Start with each data point as its own cluster. Identify the two closest clusters based on a chosen distance measure. Merge them into a single cluster. Recalculate distances between the new cluster and the remaining clusters using the selected linkage criterion. Repeat until all data points are merged into a single cluster.

This process produces a full hierarchy of possible clusterings rather than a single final result. A specific clustering can be obtained by selecting a cut level in the dendrogram, which determines how many clusters are formed.

These methods do not produce a unique partitioning of the data set, but rather a hierarchy from which the user must choose appropriate clusters. They are also sensitive to outliers, which may appear as separate clusters or cause other clusters to merge. This effect, especially in single-linkage clustering, is known as the "chaining phenomenon". In the general case, the complexity is for agglomerative clustering and for divisive clustering, which makes them computationally expensive for large data sets. For some special cases, more efficient methods (with complexity ) are known, such as SLINK for single-linkage and CLINK for complete-linkage clustering.

Centroid-based clustering

In centroid-based clustering, each cluster is represented by a central vector, which is not necessarily a member of the data set. When the number of clusters is fixed to k, k-means clustering gives a formal definition as an optimization problem: find the k cluster centers and assign the objects to the nearest cluster center, such that the squared distances from the cluster are minimized.

The optimization problem itself is known to be NP-hard, and thus the common approach is to search only for approximate solutions. A particularly well-known approximate method is Lloyd's algorithm, often just referred to as "k-means algorithm" (although another algorithm introduced this name). It does however only find a local optimum, and is commonly run multiple times with different random initializations. Variations of k-means often include such optimizations as choosing the best of multiple runs, but also restricting the centroids to members of the data set (k-medoids), choosing medians (k-medians clustering), choosing the initial centers less randomly (k-means++) or allowing a fuzzy cluster assignment (fuzzy c-means).

Most k-means-type algorithms require the number of clusters – k – to be specified in advance, which is considered to be one of the biggest drawbacks of these algorithms. Furthermore, the algorithms prefer clusters of approximately similar size, as they will always assign an object to the nearest centroid; often yielding improperly cut borders of clusters. This happens primarily because the algorithm optimizes cluster centers, not cluster borders. Steps involved in the centroid-based clustering algorithm are:

Choose, k distinct clusters at random. These are the initial centroids to be improved upon. Suppose a set of observations, . Assign each observation to the centroid to which it has the smallest squared Euclidean distance. This results in k distinct groups, each containing unique observations. Recalculate centroids (see k-means clustering).