Download presentation
Presentation is loading. Please wait.
1
1 Clustering Distance Measures Hierarchical Clustering k -Means Algorithms
2
2 The Problem of Clustering uGiven a set of points, with a notion of distance between points, group the points into some number of clusters, so that members of a cluster are in some sense as nearby as possible.
3
3 Example x x x x x x x xx x x x x x x x x x x x x x x x x x x
4
4 The Curse of Dimensionality uWhile clustering looks intuitive in 2 dimensions, many applications involve 10 or 10,000 dimensions. uHigh-dimensional spaces look different: the probability of random points being close drops quickly as the dimensionality grows.
5
5 Example: SkyCat uA catalog of “sky objects” represented objects by their radiation in 9 dimensions. uProblem was to cluster into similar objects, e.g., galaxies, nearby stars, quasars, etc. uSloan Sky Survey is a newer, better version.
6
6 Example: Clustering CD’s uIntuitively: music divides into categories, and customers prefer a few categories. wBut what are categories really? uRepresent a CD by the customers who bought it. uSimilar CD’s have similar sets of customers, and vice-versa.
7
7 The Space of CD’s uThink of a space with one dimension for each customer. wValues in a dimension may be 0 or 1 only. uA CD’s point in this space is (x 1, x 2, …, x k ), where x i = 1 iff the i th customer bought the CD. wCompare with the “correlated items” matrix: rows = customers; cols. = CD’s.
8
8 Example: Clustering Documents uRepresent a document by a vector (x 1, x 2, …, x k ), where x i = 1 iff the i th word (in some order) appears in the document. wIt actually doesn’t matter if k is infinite; i.e., we don’t limit the set of words. uDocuments with similar sets of words may be about the same topic.
9
9 Example: Protein Sequences uObjects are sequences of {C,A,T,G}. uDistance between sequences is “edit distance,” the minimum number of inserts and deletes needed to turn one into the other. uNote there is a “distance,” but no convenient space of points.
10
10 Distance Measures uEach clustering problem is based on some kind of “distance” between points. uTwo major classes of distance measure: 1.Euclidean : based on position of points in some k -dimensional space. 2.Noneuclidean : not.
11
11 Axioms of a Distance Measure ud is a distance measure if it is a function from pairs of points to reals such that: 1.d(x,x) = 0. 2.d(x,y) = d(y,x). 3.d(x,y) > 0. 4.d(x,y) < d(x,z) + d(z,y) (triangle inequality).
12
12 Some Euclidean Distances uL 2 norm : d(x,y) = square root of the sum of the squares of the differences between x and y in each dimension. wThe most common notion of “distance.” uL 1 norm : sum of the differences in each dimension. wManhattan distance = distance if you had to travel along coordinates only.
13
13 Examples of Euclidean Distances x = (5,5) y = (9,8) L 2 -norm: dist(x,y) = (4 2 +3 2 ) = 5 L 1 -norm: dist(x,y) = 4+3 = 7 4 35
14
14 Another Euclidean Distance L ∞ norm : d(x,y) = the maximum of the differences between x and y in any dimension. Note: the maximum is the limit as n goes to ∞ of what you get by taking the n th power of the differences, summing and taking the n th root.
15
15 Non-Euclidean Distances uJaccard measure for binary vectors = ratio of sizes of intersection and union. uCosine measure = angle between vectors from the origin to the points in question. uEdit distance = number of inserts and deletes to change one string into another.
16
16 Jaccard Measure uExample: p 1 = 00111; p 2 = 10011. wSize of intersection = 2; size of union = 4, J.M. = 1/2. uNeed to make a distance function satisfying triangle inequality and other laws. ud(x,y) = 1 - J.M. works.
17
17 Why J.M. Is a Distance Measure ud(x,x) = 0 because x x = x x. ud(x,y) = d(y,x) because union and intersection are symmetric. ud(x,y) > 0 because |x y| < |x y|. ud(x,y) < d(x,z) + d(z,y) trickier --- next slide.
18
18 Triangle Inequality for J.M. 1 - |x z| + 1 - |y z| > 1 - |x y| |x z| |y z| |x y| uRemember: |a b|/|a b| = probability that minhash(a) = minhash(b). uThus, 1 - |a b|/|a b| = probability that minhash(a) minhash(b).
19
19 Triangle Inequality --- (2) uSo we need to observe that prob[minhash(x) minhash(y)] < prob[minhash(x) minhash(z)] + prob[minhash(z) minhash(y)] uClincher: whenever minhash(x) minhash(y), one of minhash(x) minhash(z) and minhash(z) minhash(y) must be true.
20
20 Cosine Measure uThink of a point as a vector from the origin (0,0,…,0) to its location. uTwo points’ vectors make an angle, whose cosine is the normalized dot- product of the vectors. wExample p1 = 00111; p2 = 10011. wp1.p2 = 2; |p1| = |p2| = 3. cos( ) = 2/3; is about 48 degrees.
21
21 Cosine-Measure Diagram p1 p2 p1.p2 |p2| dist(p1, p2) = = arccos(p1.p2/|p2||p1|)
22
22 Why? p1 = (x1,y1) p2 = (x2,0) x1 Dot product is invariant under rotation, so pick convenient coordinate system. x1 = p1.p2/|p2| p1.p2 = x1*x2. |p2| = x2.
23
23 Why C.D. Is a Distance Measure ud(x,x) = 0 because arccos(1) = 0. ud(x,y) = d(y,x) by symmetry. ud(x,y) > 0 because angles are chosen to be in the range 0 to 180 degrees. uTriangle inequality: physical reasoning. If I rotate an angle from x to z and then from z to y, I can’t rotate less than from x to y.
24
24 Edit Distance uThe edit distance of two strings is the number of inserts and deletes of characters needed to turn one into the other. uEquivalently, d(x,y) = |x| + |y| -2|LCS(x,y)|. wLCS = longest common subsequence = longest string obtained both by deleting from x and deleting from y.
25
25 Example ux = abcde ; y = bcduve. uTurn x into y by deleting a, then inserting u and v after d. wEdit-distance = 3. uOr, LCS(x,y) = bcde. u|x| + |y| - 2|LCS(x,y)| = 5 + 6 –2*4 = 3.
26
26 Why E.D. Is a Distance Measure ud(x,x) = 0 because 0 edits suffice. ud(x,y) = d(y,x) because insert/delete are invertible. ud(x,y) > 0: no notion of negative edits. uTriangle inequality: changing x to z and then to y is one way to change x to y.
27
27 Methods of Clustering uHierarchical: wInitially, each point in cluster by itself. wRepeatedly combine the two “closest” clusters into one. uPoint assignment: wMaintain a set of clusters. wPlace points into “closest” cluster.
28
28 Hierarchical Clustering uKey problem: as you build clusters, how do you represent the location of each cluster, to tell which pair of clusters is closest? uEuclidean case: each cluster has a centroid = average of its points. wMeasure intercluster distances by distances of centroids.
29
29 Example (5,3) o (1,2) o o (2,1)o (4,1) o (0,0)o (5,0) x (1.5,1.5) x (4.5,0.5) x (1,1) x (4.7,1.3)
30
30 And in the Non-Euclidean Case? uThe only “locations” we can talk about are the points themselves. uApproach 1: clustroid = point “closest” to other points. wTreat clustroid as if it were centroid, when computing intercluster distances.
31
31 Example 12 3 4 5 6 intercluster distance clustroid
32
32 Other Approaches to Defining “Nearness” of Clusters uApproach 2: intercluster distance = minimum of the distances between any two points, one from each cluster. uApproach 3: Pick a notion of “cohesion” of clusters, e.g., maximum distance from the clustroid. wMerge clusters whose union is most cohesive.
33
33 k -Means uAssumes Euclidean space. uStarts by picking k, the number of clusters. uInitialize clusters by picking one point per cluster. wFor instance, pick one point at random, then k -1 other points, each as far away as possible from the previous points.
34
34 Populating Clusters uFor each point, place it in the cluster whose current centroid it is nearest. uAfter all points are assigned, fix the centroids of the k clusters. uReassign all points to their closest centroid. wSometimes moves points between clusters.
35
35 Example 1 2 3 4 5 6 7 8 x x Clusters after first round Reassigned points
36
36 Getting k Right uTry different k, looking at the change in the average distance to centroid, as k increases. uAverage falls rapidly until right k, then changes little. k Average distance to centroid Best value of k
37
37 Example x x x x x x x xx x x x x x x x x x x x x x x x x x x Too few; many long distances to centroid.
38
38 Example x x x x x x x xx x x x x x x x x x x x x x x x x x x Just right; distances rather short.
39
39 Example x x x x x x x xx x x x x x x x x x x x x x x x x x x Too many; little improvement in average distance.
40
40 BFR Algorithm uBFR (Bradley-Fayyad-Reina) is a variant of k -means designed to handle very large (disk-resident) data sets. uIt assumes that clusters are normally distributed around a centroid in a Euclidean space. wStandard deviations in different dimensions may vary.
41
41 BFR --- (2) uPoints are read one main-memory-full at a time. uMost points from previous memory loads are summarized by simple statistics. uTo begin, from the initial load we select the initial k centroids by some sensible approach.
42
42 Three Classes of Points 1.The discard set : points close enough to a centroid to be represented statistically. 2.The compression set : groups of points that are close together but not close to any centroid. They are represented statistically, but not assigned to a cluster. 3.The retained set : isolated points.
43
43 Representing Sets of Points uFor each cluster, the discard set is represented by: 1.The number of points, N. 2.The vector SUM, whose i th component is the sum of the coordinates of the points in the i th dimension. 3.The vector SUMSQ: i th component = sum of squares of coordinates in i th dimension.
44
44 Comments u2d + 1 values represent any number of points. wd = number of dimensions. uAverages in each dimension (centroid coordinates) can be calculated easily as SUM i /N. wSUM i = i th component of SUM.
45
45 Comments --- (2) uVariance of a cluster’s discard set in dimension i can be computed by: SUMSQ i /N – (SUM i /N ) 2 uAnd the standard deviation is the square root of that. uThe same statistics can represent any compression set.
46
46 “Galaxies” Picture A cluster. Its points are in the DS. The centroid Compressed sets. Their points are in the CS. Points in the RS
47
47 Processing a Set of Points 1.Find those points that are “sufficiently close” to a cluster centroid, and add those points to the cluster and the DS. 2.Use any main-memory clustering algorithm to cluster the remaining points and the old RS. uClusters go to the CS; outlying points to the RS.
48
48 Processing --- (2) 3.Adjust statistics of the clusters to account for the new points. 4.Consider merging subclusters of the CS. 5.If this is the last round, merge all subclusters of the CS and all RS points into their nearest cluster.
49
49 How Close is Close Enough? uWe need a way to decide whether to put a new point into a cluster. uBFR suggest two ways: 1.Mahalanobis distance less than a threshold. 2.Low likelihood of the currently nearest centroid changing.
50
50 Mahalanobis Distance uNormalized Euclidean distance. uFor point (x 1,…,x k ) and centroid (c 1,…,c k ): 1.Normalize in each dimension: y i = |x i -c i |/ i 2.Take sum of the squares of the y i ’s. 3.Take the square root.
51
51 Mahalanobis Distance --- (2) uIf clusters are normally distributed, then one standard deviation corresponds to a distance d. wI.e., 70% of the points of the cluster will have a Mahalanobis distance < d. uAccept a point for a cluster if its M.D. is < some threshold, e.g. 4 standard deviations.
52
52 Picture: Equal M.D. Regions 22
53
53 Should Two CS Subclusters Be Combined? uCompute the variance of the combined subcluster. wN, SUM, and SUMSQ allow us to make that calculation. uCombine if the variance is below some threshold.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.