Clustering
Clustering
Monday, 11/4/2019
1 / 24
Overview
Why clustering?
Performance measure
Distance measure
Prototype-based clustering
K-means
Learning vector quantization (LVQ)
Density-based clustering
Density-based spatial clustering of applications with noise (DBSCAN)
Hierarchical clustering
Overview 2 / 24
Clustering
Why Clustering? 3 / 24
Setting
Performance Measure 4 / 24
Performance Measure
Performance Measure 5 / 24
Performance Measure
Davies-Bouldin Index:
Dunn Index:
Performance Measure 6 / 24
Distance Measure
Distance Measure 7 / 24
Mathematicians’ Fate
Distance Measure 8 / 24
Distance Measure
|xiu − xju |p +
P P
MinkovDMp (xi , xj ) = VDMp (xiu , xju )
u=1 u=nc +1
Distance Measure 9 / 24
K-Means
Prototype-based Clustering 10 / 24
K-Means Algorithm
Algorithm 1: K-Means
Input: Dataset D = {x1 , . . . , xm }, number of clusters k
Output: Clustering C = {C1 , . . . , Ck }
1 Randomly pick k examples as the initial mean vector {µ1 , . . . , µk };
2 repeat
3 Ci ← ∅ for all 1 ≤ i ≤ k;
4 for j = 1, . . . , m do
5 dji ← ||xj − µi ||2 ;
6 λj ← argmin dji ;
i∈{1,...,k}
7 Cλj ← Cλj ∪ {xj };
8 end
9 for i = 1, . . . ,P
k do
10 µ0i = |C1i | x;
x∈Ci
11 if µ0i 6= µi then
12 µi ← µ0i ;
13 end
14 end
15 until No updates on µi ’s;
Prototype-based Clustering 12 / 24
K-Means Algorithm: Watermelon Dataset
Prototype-based Clustering 13 / 24
Learning Vector Quantization (LVQ)
Prototype-based Clustering 14 / 24
LVQ Algorithm
Algorithm 2: Learning Vector Quantization
Input: Dataset D = {(x1 , y1 ), . . . , (xm , ym )}, number of prototype vectors
q, labels of prototype vectors {t1 , . . . , tq }, learning rate 0 < η < 1
Output: Prototype vectors {p1 , . . . , pq }
1 Initialize the prototype vectors {p1 , . . . , pq };
2 repeat
3 Radomly pick example (xj , yj ) from D;
4 For each pi , dji ← ||xj − pi ||2 ;
5 pi ← argmin dji ;
i∈{1,...,q}
6 if yj = ti then
7 p 0 ← pi + η · (xj − pi );
8 else
9 p 0 ← pi − η · (xj − pi );
10 end
11 pi ← p 0 ;
12 until Stopping criteria;
Prototype-based Clustering 18 / 24
LVQ Algorithm: Watermelon Dataset
Sold circles are good melons, hollow circles are bad melons, and
pluses are the prototype vectors learned.
Prototype-based Clustering 19 / 24
Agglomerative Nesting (AGNES)
Hierarchical Clustering 20 / 24
Agglomerative Nesting (AGNES)
Hierarchical Clustering 21 / 24
AGNES Algorithm
Algorithm 5: AGNES
Input: Dataset D = {x1 , . . . , xm }, number of clusters k, distance function
d
Output: Clustering C = {C1 , . . . , Ck }
1 Cj ← {xj } for all 1 ≤ j ≤ m;
2 for i ← 1, . . . , m do
3 for j ← i + 1, . . . , m do
4 M(i, j) ← d(Ci , Cj );
5 M(j, i) ← M(i, j);
6 end
7 end
8 q ← m;
9 while q > k do
10 Find the two closest clusters Ci and Cj ;
11 Merge Ci and Cj : Ci = Ci ∪ Cj ;
12 Rename Cp to Cp−1 for all j + 1 ≤ p ≤ q;
13 Remove the j-th row and column from matrix M;
14 for p ← 1, . . . , q − 1 do
15 M(i, p) ← d(Ci , Cp );
16 M(p, i) ← M(i, p);
17 end
18 q ← q − 1;
19 end
Hierarchical Clustering 24 / 24