Chapter4 Clustering Compressed
Chapter4 Clustering Compressed
Document clustering
Motivations
Document representations
Success criteria
Clustering algorithms
Partitional
Hierarchical
Ch. 16
WHAT IS CLUSTERING?
Clustering: the process of grouping a set of objects into classes of
similar objects
Documents within a cluster should be similar.
Documents from different clusters should be
dissimilar.
The commonest form of unsupervised learning
Unsupervised learning = learning from raw data, as
opposed to supervised data where a classification of
examples is given
A common and important task that finds many applications in IR and other places
Ch. 16
APPLICATIONS OF CLUSTERING IN IR
Flat algorithms
Usually start with a random (partial) partitioning
Refine it iteratively
K means clustering
(Model based clustering)
Hierarchical algorithms
Bottom-up, agglomerative
(Top-down, divisive)
HARD VS. SOFT CLUSTERING
Hard clustering: Each document belongs to exactly one
cluster
More common and easier to do
Soft clustering: A document can belong to more than one
cluster.
Makes more sense for applications like creating browsable
hierarchies
You may want to put a pair of sneakers in two clusters: (i)
sports apparel and (ii) shoes
You can only do that with a soft clustering approach.
We won’t do soft clustering today. See IIR 16.5, 18
PARTITIONING ALGORITHMS
K-MEANS
Assumes documents are real-valued vectors.
Clusters based on centroids (aka the center of gravity or mean) of
points in a cluster, c: 1
μ(c) =
|c|
x
xc
K-MEANS ALGORITHM
Select K random docs {s1, s2,… sK} as seeds.
Until clustering converges (or other stopping criterion):
For each doc di:
Assign di to the cluster cj such that dist(xi, sj) is minimal.
(Next, update the seeds to the centroid of each cluster)
For each cluster cj
sj = (cj)
Sec. 16.4
K MEANS EXAMPLE
(K=2) Pick seeds
Reassign clusters
Compute centroids
Reassign clusters
x x Compute centroids
x
x
Reassign clusters
Converged!
Sec. 16.4
TERMINATION CONDITIONS
CONVERGENCE
CONVERGENCE OF K-MEANS
CONVERGENCE OF K-MEANS
Recomputation monotonically decreases each Gk
since (mk is number of members in cluster k):
Σ (di – a)2 reaches minimum for:
Σ –2(di – a) = 0
Σ di = Σ a
mK a = Σ di
a = (1/ mk) Σ di = ck
K-means typically converges quickly
Sec. 16.4
TIME COMPLEXITY
Computing distance between two docs is O(M) where M is the
dimensionality of the vectors.
Reassigning clusters: O(KN) distance computations, or O(KNM).
Computing centroids: Each doc gets added once to some centroid:
O(NM).
Assume these two steps are each done once for I iterations: O(IKNM).
Sec. 16.4
SEED CHOICE
Results can vary based on random seed selection. Example showing
Some seeds can result in poor convergence rate, or sensitivity to seeds
convergence to sub-optimal clusterings.
Select good seeds using a heuristic (e.g., doc least similar to
any existing mean)
Try out multiple starting points
Initialize with the results of another method. In the above, if you start
with B and E as centroids
you converge to {A,B,C}
and {D,E,F}
If you start with D and F
you converge to
{A,B,D,E} {C,F}
Sec. 16.4
Can usually take an algorithm for one flavor and convert to the other.
K NOT SPECIFIED IN ADVANCE
HIERARCHICAL CLUSTERING
Build a tree-based hierarchical taxonomy
(dendrogram) from a set of documents.
animal
vertebrate invertebrate
Clustering
obtained by
cutting the
dendrogram at a
desired level:
each connected
component
forms a cluster.
32
Sec. 17.1
HIERARCHICAL AGGLOMERATIVE
CLUSTERING (HAC)
Starts with each doc in a separate
cluster
then repeatedly joins the closest pair of
clusters, until there is only one cluster.
The history of merging forms a binary
tree or hierarchy.
Note: the resulting clusters are still “hard” and induce a partition
Sec. 17.2
Complete-link
Similarity of the “furthest” points, the least cosine-similar
Centroid
Clusters whose centroids (centers of gravity) are the most cosine-similar
Average-link
Average cosine between pairs of elements
Sec. 17.2
COMPLETE LINK
xci , yc j
COMPUTATIONAL COMPLEXITY
In the first iteration, all HAC methods need to compute similarity of all
pairs of N initial instances, which is O(N2).
In each of the subsequent N−2 merging iterations, compute the
distance between the most recently created cluster and all other
existing clusters.
In order to maintain an overall O(N2) performance, computing
similarity to each other cluster must be done in constant time.
Often O(N3) if done naively or O(N2 log N) if done more cleverly
Sec. 17.3
GROUP AVERAGE
( s (ci ) + s (c j )) • ( s (ci ) + s (c j )) − (| ci | + | c j |)
sim(ci , c j ) =
(| ci | + | c j |)(| ci | + | c j | −1)
Sec. 16.3
PURITY EXAMPLE
• • • • • •
• • • • • •
• • • • •
Same class in
ground truth 20 24
Different
classes in 20 72
ground truth
Sec. 16.3
A+ D
RI =
A+ B +C + D
Compare with standard Precision and Recall:
A
P=
A
R=
A+ B
A+C
People also define and use a cluster F-
measure, which is probably a better measure.
FINAL WORD AND RESOURCES
Resources
IIR 16 except 16.5
IIR 17.1–17.3