Data Mining: cluster analysis Instructor: Dr. Chun Yu School of Statistics Jiangxi University of Finance and Economics
What is Cluster Analysis? Finding groups of objects such that the objects in a group will be similar (or related) to one another and different from (or unrelated to) the objects in other groups Inter-cluster distances are maximized Intra-cluster distances are minimized
Applications of Cluster Analysis Understanding Group related documents for browsing, group genes and proteins that have similar functionality, or group stocks with similar price fluctuations Summarization Reduce the size of large data sets Clustering precipitation in Australia
Supervised Classification and Unsupervised Classification Cluster analysis is related to other techniques that are used to divide data objects into groups. Supervised classification Classification New, unlabeled objects are assigned a class label using a model developed from objects with known class label Unsupervised classification Cluster analysis
Notion of a Cluster can be Ambiguous How many clusters? Six Clusters Two Clusters Four Clusters
Types of Clusterings A clustering is a set of clusters Important distinction between hierarchical and partitional sets of clusters Partitional Clustering A division data objects into non-overlapping subsets (clusters) such that each data object is in exactly one subset Hierarchical clustering A set of nested clusters organized as a hierarchical tree
Partitional Clustering A Partitional Clustering Original Points
Hierarchical Clustering
Other Distinctions Between Sets of Clusters Exclusive versus non-exclusive In non-exclusive clusterings, points may belong to multiple clusters. Can represent multiple classes Fuzzy versus non-fuzzy In fuzzy clustering, a point belongs to every cluster with some weight between 0 and 1 Weights must sum to 1 Partial versus complete In some cases, we only want to cluster some of the data
Types of Clusters Well-separated clusters Center-based clusters Contiguous clusters Density-based clusters Shared-Property or Conceptual
Types of Clusters: Well-Separated Well-Separated Clusters: A cluster is a set of points such that any point in a cluster is closer (or more similar) to every other point in the cluster than to any point not in the cluster. 3 well-separated clusters
Types of Clusters: Center-Based A cluster is a set of objects such that an object in a cluster is closer (more similar) to the “center” of a cluster, than to the center of any other cluster The center of a cluster is often a centroid, the average of all the points in the cluster, or a medoid, the most “representative” point of a cluster 4 center-based clusters
Types of Clusters: Contiguity-Based Contiguous Cluster (Nearest neighbor or Transitive) A cluster is a set of points such that a point in a cluster is closer (or more similar) to one or more other points in the cluster than to any point not in the cluster. 8 contiguous clusters
Types of Clusters: Density-Based A cluster is a dense region of points, which is separated by low-density regions, from other regions of high density. Used when the clusters are irregular or intertwinded, and when noise and outliers are present. 6 density-based clusters
Types of Clusters: Conceptual Clusters Shared Property or Conceptual Clusters Finds clusters that share some common property or represent a particular concept. 2 Overlapping Circles
Clustering Algorithms K-means and its variants Hierarchical clustering Density-based clustering
K-means Clustering Partitional clustering approach Each cluster is associated with a centroid (center point) Each point is assigned to the cluster with the closest centroid Number of clusters, K, must be specified The basic algorithm is very simple
Using K-Means Algorithm to Find 3 Clusters
K-means Clustering – Details Initial centroids are often chosen randomly. Clusters produced vary from one run to another. The centroid is (typically) the mean of the points in the cluster. ‘Closeness’ is measured by Euclidean distance, cosine similarity, correlation, etc. K-means will converge for common similarity measures mentioned above. Most of the convergence happens in the first few iterations.
Evaluating K-means Clusters Most common measure is Sum of Squared Error (SSE) For each point, the error is the distance to the nearest cluster To get SSE, we square these errors and sum them. x is a data point in cluster Ci and ci is the centroid for cluster Ci dist is the standard Euclidean (L2) distance between two objects
Table of Notation Symbol Description x Ci ci c mi m K An object The ith cluster The centroid of the ith cluster The centroid of all points The number of objects in the ith cluster The number of object in the data set The number of clusters
The Centroid of a cluster It can be shown that the centroid that minimizes the SSE of the cluster is the mean The centroid (mean) of the ith cluster is defined by the equation below: 𝑐 𝑖 = 1 𝑚 𝑖 𝑥∈ 𝐶 𝑖 𝑥 For example, a cluster contains three two-dimensional points: (1,1), (2,3) and (6,2), the centroid of the cluster is: ((1+2+6)/3, (1+3+2)/3) = (3,2)
Two different K-means Clusterings Original Points Optimal Clustering Sub-optimal Clustering
Importance of Choosing Initial Centroids
Importance of Choosing Initial Centroids …
Solutions to Initial Centroids Problem Multiple runs Helps, but probability is not on your side Sample and use hierarchical clustering to determine initial centroids Select more than k initial centroids and then select among these initial centroids Select most widely separated Postprocessing Bisecting K-means
Handling Empty Clusters Basic K-means algorithm can yield empty clusters Several strategies Choose the point that contributes most to SSE Choose a point from the cluster with the highest SSE If there are several empty clusters, the above can be repeated several times.
Pre-processing and Post-processing Normalize the data Eliminate outliers Post-processing Eliminate small clusters that may represent outliers Split ‘loose’ clusters, i.e., clusters with relatively high SSE Merge clusters that are ‘close’ and that have relatively low SSE
Bisecting K-means Bisecting K-means algorithm Variant of K-means that can produce a partitional or a hierarchical clustering
Bisecting K-means Example
Limitations of K-means K-means has problems when clusters are of differing Sizes Densities Non-globular shapes K-means has problems when the data contains outliers.
Limitations of K-means: Differing Sizes Original Points K-means (3 Clusters)
Limitations of K-means: Differing Density Original Points K-means (3 Clusters)
Limitations of K-means: Non-globular Shapes Original Points K-means (2 Clusters)
Hierarchical Clustering Produces a set of nested clusters organized as a hierarchical tree Can be visualized as a dendrogram A tree like diagram that records the sequences of merges or splits
Strengths of Hierarchical Clustering Do not have to assume any particular number of clusters Any desired number of clusters can be obtained by ‘cutting’ the dendogram at the proper level They may correspond to meaningful taxonomies Example in biological sciences (e.g., animal kingdom, entomological taxonomy, …)
Hierarchical Clustering Two main types of hierarchical clustering Agglomerative: Start with the points as individual clusters At each step, merge the closest pair of clusters until only one cluster (or k clusters) left Divisive: Start with one, all-inclusive cluster At each step, split a cluster until each cluster contains a point (or there are k clusters) Traditional hierarchical algorithms use a similarity or distance matrix Merge or split one cluster at a time
Agglomerative Clustering Algorithm More popular hierarchical clustering technique Basic algorithm is straightforward Compute the proximity matrix Let each data point be a cluster Repeat Merge the two closest clusters Update the proximity matrix Until only a single cluster remains Key operation is the computation of the proximity of two clusters Different approaches to defining the distance between clusters distinguish the different algorithms
How to Define Inter-Cluster Similarity p1 p3 p5 p4 p2 . . . . Similarity? MIN MAX Group Average Distance Between Centroids Other methods driven by an objective function Ward’s Method uses squared error Proximity Matrix
How to Define Inter-Cluster Similarity p1 p3 p5 p4 p2 . . . . MIN MAX Group Average Distance Between Centroids Other methods driven by an objective function Ward’s Method uses squared error Proximity Matrix
How to Define Inter-Cluster Similarity p1 p3 p5 p4 p2 . . . . MIN MAX Group Average Distance Between Centroids Other methods driven by an objective function Ward’s Method uses squared error Proximity Matrix
How to Define Inter-Cluster Similarity p1 p3 p5 p4 p2 . . . . MIN MAX Group Average Distance Between Centroids Other methods driven by an objective function Ward’s Method uses squared error Proximity Matrix
How to Define Inter-Cluster Similarity p1 p3 p5 p4 p2 . . . . MIN MAX Group Average Distance Between Centroids Other methods driven by an objective function Ward’s Method uses squared error Proximity Matrix
Specific Techniques Sample data
Sample data: Euclidean Distance Matrix
Cluster Similarity: MIN or Single Link Similarity of two clusters is based on the two most similar (closest) points in the different clusters The proximity of two clusters is defined as the minimum of the distance (maximum of the similarity) Dendrogram: if you start with all points as singleton clusters and add links between points one at a time, shortest links first, then these single links combine the points into clusters
Hierarchical Clustering: MIN Points 6 and 3 are merged first, then points 5 and 2 The distance between clusters {3,6} and {2,5} is given by dist({3,6},{2,5}) = min(dist(3,2),dist(6,2),dist(3,5),dist(6,5)) = min(0.15,0.25,0.28,0.39) = 0.15
Hierarchical Clustering: MIN 5 1 2 3 4 5 6 4 3 2 1 Nested Clusters Dendrogram
Strength of MIN Two Clusters Original Points Can handle non-elliptical shapes
Limitations of MIN Two Clusters Original Points Sensitive to noise and outliers
Cluster Similarity: MAX or Complete Linkage Similarity of two clusters is based on the two least similar (most distant) points in the different clusters Dendrogram: we start with all points as singleton clusters and add links between points one at a time, shortest links first, then a group of points is not a cluster until all the points in it are completely linked
Hierarchical Clustering: MAX As with single link, points 6 and 3 are merged first. However, {3,6} is merged with {4}, instead of {2,5} or {1} dist({3,6},{4}) = max(dist(3,4),dist(6,4)) = max(0.15,0.22) = 0.22
Hierarchical Clustering: MAX dist({3,6},{2,5}) = max(dist(3,2),dist(6,2),dist(3,5),dist(6,5)) = max(0.15,0.25,0.28,0.39) = 0.39 dist({3,6},{1}) = max(dist(3,1),dist(6,1)) = max(0.22,0.23) = 0.23
Hierarchical Clustering: MAX 5 4 1 2 3 4 5 6 2 3 1 Nested Clusters Dendrogram
Strength of MAX Two Clusters Original Points Less susceptible to noise and outliers
Limitations of MAX Two Clusters Original Points Tends to break large clusters
Cluster Similarity: Group Average Proximity of two clusters is the average of pairwise proximity between points in the two clusters. dist({3,6,4},{1}) = (0.22+0.37+0.23)/(3*1) = 0.28 dist({2,5},{1}) =(0.24+0.34)/(2*1) =0.29
Cluster Similarity: Group Average dist({3,6,4},{2,5}) = (0.15+0.28+0.25+0.39+0.20+0.29)/(3*2) = 0.26 Because dist({3,6,4},{2,5}) is smaller than dist({3,6,4},{1}) and dist({2,5},{1}), clusters {3,6,4} and {2,5} are merged at the fourth stage
Hierarchical Clustering: Group Average 5 4 1 2 3 4 5 6 2 3 1 Nested Clusters Dendrogram
Hierarchical Clustering: Group Average Compromise between Single and Complete Link Strengths Less susceptible to noise and outliers Limitations Biased towards globular clusters
Cluster Similarity: Ward’s Method Similarity of two clusters is based on the increase in squared error when two clusters are merged Similar to group average if distance between points is distance squared Less susceptible to noise and outliers Biased towards globular clusters Hierarchical analogue of K-means Can be used to initialize K-means
Hierarchical Clustering: Comparison 5 5 1 2 3 4 5 6 4 4 1 2 3 4 5 6 3 2 2 1 MIN MAX 3 1 5 5 1 2 3 4 5 6 1 2 3 4 5 6 4 4 2 2 Ward’s Method 3 3 1 Group Average 1
Determining the correct number of clusters We can try to find the natural number of clusters in a data set by looking for the number of clusters at which there is a knee in the plot of the evaluation measure when it is plotted against the number of clusters.
Hierarchical Clustering: Problems and Limitations No objective function is directly minimized Different schemes have problems with one or more of the following: Sensitivity to noise and outliers Difficulty handling different sized clusters and convex shapes Breaking large clusters
DBSCAN DBSCAN is a density-based algorithm. Center-based density Density = number of points within a specified radius (Eps)
DBSCAN A point is a core point if it has more than a specified number of points (MinPts) within Eps These are points that are at the interior of a cluster A border point has fewer than MinPts within Eps, but is in the neighborhood of a core point A noise point is any point that is not a core point or a border point.
DBSCAN: Core, Border, and Noise Points
DBSCAN Algorithm Any two core points that are close enough (within a distance Eps of one another) are put in the same cluster Any border point that is close enough to a core point is put in the same cluster as the core point
DBSCAN: Determining EPS and MinPts Idea is that for points in a cluster, their kth nearest neighbors are at roughly the same distance (called k-dist) Noise points have the kth nearest neighbor at farther distance So, plot sorted distance of every point to its kth nearest neighbor
DBSCAN: Core, Border and Noise Points Original Points Point types: core, border and noise Eps = 10, MinPts = 4
When DBSCAN Works Well Original Points Clusters Resistant to Noise Can handle clusters of different shapes and sizes
When DBSCAN Does NOT Work Well Varying densities High-dimensional data
Thank you!