Docsity

Clustering-Distributed Queries-Lecture Notes, Study notes of Distributed Database Management Systems

Toggle sidebar
bg1
1 Clustering
Given points in some space | often a high-dimensional space | group the points into a small number of
clusters
, each cluster consisting of points that are \near" in some sense. Some applications:
1. Manyyears ago, during a cholera outbreak in London, a physician plotted the location of cases on a
map, getting a plot that looked like Fig. 1. Properly visualized, the data indicated that cases
clustered around certain intersections, where there were polluted wells, not only exposing the cause of
cholera, but indicating what to do about the problem. Alas, not all data mining is this easy, often
because the clusters are in so many dimensions that visualization is very hard.
x
xx
x
x
xxxx xx
x
xxx
xx
x
x
x
x
Figure 1: Clusters of cholera cases indicated where the polluted wells were
2.
Skycat
clustered 2
10
9
sky objects into stars, galaxies, quasars, etc. Each object was a pointina
space of 7 dimensions, with each dimension representing radiation in one band of the spectrum. The
Sloan Sky Survey is a more ambitious attempt to catalog and cluster the entire visible universe.
3. Documents may be thoughtofaspoints in a high-dimensional space, where each dimension
corresponds to one possible word. The position of a document in a dimension is the number of times
the word occurs in the document (or just 1 if it occurs, 0 if not). Clusters of documents in this space
often correspond to groups of documents on the same topic.
1.1 Distance Measures
To discuss whether a set of points is close enough to be considered a cluster, we need a
distancemeasure
D
(
x; y
) that tells how far points
x
and
y
are. The usual axioms for a distance measure
D
are:
1.
D
(
x; x
) = 0. A point is distance 0 from itself.
2.
D
(
x; y
)=
D
(
y; x
). Distance is symmetric.
3.
D
(
x; y
)
D
(
x; z
)+
D
(
z; y
). The
triangle inequality
.
Often, our points may be thought to liveina
k
-dimensional Euclidean space, and the distance between any
two p oints, say
x
=[
x
1
;x
2
;:::;x
k
] and
y
=[
y
1
;y
2
;:::;y
k
] is given in one of the usual manners:
1. Common distance (\
L
2
norm"):
q
P
k
i
=1
(
x
i
,
y
i
)
2
.
2.
Manhattan distance
(\
L
1
norm"):
P
k
i
=1
j
x
i
,
y
i
j
.
3. Max of dimensions (\
L
1
norm"): max
k
i
=1
j
x
i
,
y
i
j
.
When there is no Euclidean space in which to place the points, clustering becomes more dicult. Here are
some examples where a distance measure without a Euclidean space makes sense.
1
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Clustering-Distributed Queries-Lecture Notes and more Study notes Distributed Database Management Systems in PDF only on Docsity!

1 Clustering

Given p oints in some space | often a high-dimensional space | group the p oints into a small numb er of clusters, each cluster consisting of p oints that are \near" in some sense. Some applications:

  1. Many years ago, during a cholera outbreak in London, a physician plotted the lo cation of cases on a map, getting a plot that lo oked like Fig. 1. Prop erly visualized, the data indicated that cases clustered around certain intersections, where there were p olluted wells, not only exp osing the cause of cholera, but indicating what to do ab out the problem. Alas, not all data mining is this easy, often b ecause the clusters are in so many dimensions that visualization is very hard.

x

x x

xx

x

x

xx x

xxx

x

x

x x

x

x

x

x

Figure 1: Clusters of cholera cases indicated where the p olluted wells were

2. Skycat clustered 2  109 sky ob jects into stars, galaxies, quasars, etc. Each ob ject was a p oint in a

space of 7 dimensions, with each dimension representing radiation in one band of the sp ectrum. The Sloan Sky Survey is a more ambitious attempt to catalog and cluster the entire visible universe.

  1. Do cuments may b e thought of as p oints in a high-dimensional space, where each dimension corresp onds to one p ossible word. The p osition of a do cument in a dimension is the numb er of times the word o ccurs in the do cument (or just 1 if it o ccurs, 0 if not). Clusters of do cuments in this space often corresp ond to groups of do cuments on the same topic.

1.1 Distance Measures

To discuss whether a set of p oints is close enough to b e considered a cluster, we need a distance measure D (x; y ) that tells how far p oints x and y are. The usual axioms for a distance measure D are:

  1. D (x; x) = 0. A p oint is distance 0 from itself.
  2. D (x; y ) = D (y ; x). Distance is symmetric.

3. D (x; y )  D (x; z ) + D (z ; y ). The triangle inequality.

Often, our p oints may b e thought to live in a k -dimensional Euclidean space, and the distance b etween any two p oints, say x = [x 1 ; x 2 ; : : : ; xk ] and y = [y 1 ; y 2 ; : : : ; yk ] is given in one of the usual manners:

  1. Common distance (\L 2 norm"):

qP

k

i=1 (xi^ ^ yi^ )^2.

  1. Manhattan distance (\L 1 norm"):

Pk

i=1 jxi^ ^ yi^ j.

3. Max of dimensions (\L 1 norm"): maxki=1 jxi yi j.

When there is no Euclidean space in which to place the p oints, clustering b ecomes more dicult. Here are some examples where a distance measure without a Euclidean space makes sense.

Example 1.1 : We can think of Web pages as p oints in the roughly 108 -dimensional space where each dimension corresp onds to one word. However, computation of distances would b e prohibitive in a space this large. A b etter approach is to base the distance D (x; y ) on the dot pro duct of vectors corresp onding to x and y , since we then have to deal only with the words actually present in b oth x and y. We need to compute the lengths of the vectors involved, which is the square ro ot of the sum of the squares of the numb ers of o ccurrences of each word. The sum of the pro duct of the o ccurrences of each word in each do cument is divided by each of the lengths to get a normalized dot pro duct. We subtract this quantity from 1 to get the distance b etween x and y. For instance, supp ose there were only 4 words of interest, and the vectors x = [2; 0 ; 3 ; 1] and y = [5; 3 ; 2 ; 0] represented the numb ers of o ccurrences of these words in the two do cuments. The dot pro duct x:y is

2  5 + 0  3 + 3  2 + 1  0 = 16, the length of the rst vector is

p

p

14, and the length of the second is

p

p

  1. Thus,

D (x; y ) = 1

p

p

As another example, supp ose do cument x has word-vector [a 1 ; a 2 ; : : :], and y is two copies of x; i.e., y = [2a 1 ; 2 a 2 ; : : :]. Then

D (x; y ) = 1

P

i 2 a

2

pP^ i

i a

2 i

pP

i (2ai^ )

2 =^0

That is, x and y are essentially the same do cument; surely they are on the same topic, and deserve to b e clustered together. 2

Example 1.2 : Character strings, such as DNA sequences may b e similar even though there are some insertions and deletions as well as changes in some characters. For instance, abcde and bcdxy e are rather similar, even though they don't have any p ositions in common, and don't even have the same length. Thus, instead of trying to construct a Euclidean space with one dimension for each p osition, we can de ne the

distance function D (x; y ) = jxj + jy j 2 jLC S (x; y )j, where LCS stands for the longest common subsequence

of x and y. In our example, LC S (abcde; bcdxy e) is bcde, of length 4, so

D (abcde; bcdxy e) = 5 + 6 2  4 = 3; i.e., the strings are fairly close. 2

1.2 The Curse of Dimensionality

An unintuitive consequence of working in a high-dimensional space is that almost all pairs of p oints are ab out as far away as average.

Example 1.3 : Supp ose we throw p oints at random into a k -dimensional unit cub e. If k = 2, we exp ect that the p oints will spread out in the plane, with some very nearby p oints and some pairs at almost the maximum p ossible distance,

p

However, supp ose k is large, say 100, or 100,000. Regardless of which norm we use, L 2 , L 1 , or L 1 , we

know that D (x; y )  maxi jxi yi j, if x = [x 1 ; x 2 ; : : :] and y = [y 1 ; y 2 ; : : :]. For large k , it is very likely that

there will b e some dimension i such that xi and yi are almost as di erent as p ossible, even if x and y are very close in other dimensions. Thus, D (x; y ) is going to b e very close to 1. 2

Another interesting consequence of high-dimensionality is that all vectors, such as x = [x 1 ; x 2 ; : : :] and y = [y 1 ; y 2 ; : : :] are almost orthogonal. The reason is that if we pro ject x and y onto any of the

k

2

planes formed by two of the k axes, there is going to b e one in which the pro jected vectors are almost orthogonal.

1.3 Approaches to Clustering

At a high level, we can divide clustering algorithms into two broad classes:

  1. Centroid approaches. We guess the centroids or central p oint in each cluster, and assign p oints to the cluster of their nearest centroid.

 Having lo cated the centroids of the k clusters, we can reassign all p oints, since some p oints that were assigned early may actually wind up closer to another centroid, as the centroids move ab out.

 If we are not sure of k , we can try di erent values of k until we nd the smallest k such that increasing k do es not much decrease the average distance of p oints to their centroids. Example 1. illustrates this p oint.

Example 1.5 : Consider the data suggested by Fig. 3. Clearly, k = 3 is the right numb er of clusters, but supp ose we rst try k = 1. Then all p oints are in one cluster, and the average distance to the centroid will b e high.

x x x

xxx

x

x

x x

x

x

x

x x

x x

x

x

radius

k

Average

Figure 3: Discovering that k = 3 is the right numb er of clusters

Supp ose we then try k = 2. One of the three clusters will b e by itself and the other two will b e forced into one cluster, as suggested by the dotted lines. The average distance of p oints to the centroid will thus shrink considerably. If k = 3, then each of the apparent clusters should b e a cluster by itself, and the average distance from p oints to their centroids shrinks again, as indicated by the graph in Fig. 3. However, if we increase k to 4, then one of the true clusters will b e arti cially partitioned into two nearby clusters, as suggested by the solid lines. The average distance to centroid will drop a bit, but not much. It is this failure to drop further that tips us o that k = 3 is right, even if the data is in so many dimensions that we cannot visualize the clusters. 2

1.6 The BFR Algorithm

Based on k -means, this algorithm reads its data once, consuming a main-memory-full at a time. The algorithm works b est if the clusters are normally distributed around a central p oint, p erhaps with a di erent standard deviation in each dimension. Figure 4 suggests what the data b elonging to a typical cluster in two-dimensions might lo ok like. A centroid, marked by +, has p oints scattered around, with the standard deviation  in the horizontal dimension b eing twice what it is in the vertical dimension. Ab out 70% of the p oints will lie within the 1  ellipse; 95% will lie within 2  , 99.9% within 3  , and 99.9999% within 4 .

1.7 Representation of Clusters in BFR

Having worked on Skycat, Usama Fayyad (the \F" in BFR) probably thought of clusters as \galaxies," as suggested in Fig. 5. A cluster consists of:

  1. A central core, the Discard set (DS). This set of p oints is considered certain to b elong to the cluster. All the p oints in this set are replaced by some simple statistics, describ ed b elow. Note: although called \discarded" p oints, these p oints in truth have a signi cant e ect throughout the running of the algorithm, since they determine collectively where the centroid is and what the standard deviation of the cluster is in each dimension.

Figure 4: Points in a cluster are assumed to have b een generated by taking a centroid for the cluster and adding to it in each dimension a normally distributed random variable with mean 0

  1. Surrounding subgalaxies, collectively called the Compression set (CS). Each sub cluster in the CS consists of a group of p oints that are suciently close to each other that they can b e replaced by their statistics, just like the DS for a cluster is. However, they are suciently far away from any cluster's centroid, that we are not yet sure which cluster they b elong to.
  2. Individual stars that are not part of a galaxy or subgalaxy, the Retained set (RS). These p oints can neither b e assigned to any cluster nor can they b e group ed into a sub cluster of the CS. They are stored in main memory, as individual p oints, along with the statistics of the DS and CS.

The statistics used to represent each cluster of the DS and each sub cluster of the CS are:

  1. The count of the numb er of p oints, N.
  2. The vector of sums of the co ordinates of the p oints in each dimension. The vector is called SUM, and the comp onent in the ith dimension is S U Mi.
  3. The vector of sums of squares of the co ordinates of the p oints in each dimension, called S U M S Q. The comp onent in dimension i is S U M S Qi.

Note that these three pieces of information, totaling 2 k + 1 numb ers if there are k dimensions, are sucient to compute imp ortant statistics of a cluster or sub cluster, and they are more convenient to maintain as p oints are added to clusters than would, say, b e the mean and variance in each dimension. For instance:

 The co ordinate i of the centroid of the cluster in dimension i is S U Mi =N.

 The variance in dimension i is

S U M S Qi N

 S U M

i N

and the standard deviation i is the square ro ot of that.

1.8 Pro cessing a Main-Memory-Full of Points in BFR

With the rst load of main memory, BFR selects the k cluster centroids, using some chosen main-memory algorithm, e.g., pick a sample of p oints, optimize the clusters exactly, and chose their centroids as the initial centroids. The entire main-memory full of p oints is then pro cessed like any subsequent memory-load of p oints, as follows: