Cluster Analysis
What is Cluster Analysis? Finding groups of objects (data points) 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 Intra-cluster distances are minimized Inter-cluster distances are maximized
Applications of Cluster Analysis 1. Clustering for Understanding Group related documents for browsing Group genes and proteins that have similar functionality Group stocks with similar price fluctuations Segment customers into a small number of groups for additional analysis and marketing activities. 1 2 3 4 Discovered Clusters Applied-Matl-DOWN,Bay-Network-Down,3-COM-DOWN, Cabletron-Sys-DOWN,CISCO-DOWN,HP-DOWN, DSC-Comm-DOWN,INTEL-DOWN,LSI-Logic-DOWN, Micron-Tech-DOWN,Texas-Inst-Down,Tellabs-Inc-Down, Natl-Semiconduct-DOWN,Oracl-DOWN,SGI-DOWN, Sun-DOWN Apple-Comp-DOWN,Autodesk-DOWN,DEC-DOWN, ADV-Micro-Device-DOWN,Andrew-Corp-DOWN, Computer-Assoc-DOWN,Circuit-City-DOWN, Compaq-DOWN, EMC-Corp-DOWN, Gen-Inst-DOWN, Motorola-DOWN,Microsoft-DOWN,Scientific-Atl-DOWN Fannie-Mae-DOWN,Fed-Home-Loan-DOWN, MBNA-Corp-DOWN,Morgan-Stanley-DOWN Baker-Hughes-UP,Dresser-Inds-UP,Halliburton-HLD-UP, Louisiana-Land-UP,Phillips-Petro-UP,Unocal-UP, 4 Schlumberger-UP Industry Group Technology1-DOWN Technology2-DOWN Financial-DOWN Oil-UP 2. Clustering for Summarization Reduce the size of large data sets Clustering precipitation in Australia
Similarity Similarity and Dissimilarity Numerical measure of how alike two data objects are. Higher when objects are more alike. Dissimilarity Numerical measure of how different are two data objects Lower when objects are more alike Proximity measures for objects with a number of attributes are defined by combining the proximities of individual attributes.
Similarity/Dissimilarity for Simple Attributes p and q are the attribute values for two data objects. Nominal E.g. province attribute of an address with values: {BC, AB, ON, QC, } Order not important. Dissimilarity d(p, q) = 0 if p = q d(p, q) = 1 if p q
Similarity/Dissimilarity for Simple Attributes p and q are the attribute values for two data objects. Ordinal E.g. quality attribute of a product with values: {poor, fair, OK, good, wonderful} Order is important, but exact difference between values is undefined or not important. Map the values of the attribute to successive integers {poor=0, fair=1, OK=2, good=3, wonderful=4} Dissimilarity d(p, q) = p q / (max_d min_d) e.g. d(wonderful, fair) = 4-1 / (4-0) =.75
Similarity/Dissimilarity for Simple Attributes p and q are the attribute values for two data objects. Continuous (or Interval) E.g. weight attribute of a product Dissimilarity d(p, q) = p q
Combining dissimilarities Sometimes attributes are of many different types, but an overall similarity/dissimilarity is needed. For each attribute (1 i m), compute a dissimilarity d i in the range [0,1]. Then, for two data points x and x : dissimilarity( x, x') m i = = 1 m d i
Euclidean Distance When all the attributes are continuous we can use the Euclidean Distance dist( x, x') = m i= 1 ( x i x' i 2 ) Where m is the number of dimensions (attributes) and x i and x i are, respectively, the i th attributes of data objects x and x. Standardization is necessary, if scales of attribute values differ E.g. weight, salary have different scales
Euclidean Distance 3 2 1 0 p1 point x1 x2 p3 p4 p1 0 2 p2 2 0 p2 p3 3 1 0 1 2 3 4 5 6 p4 5 1 p1 p2 p3 p4 p1 0 2.828 3.162 5.099 p2 2.828 0 1.414 3.162 p3 3.162 1.414 0 2 p4 5.099 3.162 2 0 Distance Matrix
Minkowski Distance Minkowski Distance is a generalization of Euclidean Distance m dist( x, x') = r x i x' i i= 1 r Where r is a parameter, m is the number of dimensions (attributes) and x i and x i are, respectively, the ith attributes of data objects x and x. Examples r = 1 : City block (Manhattan, taxicab, L 1 norm) distance. r = 2 : Euclidean distance r. supremum (L max norm, L norm) distance. This is the maximum difference among all dimensions of the vectors.
Minkowski Distance 3 2 1 0 point x1 x2 p1 0 2 p2 2 0 p3 3 1 p4 5 1 p1 p2 p3 p4 0 1 2 3 4 5 6 L1 p1 p2 p3 p4 p1 0 4 4 6 p2 4 0 2 4 p3 4 2 0 2 p4 6 4 2 0 L2 p1 p2 p3 p4 p1 0 2.828 3.162 5.099 p2 2.828 0 1.414 3.162 p3 3.162 1.414 0 2 p4 5.099 3.162 2 0 L p1 p2 p3 p4 p1 0 2 3 5 p2 2 0 1 3 p3 3 1 0 2 p4 5 3 2 0 Distance Matrix
Similarity Between Binary Vectors Common situation is that objects, x and x, have only binary attributes Compute similarities using the following quantities M 01 = the number of attributes where x was 0 and x was 1 M 10 = the number of attributes where x was 1 and x was 0 M 00 = the number of attributes where x was 0 and x was 0 M 11 = the number of attributes where x was 1 and x was 1 Simple Matching SMC = (M 11 + M 00 ) / (M 01 + M 10 + M 11 + M 00 ) = number of matches / number of attributes Jaccard Coefficients JC = (M 11 ) / (M 01 + M 10 + M 11 ) = number of M 11 matches / number of not-both-zero attributes
SMC versus Jaccard: Example x = 1 0 0 0 0 0 0 0 0 0 x' = 0 0 0 0 0 0 1 0 0 1 M 01 = 2 (the number of attributes where x was 0 and x was 1) M 10 = 1 (the number of attributes where x was 1 and x was 0) M 00 = 7 (the number of attributes where x was 0 and x was 0) M 11 = 0 (the number of attributes where x was 1 and x was 1) 11 SMC = (M 11 + M 00 )/(M 01 + M 10 + M 11 + M 00 ) = (0+7) / (2+1+0+7) = 0.7 JC= (M 11 ) / (M 01 + M 10 + M 11 ) = 0 / (2 + 1 + 0) = 0
Cosine Similarity If D 1 and D 2 are two document vectors, then cos(d 1, D 2 ) = (D 1 D 2 ) / D 1. D 2 where indicates vector dot product and D is the length of vector D. Example: D 1 D 2 =.4*0 +.33*0 + 0*.33 + 0*1 +.17*.33 =.0561 D 1 = sqrt(.40 2 +.33 2 +.17 2 ) =.55 D 2 = sqrt(.33 2 + 1 2 +.33 2 ) = 1.1 TID W1 W2 W3 W4 W5 D1 0.40 0.33 0.00 0.00 0.17 D2 0.00 0.00 0.33 1.00 0.33 D3 0.40 0.50 0.00 0.00 0.00 D4 0.00 0.00 0.33 0.00 0.17 D5 0.20 0.17 0.33 0.00 0.33 If the cosine similarity is 1, the angle between D 1 and D 2 is 0 o, and D 1 and D 2 are the same except for the magnitude. If the cosine similarity is 0, then the angle between D 1 and D 2 is 90 o, and they don t share any terms (words). cos( D 1, D 2 ) =.0561 / (.55 * 1.1) =.093
Types of Clusters: Well-Separated 1. Well-Separated Clusters: 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 2. Center-based An object in a cluster is closer (more similar) to the center of the 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 (for continuous attributes), or a medoid, the most representative point of a cluster (for discrete attributes ) 4 center-based clusters
Types of Clusters: Contiguity-Based 3. Contiguous Cluster (Nearest neighbor or Transitive) 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 4. Density-based A cluster is a dense region of points, which is separated, by lowdensity regions, from other regions of high density. Used when the clusters are irregular or intertwined, and when noise and outliers are present. 6 density-based clusters
K-means Clustering Algorithm: Each cluster is associated with a centroid (center point) Each point is assigned to the cluster with the closest centroid Centroids are recomputed Number of clusters, K, must be specified Basic algorithm is very simple
Example 3 Iteration 12 34 56 2.5 2 1.5 y 1 0.5 0-2 -1.5-1 -0.5 0 0.5 1 1.5 2 x
K-means Clustering Details Initial centroids may be chosen randomly. Clusters produced vary from one run to another. Rerun several times and pick the clustering with the smallest SSE (see next slide). The centroid is (typically) the mean of the points in the cluster. Closeness is measured by Euclidean distance, cosine similarity, etc. Most of the convergence happens in the first few iterations. Often the stopping condition is changed to Until relatively few points change clusters
Evaluating K-means Clusters Most common measure is Sum of Squared Error (SSE) For each data point, the error is the distance to the nearest centroid To get SSE, we square these errors and sum them up for K clusters. SSE K = = i= 1 x C i [ dist ( m, x )] i 2 x is a data point in cluster C i and m i is the representative point for cluster C i
Reducing SSE Obvious way to reduce the SSE is to find more clusters, i.e., to use a larger K. Try different K, looking at the change in the average distance to centroid, as K increases. Average falls rapidly until right K, then changes little. Average distance to centroid K
Limitations of K-means K-means has problems when clusters are of Differing sizes Differing densities Non-globular shapes
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)
Overcoming K-means Limitations Original Points K-means Clusters One solution is to use many clusters, then - Find parts of clusters - Apply merge strategy (merge clusters that would cause the least increase in SSE)
Overcoming K-means Limitations Original Points K-means Clusters
Overcoming K-means Limitations Original Points K-means Clusters
Importance of Choosing Initial Centroids 8 Iteration 12 34 6 4 2 y 0-2 -4-6 0 5 10 15 20 x Starting with two initial centroids in one cluster of each pair of clusters
Importance of Choosing Initial Centroids 8 Iteration 1 8 Iteration 2 6 6 4 4 2 2 y 0 y 0-2 -4-2 -4-6 -6 8 0 5 10 15 20 x Iteration 3 8 0 5 10 15 20 x Iteration 4 6 6 4 2 4 2 y 0 y 0-2 -4-2 -4-6 -6 0 5 10 15 20 x 0 5 10 15 20 Starting with two initial centroids in one cluster of each pair of clusters x
Importance of Choosing Initial Centroids 8 Iteration 12 34 6 4 2 y 0-2 -4-6 0 5 10 15 20 x Starting with some pairs of clusters having three initial centroids, while other have only one.
Importance of Choosing Initial Centroids 8 Iteration 1 8 Iteration 2 6 6 4 4 2 2 y 0 y 0-2 -4-2 -4-6 -6 0 5 10 15 20 0 5 10 15 20 Iteration x 3 Iteration x 4 8 8 6 6 4 4 2 2 y 0 y 0-2 -4-2 -4-6 -6 0 5 10 15 20 x 0 5 10 15 20 x Starting with some pairs of clusters having three initial centroids, while other have only one.
Problems with Selecting Initial Points Of course, the ideal would be to choose initial centroids, one from each true cluster. However, this is very difficult. If there are K real clusters then the chance of selecting one centroid from each cluster is small. Chance is relatively small when K is large If clusters are the same size, n, then For example, if K = 10, then probability = 10!/10 10 = 0.00036 Sometimes the initial centroids will readjust themselves in the right way, and sometimes they don t. Consider the previous example of five pairs of clusters
Solutions to Initial Centroids Problem Randomly selected initial centroids may be poor. 1. Perform multiple runs with different randomly chosen initial points, and select the set of clusters with minimum SSE. Might help, it depends on the type of data set or the number of clusters sought. 2. Use another variant of the algorithm Bisecting K-means Not as susceptible to initialization issues
Bisecting K-means Straightforward extension of the basic K-means algorithm. Simple idea: To obtain K clusters, split the set of points into two clusters, select one of these clusters to split, and so on, until K clusters have been produced. Algorithm Initialize the list of clusters to contain one cluster consisting of all points. repeat Choose and remove a cluster from the list of clusters. (biggest cluster or the cluster with the worst quality) //Perform several trial bisections of the chosen cluster. for i = 1 to number of trials do Bisect the selected cluster using basic K-means (i.e. 2-means). end for Select the two clusters from several bisections with the lowest total SSE. Add these two clusters to the list of clusters. until the list of clusters contains K clusters.
Bisecting K-means Example
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 0.2 0.15 0.1 6 4 3 4 2 5 2 5 0.05 3 1 1 0 1 3 2 5 4 6
Strengths of Hierarchical Clustering Do not have to assume any particular number of clusters cut the dendogram at the proper level to get the desired number of clusters. They may correspond to meaningful taxonomies Example in biological sciences e.g., animal kingdom, phylogeny reconstruction,
Hierarchical Clustering Algorithm Let each data point be a cluster Compute the proximity matrix 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.
Starting Situation Start with clusters of individual points and a proximity matrix p1 p1 p2 p3 p4 p5... p2 p3 p4 p5... Proximity Matrix
Intermediate Situation After some merging steps, we have some clusters C1 C2 C3 C4 C5 C1 C3 C4 C1 C2 C3 C4 C5 Proximity Matrix C2 C5
Intermediate Situation We want to merge the two closest clusters (C2 and C5) and update the proximity matrix. C1 C2 C1 C2 C3 C4 C5 C3 C3 C1 C4 C4 C5 Proximity Matrix C2 C5
After Merging The question is How do we update the proximity matrix? C1 C2 U C5 C3 C4 C1? C3 C4 C2 U C5 C3 C4?????? C1 Proximity Matrix C2 U C5
How to Define Inter-Cluster Similarity p1 p2 p3 p4 p5... Distance? p1 p2 MIN (or Single Link) MAX (or Complete Link or Clique) Group Average p3 p4 p5... Proximity Matrix
How to Define Inter-Cluster Similarity p1 p2 p3 p4 p5... p1 p2 p3 p4 MIN MAX Group Average p5... Proximity Matrix
How to Define Inter-Cluster Similarity p1 p2 p3 p4 p5... p1 p2 p3 p4 MIN MAX Group Average p5... Proximity Matrix
How to Define Inter-Cluster Similarity p1 p2 p3 p4 p5... p1 p2 p3 p4 MIN MAX Group Average p5... Proximity Matrix
Cluster Similarity: MIN Similarity of two clusters is based on the two most similar (closest) points in the different clusters Determined by only one pair of points
Hierarchical Clustering: MIN 3 5 1 0.2 0.15 5 2 2 3 1 6 0.1 0.05 0 3 6 2 5 4 1 4 4 Dendrogram Nested Clusters
Strength of MIN Original Points Two Clusters Can handle non-globular shapes
Limitations of MIN Original Points Four clusters Three clusters: Sensitive to noise and outliers The yellow points got wrongly merged with the red ones, as opposed to the green one.
Cluster Similarity: MAX Similarity of two clusters is based on the two least similar (most distant) points in the different clusters Determined by one pair of points in two clusters
Hierarchical Clustering: MAX 0.4 0.35 5 4 1 2 5 2 3 6 3 1 4 0.3 0.25 0.2 0.15 0.1 0.05 0 3 6 4 1 2 5 Dendrogram Nested Clusters
Strengths of MAX Original Points Four clusters Three clusters: The yellow points get now merged with the green one. Less susceptible with respect to noise and outliers
Limitations of MAX Original Points Two Clusters Tends to break large clusters
Cluster Similarity: Group Average Proximity of two clusters C i, C j is the average of pairwise proximity between points in the two clusters. proximity ( C,C i j ) p C q C = i j proximity(p, q) C C i j C i is the size of cluster C i (the number of data points).
Hierarchical Clustering: Group Average 0.25 5 5 2 2 4 1 0.2 0.15 0.1 0.05 3 1 6 0 3 6 4 2 5 1 Dendrogram 4 3 Nested Clusters
Hierarchical Clustering: Time and Space O(n 2 ) space since it uses the proximity matrix. n is the number of points. O(n 3 ) time in many cases There are n steps and at each step the size, n 2, proximity matrix must be updated and searched. Complexity can be reduced to O(n 2 log(n) ) time for some approaches.
Hierarchical Clustering Example
Hierarchical Clustering Example From Indo-European languages tree by Levenshtein distance by M.Serva and F.Petroni
DBSCAN DBSCAN is a density-based clustering algorithm. Locates regions of high density that are separated from one another by regions of low density. Density = the number of points within a specified radius (Eps) 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 neither a core point nor a border point.
DBSCAN: Core, Border, and Noise Points
DBSCAN Algorithm First, specify the type of each point (core, border, noise) Eliminate noise points. Any two core points that are close enough --- within a distance Eps of one another --- are put in the same cluster. Likewise, any border point that is close enough to a core point is put in the same cluster as the core point. Ties may need to be resolved if a border point is close to core points from different clusters.
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 Why DBSCAN doesn t work well here?
DBSCAN: Determining EPS and MinPts Look at the behavior of the distance from a point to its k-th nearest neighbor, called the k-dist. For points that belong to some cluster, the value of k-dist will be small [if k is not larger than the cluster size]. However, for points that are not in a cluster, such as noise points, the k-dist will be relatively large. So, if we compute the k-dist for all the data points for some k, sort them in increasing order, and then plot the sorted values, we expect to see a sharp change at the value of k-dist that corresponds to a suitable value of Eps. If we select this distance as the Eps parameter and take the value of k as the MinPts parameter, then points for which k-dist is less than Eps will be labeled as core points, while other points will be labeled as noise or border points.
DBSCAN: Determining EPS and MinPts Eps determined in this way depends on k, but does not change dramatically as k changes. If k is too small? Then even a small number of closely spaced points that are noise or outliers will be incorrectly labeled as clusters. If k is too large? then small clusters (of size less than k) are likely to be labeled as noise. Original DBSCAN used k = 4, which appears to be a reasonable value for most data sets.