K Means Clustering
K Means Clustering
K Means Clustering
1 X
µ= · x
|S|
x∈S
1 X
µ= · x
|S|
x∈S
1 X
µ= · x
|S|
x∈S
Algorithm k -means
Require: Set of points X
1: Start with centers c1 , . . . , ck chosen arbitrarily from X
2: repeat
3: for each point xi ∈ X do
4: Assign xi to cluster Cj that minimizes ||xi − cj ||
5: end for
6: for each clusterPCj do
7: cj ← |C1j | · xi ∈Cj xi
8: end for
9: until cluster centers do not change
Time Complexity of k -means
Algorithm k -means
Require: Set of points X
1: Start with centers c1 , . . . , ck chosen arbitrarily from X
2: repeat
3: for each point xi ∈ X do
4: Assign xi to cluster Cj that minimizes ||xi − cj ||
5: end for
6: for each clusterPCj do
7: cj ← |C1j | · xi ∈Cj xi
8: end for
9: until cluster centers do not change
Time Complexity of k -means
Algorithm k -means
Require: Set of points X
1: Start with centers c1 , . . . , ck chosen arbitrarily from X
2: repeat
3: for each point xi ∈ X do
4: Assign xi to cluster Cj that minimizes ||xi − cj ||
5: end for
6: for each clusterPCj do
7: cj ← |C1j | · xi ∈Cj xi
8: end for
9: until cluster centers do not change
P
For what function g(., .), mean(S) minimizes x∈S g(x, c)
over all c?
A Suitable Cost Function
P
For what function g(., .), mean(S) minimizes x∈S g(x, c)
over all c?
Such g is called Bregman divergence that encompasses
many functions
A Suitable Cost Function
P
For what function g(., .), mean(S) minimizes x∈S g(x, c)
over all c?
Such g is called Bregman divergence that encompasses
many functions
One such g is squared Euclidean distance
P
For what function g(., .), mean(S) minimizes x∈S g(x, c)
over all c?
Such g is called Bregman divergence that encompasses
many functions
One such g is squared Euclidean distance
Algorithm k -means++
Require: Set of points X , parameter k
1: Select c1 randomly from X
2: C ← {c1 }
3: while (|C| ≠ k ) do
4: for each i = 1 to n do
5: cost(xi , C) ← minc∈C ||xi − c||2
6: end for P
7: cost(C) ← ni=1 cost(xi , C)
8: Sample a random point y ∈ X , selecting each xi w.p.
pi = cost(xi , C)/cost(C)
9: C ← C ∪ {y }
10: end while
11: Invoke Lloyd’s algorithm with C as the seed
Analysis of k -means++