Cluster Analysis in Data Mining
Cluster Analysis in Data Mining
Inter-cluster
Intra-cluster distances are
distances are maximized
minimized
4 Louisiana-Land-UP,Phillips-Petro-UP,Unocal-UP,
Schlumberger-UP
Oil-UP
Summarization
– Reduce the size of large
data sets
Clustering precipitation
in Australia
– Hierarchical clustering
A set of nested clusters organized as a hierarchical tree
p1
p3 p4
p2
p1 p2 p3 p4
p1
p3 p4
p2
p1 p2 p3 p4
Well-separated clusters
Prototype-based clusters
Contiguity-based clusters
Density-based clusters
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
Prototype-based
– A cluster is a set of objects such that an object in a cluster is
closer (more similar) to the prototype or “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
8 contiguous 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 intertwined, and when
noise and outliers are present.
6 density-based clusters
Hierarchical clustering
Density-based clustering
2.5
1.5
y
0.5
2 2 2
y
1 1 1
0 0 0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x x x
2 2 2
y
1 1 1
0 0 0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x x x
A1 A2
O1 1 2
O2 2 3
O3 3 4
O4 8 9
O5 9 10
A1 A2
O1 1 2
O2 2 3
O3 3 4
O4 8 9
O5 9 10
1. Select initial centroids (seeds) (given):
Dist S1 S2
S1 = <1, 3>
O1 1 3.16
S2 = <2, 5> O2 1 2
2. Calculate Euclidean distance to centroids: O3 2.23 1.41
Distance(O1, S1) = √((1-1)2 + (2-3)2) = 1 O4 9.21 7.21
Distance(O1, S2) = √((1-2)2 + (2-5)2) = √10 = 3.16 O5 10.6 8.60
3
…
A1 A2 Cluster
O1 1 2 O1 1
O2 2 3 O2 1
O3 3 4 O3 2
O4 8 9 O4 2
O5 9 10 O5 2
3. Assign objects to nearest centroid
Dist S1 S2
S1 = <O1, O2>
O1 1 3.16
S2 = <O3, O4, O5> O2 1 2
O3 2.23 1.41
O4 9.21 7.21
O5 10.6 8.60
3
A1 A2 Cluster
O1 1 2 O1 1
O2 2 3 O2 1
O3 3 4 O3 2
O4 8 9 O4 2
O5 9 10 O5 2
4. Recompute the centroid of each cluster
Dist S1 S2
S1 = < (1+2)/2 , (2+3)/2> = <1.5, 2.5>
O1 0.70 8.00
S2 = < (3+8+9)/3 , (4+9+10)/3> = <6.66, 7.66> O2 0.70 6.59
5. Calculate Euclidean distance to centroids: O3 2.12 4.17
Distance(O1, S1) = √((1-1.5)2 + (2-2.5)2) = √.5 = 0.70 O4 9.19 1.89
Distance(O1, S2) = √((1-6.66)2 + (2-7.66)2) = 8.00 O5 10.6 3.30
0
A1 A2 Cluster
O1 1 2 O1 1
O2 2 3 O2 1
O3 3 4 O3 1
O4 8 9 O4 2
O5 9 10 O5 2
A1 A2 Cluster
O1 1 2 O1 1
O2 2 3 O2 1
O3 3 4 O3 1
O4 8 9 O4 2
O5 9 10 O5 2
A1 A2 Cluster
O1 1 2 O1 1
O2 2 3 O2 1
O3 3 4 O3 1
O4 8 9 O4 2
O5 9 10 O5 2
2.5
2
Original Points
1.5
y
1
0.5
3 3
2.5 2.5
2 2
1.5 1.5
y
y
1 1
0.5 0.5
0 0
2.5
1.5
y
0.5
Iteration 1 Iteration 2
3 3
2.5 2.5
2 2
1.5 1.5
y
y
1 1
0.5 0.5
0 0
2 2 2
y
1 1 1
0 0 0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x x x
Depending on the
choice of initial
centroids, B and C
may get merged or
remain separate
Iteration 4
1
2
3
8
2
y
-2
-4
-6
0 5 10 15 20
x
Starting with two initial centroids in one cluster of each pair of clusters
11/16/2020 Introduction to Data Mining, 2nd Edition 34
Tan, Steinbach, Karpatne, Kumar
10 Clusters Example
Iteration 1 Iteration 2
8 8
6 6
4 4
2 2
y
y
0 0
-2 -2
-4 -4
-6 -6
0 5 10 15 20 0 5 10 15 20
x x
Iteration 3 Iteration 4
8 8
6 6
4 4
2 2
y
y
0 0
-2 -2
-4 -4
-6 -6
0 5 10 15 20 0 5 10 15 20
x x
Starting with two initial centroids in one cluster of each pair of clusters
11/16/2020 Introduction to Data Mining, 2nd Edition 35
Tan, Steinbach, Karpatne, Kumar
10 Clusters Example
Iteration 4
1
2
3
8
2
y
-2
-4
-6
0 5 10 15 20
x
Starting with some pairs of clusters having three initial centroids, while other
have only one.
6 6
4 4
2 2
y
y
0 0
-2 -2
-4 -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
y
0 0
-2 -2
-4 -4
-6 -6
0 5 10 15 20 0 5 10 15 20
x x
Starting with some pairs of clusters having three initial centroids, while other have only
one.
11/16/2020 Introduction to Data Mining, 2nd Edition 37
Tan, Steinbach, Karpatne, Kumar
Solutions to Initial Centroids Problem
Multiple runs
– Helps, but probability is not on your side
Use some strategy to select the k initial centroids
and then select among these initial centroids
– Select most widely separated
K-means++ is a robust way of doing this selection
– Use hierarchical clustering to determine initial
centroids
Bisecting K-means
– Not as susceptible to initialization issues
Pre-processing
– Normalize the data
– Eliminate outliers
Post-processing
– Eliminate empty clusters and 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
– These steps can be used multiple times during the
clustering process
ISODATA
6.8 13 18
6.5
X 9 10
X 15 16
X18.5
6.5
X 9 10
X 15 16
X 18.5
Empty
Cluster
Several strategies
– Choose the point that contributes most to SSE, and
make it a new centroid
– Choose a point from the cluster with the highest SSE,
and make it a new centroid
– If there are several empty clusters, the above can be
repeated several times.
CLUTO: [Link]
6 5
0.2
4
3 4
0.15
2
5
2
0.1
1
0.05 1
3
0
1 3 2 5 4 6
– Divisive:
Start with one, all-inclusive cluster
At each step, split a cluster until each cluster contains an individual
point (or there are k clusters)
p2
p3
p4
p5
.
.
. Proximity Matrix
...
p1 p2 p3 p4 p9 p10 p11 p12
C2
C3
C3
C4
C4
C5
Proximity Matrix
C1
C2 C5
...
p1 p2 p3 p4 p9 p10 p11 p12
We want to merge the two closest clusters (C2 and C5) and
update the proximity matrix. C1 C2 C3 C4 C5
C1
C2
C3
C3
C4
C4
C5
Proximity Matrix
C1
C2 C5
...
p1 p2 p3 p4 p9 p10 p11 p12
C1 ?
C2 U C5 ? ? ? ?
C3
C3 ?
C4
C4 ?
Proximity Matrix
C1
C2 U C5
...
p1 p2 p3 p4 p9 p10 p11 p12
p3
p4
p5
MIN
.
MAX .
Group Average .
Proximity Matrix
Distance Between Centroids
Other methods driven by an objective
function
– Ward’s Method uses squared error
p2
p3
p4
p5
MIN
.
MAX .
Group Average .
Proximity Matrix
Distance Between Centroids
Other methods driven by an objective
function
– Ward’s Method uses squared error
p2
p3
p4
p5
MIN
.
MAX .
Group Average .
Proximity Matrix
Distance Between Centroids
Other methods driven by an objective
function
– Ward’s Method uses squared error
p2
p3
p4
p5
MIN
.
MAX .
Group Average .
Proximity Matrix
Distance Between Centroids
Other methods driven by an objective
function
– Ward’s Method uses squared error
p2
p3
p4
p5
MIN
.
MAX .
Group Average .
Proximity Matrix
Distance Between Centroids
Other methods driven by an objective
function
– Ward’s Method uses squared error
5
1
3
5 0.2
2 1 0.15
2 3 6 0.1
0.05
4
4 0
3 6 2 5 4 1
Two Clusters
Original Points
Distance Matrix:
4 1
2 5 0.4
0.35
5
2 0.3
0.25
3 6 0.2
3 0.15
1 0.1
4 0.05
0
3 6 4 1 2 5
p jClusterj
proximity(Clusteri , Clusterj )
|Clusteri ||Clusterj |
5 4 1
2 0.25
5 0.2
2
0.15
3 6 0.1
1 0.05
4 0
3 3 6 4 1 2 5
Strengths
– Less susceptible to noise and outliers
Limitations
– Biased towards globular clusters
5
1 4 1
3
2 5
5 5
2 1 2
MIN MAX
2 3 6 3 6
3
1
4 4
4
5
1 5 4 1
2 2
5 Ward’s Method 5
2 2
3 6 Group Average 3 6
3
4 1 1
4 4
3
MinPts = 7
• Resistant to Noise
• Can handle clusters of different shapes and sizes
Original Points
(MinPts=4, Eps=9.92).
Original Points
• Varying densities
• High-dimensional data
(MinPts=4, Eps=9.75)
11/16/2020 Introduction to Data Mining, 2nd Edition 88
Tan, Steinbach, Karpatne, Kumar
DBSCAN: Determining EPS and MinPts
0.9 0.9
0.8 0.8
0.7 0.7
0.5
y
0.4 0.4
0.3 0.3
0.2 0.2
0.1 0.1
0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
x x
1 1
0.9 0.9
0.5 0.5
y
0.4 0.4
0.3 0.3
0.2 0.2
0.1 0.1
0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
x x
11/16/2020 Introduction to Data Mining, 2nd Edition 91
Tan, Steinbach, Karpatne, Kumar
Different Aspects of Cluster Validation
1
1
10 0.9
0.9
20 0.8
0.8
30 0.7
0.7
40 0.6
0.6
Points
50 0.5
0.5
y
60 0.4
0.4
70 0.3
0.3
80 0.2
0.2
90 0.1
0.1
100 0
0 20 40 60 80 100Similarity
0 0.2 0.4 0.6 0.8 1
Points
x
10
6 9
8
4
7
2 6
SSE
0 5
4
-2
3
-4 2
-6 1
5 10 15 0
2 5 10 15 20 25 30
K
1
2 6
3
4
𝑖 𝑥 ∈𝐶
– Separation 𝑖is measured by the between cluster sum of squares
𝑆𝑆𝐵=∑ |𝐶 𝑖|( 𝑚− 𝑚𝑖 )
2
𝑖
Where is the size of cluster i
Example: SSE
– SSB + SSE = constant
m
1 m1 2 3 4 m2 5
cohesion separation
• Purity(cluster 1) = 53 / 63 = 0.84
• Purity(cluster 2) = 60 / 66 = 0.909
• Purity(cluster 3) = 16 / 16 = 1
• Total Purity = (63/145) * 0.84 + (66/145) * 0.909 + (16/145) * 1
• = 0.36 + 0.41 + 0.11 = 0.88
• Entropy(cluster 1) = - 0 log2 0 - (53/63) log2 (53/63) - (10/63) log2 (10/63) = 0 + 0.209 + 0.421 = 0.63
• Entropy(cluster 2) = - (5/66) log2 (5/66) – (1/66) log2 (1/66) – (60/66) log2 (60/66) =0.28 + 0.09 + 0.12 = 0.49
• Entropy(cluster 3) = - 0 log2 0 - (16/16) log2 (16/16) - 0 log2 0 = 0
• Total Entropy= (63/145) * 0.63 + (66/145) * 0.49 + (16/145) * 0 = 0.49