Data Mining
Cluster Analysis: Basic Concepts and Algorithms
Lecture Notes for Chapter 8
Introduction to Data Mining
by
Tan, Steinbach, Kumar
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 1
Hierarchical Clustering
z Produces a set of nested clusters organized as a hierarchical tree
hierarchical tree
z Can be visualized as a dendrogram
– A tree like diagram that records the sequences of A tree like diagram that records the sequences of merges or splits
5
0.15 0.2
2 4
5 6
3 2 4
5
1 3 2 5 4 6
0 0.05 0.1
1
2
3 1
1 3 2 5 4 6
Strengths of Hierarchical Clustering
z 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
z They may correspond to meaningful taxonomies
– Example in biological sciences (e g animal kingdom – Example in biological sciences (e.g., animal kingdom,
phylogeny reconstruction, …)
Hierarchical Clustering
z
Hierarchical clustering is most frequently performed in an agglomerative manner
–
Start with the points as individual clusters
–
At each step, merge the closest pair of clusters until only one cluster (or k clusters) left
(o c uste s) e t
z
Traditional hierarchical algorithms use a similarity or
z
Traditional hierarchical algorithms use a similarity or distance matrix
– Merge or split one cluster at a time
Agglomerative Clustering Algorithm
z
Most popular hierarchical clustering technique
z
Basic algorithm is straightforward
z
Basic algorithm is straightforward
1. Compute the proximity (distance) matrix 2. Let each data point be a cluster
3. Repeat
4. Merge the two closest clusters 5 Update the proximity matrix 5. Update the proximity matrix 6. Until only a single cluster remains
z
Key operation is the computation of the proximity of
z
Key operation is the computation of the proximity of two clusters
– Different approaches to defining the distance between l t di ti i h th diff t l ith
clusters distinguish the different algorithms
Starting Situation
z Start with clusters of individual points and a proximity matrix
proximity matrix
p1 p2
p1 p2 p3 p4 p5 . . .
p3
p5 p4
. .
.
Proximity Matrix
Intermediate Situation
z
After some merging steps, we have some clusters
C2
C1 C3 C4 C5
C1
C3 C2
C4 C3
C3
C5 C4
C1
Proximity Matrix
C2 C5
Intermediate Situation
z
We want to merge the two closest clusters (C2 and C5) and update the proximity matrix.
C1 C2 C3 C4 C5C1
C3 C2
C4 C3
C3
C5 C4
C1
Proximity Matrix
C2 C5
After Merging
z
The question is “How do we update the proximity matrix?”
C2 U
? ? ? ?
? U C5 C1
C1 C2 U C5
C3 C4
C4 C3
? ? ? ?
?
? C3
C4 C2 U C5
C1
Proximity Matrix
C2 U C5
How to Define Inter-Cluster Similarity
p1
p1 p2 p3 p4 p5 . . .
Similarity?
p3 p4 p2
p5 p4
.
z
MIN
z
MAX
.
.
Proximity Matrix
zMAX
z
Group Average
z
Distance Between Centroids
z
Other methods driven by an objective function
– Ward’s Method uses squared error
– Ward s Method uses squared error
How to Define Inter-Cluster Similarity
p1
p1 p2 p3 p4 p5 . . .
p3 p4 p2
p5 p4
.
z
MIN
z
MAX
.
.
Proximity Matrix
zMAX
z
Group Average
z
Distance Between Centroids
z
Other methods driven by an objective function
– Ward’s Method uses squared error
– Ward s Method uses squared error
How to Define Inter-Cluster Similarity
p1
p1 p2 p3 p4 p5 . . .
p3 p4 p2
p5 p4
.
z
MIN
z
MAX
.
.
Proximity Matrix
zMAX
z
Group Average
z
Distance Between Centroids
z
Other methods driven by an objective function
– Ward’s Method uses squared error
– Ward s Method uses squared error
How to Define Inter-Cluster Similarity
p1
p1 p2 p3 p4 p5 . . .
p3 p4 p2
p5 p4
.
z
MIN
z
MAX
.
.
Proximity Matrix
zMAX
z
Group Average
z
Distance Between Centroids
z
Other methods driven by an objective function
– Ward’s Method uses squared error
– Ward s Method uses squared error
How to Define Inter-Cluster Similarity
p1
p1 p2 p3 p4 p5 . . .
p3 p4
× × p2
p5 p4
.
z
MIN
z
MAX
.
.
Proximity Matrix
zMAX
z
Group Average
z
Distance Between Centroids
z
Other methods driven by an objective function
– Ward’s method uses squared error
– Ward s method uses squared error
Cluster Similarity: MIN or Single Link
z Similarity of two clusters is based on the two most similar (closest) points in the different most similar (closest) points in the different clusters
– Determined by one pair of points, i.e., by one link in the proximity graph.
I1 I2 I3 I4 I5
I1 1.00 0.90 0.10 0.65 0.20 I2 0.90 1.00 0.70 0.60 0.50 I3 0.10 0.70 1.00 0.40 0.30 I4 0.65 0.60 0.40 1.00 0.80 I5 0 20 0 50 0 30 0 80 1 00
I5 0.20 0.50 0.30 0.80 1.00 1 2 3 4 5
Hierarchical Clustering: MIN
1 5 1
5 2
1 3
0.2
2
3 6
1 2
0.1 0.15
4
4
0 3 6 2 5 4 10.05
Nested Clusters Dendrogram
Nested Clusters Dendrogram
Strength of MIN
Original Points Two Clusters
• Can handle non-elliptical shapes p p
Limitations of MIN
Original Points Two Clusters
Original Points Two Clusters
• Sensitive to noise and outliers
Cluster Similarity: MAX or Complete Linkage
z Similarity of two clusters is based on the two least similar (most distant) points in the different
similar (most distant) points in the different clusters
– Determined by all pairs of points in the two clusters
I1 I2 I3 I4 I5
I1 1.00 0.90 0.10 0.65 0.20 I2 0.90 1.00 0.70 0.60 0.50 I3 0 10 0 0 1 00 0 40 0 30 I3 0.10 0.70 1.00 0.40 0.30 I4 0.65 0.60 0.40 1.00 0.80
I5 0 20 0 50 0 30 0 80 1 00 1 2 3 4 5
I5 0.20 0.50 0.30 0.80 1.00 1 2 3 4 5
Hierarchical Clustering: MAX
4 1
0 3 0.35 0.4
1
5 2
2 5
4
0.15 0.2 0.25
2
0.33 6
3 1
3 6 4 1 2 5
0 0.05 0.1
4
1
Nested Clusters Dendrogram
Strength of MAX
Original Points Two Clusters
• Less susceptible to noise and outliers p
Limitations of MAX
Original Points Two Clusters
Original Points Two Clusters
• Tends to break large clusters
• Biased towards globular clusters
Cluster Similarity: Group Average
z
Proximity of two clusters is the average of pairwise proximity between points in the two clusters.
∑
|
|Cluster
|
|Cluster
) p , p proximity(
) Cluster ,
Cluster proximity(
j i
Cluster p Cluster
p i j
j
i j j
i i
= ∗
∑
∈∈
z
Need to use average connectivity for scalability since total proximity favors large clusters
I1 I2 I3 I4 I5
I1 1.00 0.90 0.10 0.65 0.20 I2 0 90 1 00 0 70 0 60 0 50 I2 0.90 1.00 0.70 0.60 0.50 I3 0.10 0.70 1.00 0.40 0.30 I4 0.65 0.60 0.40 1.00 0.80
I5 0.20 0.50 0.30 0.80 1.00 1 2 3 4 5
Hierarchical Clustering: Group Average
5
0.2 0.25
1
5
2
5 4
0.1 0.15
2
3 5
6 1
3 6 4 1 2 5
0 0.05
4
1 3
Nested Clusters Dendrogram g
Hierarchical Clustering: Group Average
z Compromise between Single and Complete Link
Link
St th
z Strengths
– Less susceptible to noise and outliers
z Limitations
– Biased towards globular clusters
Cluster Similarity: Ward’s Method
z Similarity of two clusters is based on the increase in squared error when two clusters are merged
in squared error when two clusters are merged
– Similar to group average if distance between points is distance squared
z Less susceptible to noise and outliers
z Biased towards globular clusters
z Hierarchical analogue of K-means
– Can be used to initialize K-means Can be used to initialize K means
Hierarchical Clustering: Comparison
1
2 5
1 4 5
3
5
MIN MAX 2
3 5
6 3 1
2
3 5
6 1 2
4 4 4
Ward’s Method
1 5 2
2
5 4
1 5 2
2
5
Group Average
2
3 4
6 1 3 3
4
6 3 1
4
3
Hierarchical Clustering: Problems and Limitations
z Once a decision is made to combine two clusters, it cannot be undone
it cannot be undone
z No objective function is directly minimized
z Different schemes have problems with one or f th f ll i
more of the following:
– Sensitivity to noise and outliers
Diffi lt h dli diff t i d l t d
– Difficulty handling different sized clusters and convex shapes
– Breaking large clusters Breaking large clusters
Cluster Validity
z
For supervised classification we have a variety of measures to evaluate how good our model is
Accuracy sensitivity specificity – Accuracy, sensitivity, specificity...
z
For cluster analysis, the analogous question is how to evaluate the “goodness” of the resulting clusters?
evaluate the goodness of the resulting clusters?
z
But “clusters are in the eye of the beholder”!
z
Then why do we want to evaluate them?
– To avoid finding patterns in noise g p
– To compare clustering algorithms
– To compare two sets of clusters
– To compare two clusters p
Clusters found in Random Data
0.7 0.8 0.9 1
0.7 0.8 0.9 1
0.3 0.4 0.5 0.6
y
Random Points
0.3 0.4 0.5 0.6
y
DBSCAN (density- based)
0 0.2 0.4 0.6 0.8 1
0 0.1 0.2
x
1
0 0.2 0.4 0.6 0.8 1
0 0.1 0.2
x
1
0.6 0.7 0.8 0.9
K-means
0.6 0.7 0.8 0.9
Complete Link
0 1 0.2 0.3 0.4
y0.5
0 1 0.2 0.3 0.4
y 0.5
0 0.2 0.4 0.6 0.8 1
0 0.1
x
0 0.2 0.4 0.6 0.8 1
0 0.1
x
Different Aspects of Cluster Validation
1. Determining the clustering tendency of a set of data, i.e.,
distinguishing whether non-random structure actually exists in the data.
data.
2. Comparing the results of a cluster analysis to externally known results, e.g., to externally given class labels.
3 Evaluating how well the results of a cluster analysis fit the data 3. Evaluating how well the results of a cluster analysis fit the data
without reference to external information.
- Use only the data
4 C i th lt f t diff t t f l t l t
4. Comparing the results of two different sets of cluster analyses to determine which is better.
5. Determining the ‘correct’ number of clusters.
For 2, 3, and 4, we can further distinguish whether we want to evaluate the entire clustering or just individual clusters
evaluate the entire clustering or just individual clusters.
Measures of Cluster Validity
z
Numerical measures that are applied to judge various aspects of cluster validity, are classified into the following three types.
External Index: Used to measure the extent to which cluster labels – External Index: Used to measure the extent to which cluster labels
match externally supplied class labels.
Entropy
– Internal Index: Used to measure the goodness of a clustering – Internal Index: Used to measure the goodness of a clustering
structure without respect to external information.
Sum of Squared Error (SSE)
– Relative Index: Relative Index: Used to compare two different clusterings or Used to compare two different clusterings or clusters.
Often an external or internal index is used for this function, e.g., SSE or entropy
z
Sometimes these are referred to as criteria instead of indices
–
However, sometimes criterion is the general strategy and index is the
numerical measure that implements the criterion.
Measuring Cluster Validity Via Correlation
z
Two matrices
–
Proximity Matrix
“Incidence” Matrix
–Incidence Matrix
One row and one column for each data point
An entry is 1 if the associated pair of points belong to the same cluster
An entry is 0 if the associated pair of points belongs to different clusters
An entry is 0 if the associated pair of points belongs to different clusters
z
Compute the correlation between the two matrices
–
Since the matrices are symmetric, only the correlation between n(n-1) / 2 entries needs to be calculated.
z
High correlation indicates that points that belong to the same cluster are close to each other.
z
Not a good measure for some density or contiguity based
clusters.
Measuring Cluster Validity Via Correlation
z Correlation of incidence and proximity matrices for the K-means clusterings of the following two for the K means clusterings of the following two data sets.
1 1
0.6 0.7 0.8 0.9
0.6 0.7 0.8 0.9
0 1 0.2 0.3 0.4
y 0.5
0 1 0.2 0.3 0.4
y 0.5
0 0.2 0.4 0.6 0.8 1
0 0.1
x
0 0.2 0.4 0.6 0.8 1
0 0.1
x
Corr = -0.9235 Corr = -0.5810
Using Similarity Matrix for Cluster Validation
z Order the similarity matrix with respect to cluster labels and inspect visually.
0.9 1
10
20 0 8
0.9 1
0.5 0.6 0.7 0.8
y Points
20 30 40
50 0.5
0.6 0.7 0.8
0.1 0.2 0.3 0.4
P 60
70 80
90 0.1
0.2 0.3 0.4
0 0.2 0.4 0.6 0.8 1
0 0.1
x Points
20 40 60 80 100
100
Similarity 0
Using Similarity Matrix for Cluster Validation
z Clusters in random data are not so crisp
10 20
30 0 7
0.8 0.9 1
0 7 0.8 0.9 1
Points
30 40 50 60
70 0.3
0.4 0.5 0.6 0.7
0.3 0.4 0.5 0.6 0.7
y
Points
20 40 60 80 100
80 90
100
Similarity0 0.1 0.2
0 0.2 0.4 0.6 0.8 1
0 0.1 0.2
x
DBSCAN
Using Similarity Matrix for Cluster Validation
z Clusters in random data are not so crisp
10 20
30 0.7
0.8 0.9 1
0.7 0.8 0.9 1
Points
40 50 60
70 0.3
0.4 0.5 0.6
0.3 0.4 0.5 0.6
y
Points
20 40 60 80 100
80 90
100
Similarity0 0.1 0.2
0 0.2 0.4 0.6 0.8 1
0 0.1 0.2
x
K-means
Using Similarity Matrix for Cluster Validation
z Clusters in random data are not so crisp
0 7 0.8 0.9 1 10
20
30 0 7
0.8 0.9 1
0.3 0.4 0.5 0.6 0.7
y
Points
30 40 50 60
70 0.3
0.4 0.5 0.6 0.7
0 0.2 0.4 0.6 0.8 1
0 0.1 0.2
x Points
20 40 60 80 100
80 90
100
Similarity 0 0.1 0.2
Complete Link
Using Similarity Matrix for Cluster Validation
1
1
2
3 6
4 0.6
0.7 0.8 0.9 500
1000
5
4
0 2 0.3 0.4 0.5 1500
2000
7
0 0.1 0.2
500 1000 1500 2000 2500 3000
2500
3000
DBSCAN
Internal Measures: SSE
z
Clusters in more complicated figures aren’t well separated
z
Internal Index: Used to measure the goodness of a clustering structure without respect to external information
structure without respect to external information
– SSE
z
SSE is good for comparing two clusterings or two clusters g p g g (average SSE).
z
Can also be used to estimate the number of clusters
10
6 7 8 9
E
2 4 6
1 2 3 4
SSE 5
-4 -2 0
2 5 10 15 20 25 30
0 1
5 10 15 K
-6
Internal Measures: SSE
z SSE curve for a more complicated data set
1
2
3 6
4
5
7