Flat Clustering Adapted from Slides by Prabhakar Raghavan
Flat Clustering Adapted from Slides by Prabhakar Raghavan, Christopher Manning, Ray Mooney and Soumen Chakrabarti Prasad L 16 Flat. Cluster 1
Today’s Topic: Clustering n Document clustering Motivations n Document representations n Success criteria n n Clustering algorithms Partitional (Flat) n Hierarchical (Tree) n Prasad L 16 Flat. Cluster 2
What is clustering? n Clustering: the process of grouping a set of objects into classes of similar objects n n n 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 n n Prasad L 16 Flat. Cluster 3
A data set with clear cluster structure n How would you design an algorithm for finding the three clusters in this case?
Why cluster documents? n Whole corpus analysis/navigation n n For improving recall in search applications n n Better search results (pseudo RF) For better navigation of search results n n Better user interface Effective “user recall” will be higher For speeding up vector space retrieval n Prasad Faster search L 16 Flat. Cluster 5
Yahoo! Hierarchy isn’t clustering but is the kind of output you want from clustering www. yahoo. com/Science … (30) agriculture. . . biology physics. . . CS. . . dairy space. . . botany cell AI courses crops magnetism HCI agronomy evolution forestry relativity Prasad L 16 Flat. Cluster . . . craft missions 6
Google News: automatic clustering gives an effective news presentation metaphor
Scatter/Gather: Cutting, Karger, and Pedersen
For visualizing a document collection and its themes n n Wise et al, “Visualizing the non-visual” PNNL Theme. Scapes, Cartia n [Mountain height = cluster size]
For improving search recall n n Cluster hypothesis - Documents in the same cluster behave similarly with respect to relevance to information needs Therefore, to improve search recall: n n n Cluster docs in corpus a priori When a query matches a doc D, also return other docs in the cluster containing D Example: The query “car” will also return docs containing automobile n Because clustering grouped together docs containing car with those containing automobile. Prasad Why might this happen? 10
For better navigation of search results n For grouping search results thematically n clusty. com / Vivisimo Prasad L 16 Flat. Cluster 11
Issues for clustering n Representation for clustering n Document representation n Vector space? Normalization? Need a notion of similarity/distance How many clusters? n n Fixed a priori? Completely data driven? n Prasad Avoid “trivial” clusters - too large or small L 16 Flat. Cluster 12
What makes docs “related”? n n Ideal: semantic similarity. Practical: statistical similarity Docs as vectors. n For many algorithms, easier to think in terms of a distance (rather than similarity) between docs. n We can use cosine similarity (alternatively, Euclidean Distance). n Prasad L 16 Flat. Cluster 13
Clustering Algorithms n Partitional (Flat) algorithms n n Usually start with a random (partial) partition Refine it iteratively n n n K means clustering (Model based clustering) Hierarchical (Tree) algorithms n n Prasad Bottom-up, agglomerative (Top-down, divisive) L 16 Flat. Cluster 14
Hard vs. soft clustering n n Hard clustering: Each document belongs to exactly one cluster n More common and easier to do Soft clustering: A document can belong to more than one cluster. n Makes more sense for applications like creating browsable hierarchies n You may want to put a pair of sneakers in two clusters: (i) sports apparel and (ii) shoes
Partitioning Algorithms n n n Partitioning method: Construct a partition of n documents into a set of K clusters Given: a set of documents and the number K Find: a partition of K clusters that optimizes the chosen partitioning criterion n n Prasad Globally optimal: exhaustively enumerate all partitions Effective heuristic methods: K-means and Kmedoids algorithms L 16 Flat. Cluster 16
K-Means n n n Assumes documents are real-valued vectors. Clusters based on centroids (aka the center of gravity or mean) of points in a cluster, c. Reassignment of instances to clusters is based on distance to the current cluster centroids. n Prasad (Or one can equivalently phrase it in terms of similarities) L 16 Flat. Cluster 17
K-Means Algorithm Select K random docs {s 1, s 2, … s. K} 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. (Update the seeds to the centroid of each cluster) For each cluster cj sj = (cj) Prasad L 16 Flat. Cluster 18
K Means Example (K=2) Pick seeds x x Reassign clusters Compute centroids Reassign clusters Converged! Prasad L 16 Flat. Cluster 19
Termination conditions n Several possibilities, e. g. , A fixed number of iterations. n Doc partition unchanged. n Centroid positions don’t change. n Prasad Does this mean that the docs in a cluster are unchanged? 20
Convergence n Why should the K-means algorithm ever reach a fixed point? n n A state in which clusters don’t change. K-means is a special case of a general procedure known as the Expectation Maximization (EM) algorithm. n n Prasad EM is known to converge. Number of iterations could be large. L 16 Flat. Cluster 21
Lower case Convergence of K-Means n Define goodness measure of cluster k as sum of squared distances from cluster centroid: n n n Gk = Σi (di – ck)2 (sum over all di in cluster k) G = Σk G k Intuition: Reassignment monotonically decreases G since each vector is assigned to the closest centroid. Prasad L 16 Flat. Cluster 22
Time Complexity n n 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). Prasad L 16 Flat. Cluster 24
Seed Choice n n Results can vary based on random seed selection. Some seeds can result in poor convergence rate, or convergence to sub-optimal clusterings. n n n Prasad 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. L 16 Flat. Cluster Example showing sensitivity to seeds 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}. 25
K-means issues, variations, etc. n n Recomputing the centroid after every assignment (rather than after all points are reassigned) can improve speed of convergence of K-means Assumes clusters are spherical in vector space n n Sensitive to coordinate changes, weighting etc. Disjoint and exhaustive n n Prasad Doesn’t have a notion of “outliers” But can add outlier filtering L 16 Flat. Cluster 26
How Many Clusters? n Number of clusters K is given n Partition n docs into predetermined number of clusters n Finding the “right” number of clusters is part of the problem n n Prasad Given docs, partition into an “appropriate” number of subsets. E. g. , for query results - ideal value of K not known up front - though UI may impose limits. L 16 Flat. Cluster 27
Hierarchical Clustering Adapted from Slides by Prabhakar Raghavan, Christopher Manning, Ray Mooney and Soumen Chakrabarti Prasad L 17 Hier. Cluster 28
“The Curse of Dimensionality” n Why document clustering is difficult n n While clustering looks intuitive in 2 dimensions, many of our applications involve 10, 000 or more dimensions… High-dimensional spaces look different n n Prasad The probability of random points being close drops quickly as the dimensionality grows. Furthermore, random pair of vectors are all almost perpendicular. L 17 Hier. Cluster 29
Hierarchical Clustering n Build a tree-based hierarchical taxonomy (dendrogram) from a set of documents. animal vertebrate invertebrate fish reptile amphib. mammal n worm insect crustacean One approach: recursive application of a partitional clustering algorithm. Prasad L 17 Hier. Cluster 30
Dendogram: Hierarchical Clustering • Clustering obtained by cutting the dendrogram at a desired level: each connected component forms a cluster. Prasad L 17 Hier. Cluster 31
Hierarchical Clustering algorithms n n Agglomerative (bottom-up): n Precondition: Start with each document as a separate cluster. n Postcondition: Eventually all documents belong to the same cluster. Divisive (top-down): n n Precondition: Start with all documents belonging to the same cluster. Postcondition: Eventually each document forms a cluster of its own. n Does not require the number of clusters k in advance. n Needs a termination/readout condition Prasad L 17 Hier. Cluster 32
Hierarchical Agglomerative Clustering (HAC) Algorithm Start with all instances in their own cluster. Until there is only one cluster: Among the current clusters, determine the two clusters, ci and cj, that are most similar. Replace ci and cj with a single cluster ci cj Prasad L 17 Hier. Cluster 33
Dendrogram: Document Example n As clusters agglomerate, docs likely to fall into a hierarchy of “topics” or concepts. d 3 d 5 d 1 d 2 Prasad d 3, d 4, d 5 d 4 d 1, d 2 L 17 Hier. Cluster d 4, d 5 d 3 34
Key notion: cluster representative n n We want a notion of a representative point in a cluster, to represent the location of each cluster Representative should be some sort of “typical” or central point in the cluster, e. g. , n n n point inducing smallest radii to docs in cluster smallest squared distances, etc. point that is the “average” of all docs in the cluster n n Prasad Centroid or center of gravity Measure intercluster distances by distances of centroids. L 17 Hier. Cluster 35
Example: n=6, k=3, closest pair of centroids d 6 d 4 d 3 d 5 Centroid after second step. d 1 Prasad d 2 Centroid after first step. 36
Outliers in centroid computation n n Can ignore outliers when computing centroid. What is an outlier? n Lots of statistical definitions, e. g. n moment of point to centroid > M some cluster moment. Say 10. Centroid Outlier Prasad L 17 Hier. Cluster 37
Closest pair of clusters n n Many variants to defining closest pair of clusters Single-link n n Complete-link n n Similarity of the “furthest” points, the least cosinesimilar Centroid n n Similarity of the most cosine-similar (single-link) Clusters whose centroids (centers of gravity) are the most cosine-similar Average-link n Average cosine between pairs of elements 38
Single Link Agglomerative Clustering n n n Use maximum similarity of pairs: Can result in “straggly” (long and thin) clusters due to chaining effect. After merging ci and cj, the similarity of the resulting cluster to another cluster, ck, is: Prasad L 17 Hier. Cluster 39
Single Link Example Prasad L 17 Hier. Cluster 40
Complete Link Agglomerative Clustering n n n Use minimum similarity of pairs: Makes “tighter, ” spherical clusters that are typically preferable. After merging ci and cj, the similarity of the resulting cluster to another cluster, ck, is: Prasad Ci Cj Ck 41
Complete Link Example Prasad L 17 Hier. Cluster 42
Computational Complexity n n n In the first iteration, all HAC methods need to compute similarity of all pairs of n individual instances which is O(n 2). 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(n 2) performance, computing similarity to each cluster must be done in constant time. n Prasad Often O(n 3) if done naively or O(n 2 log n) if done more cleverly L 17 Hier. Cluster 43
Group Average Agglomerative Clustering n Use average similarity across all pairs within the merged cluster to measure the similarity of two clusters. n Compromise between single and complete link. n Two options: Averaged across all ordered pairs in the merged cluster n Averaged over all pairs between the two original clusters No clear difference in efficacy n n Prasad L 17 Hier. Cluster 44
Computing Group Average Similarity n Assume cosine similarity and normalized vectors with unit length. Always maintain sum of vectors in each cluster. n Compute similarity of clusters in constant time: n Prasad L 17 Hier. Cluster 45
Medoid as Cluster Representative n n n The centroid does not have to be a document. Medoid: A cluster representative that is one of the documents (E. g. , the document closest to the centroid) One reason this is useful n n Consider the representative of a large cluster (>1 K docs) The centroid of this cluster will be a dense vector The medoid of this cluster will be a sparse vector Compare: mean/centroid vs. median/medoid Prasad L 17 Hier. Cluster 46
Efficiency: “Using approximations” n n In standard algorithm, must find closest pair of centroids at each step Approximation: instead, find nearly closest pair n n use some data structure that makes this approximation easier to maintain simplistic example: maintain closest pair based on distances in projection on a random line Random line Prasad 47
Major issue - labeling n n After clustering algorithm finds clusters - how can they be useful to the end user? Need pithy label for each cluster n n Prasad In search results, say “Animal” or “Car” in the jaguar example. In topic trees (Yahoo), need navigational cues. n Often done by hand, a posteriori. L 17 Hier. Cluster 48
How to Label Clusters n Show titles of typical documents n n Titles are easy to scan Authors create them for quick scanning! But you can only show a few titles which may not fully represent cluster Show words/phrases prominent in cluster n n More likely to fully represent cluster Use distinguishing words/phrases n Prasad Differential labeling L 17 Hier. Cluster 49
Labeling n Common heuristics - list 5 -10 most frequent terms in the centroid vector. n n Differential labeling by frequent terms n n n Drop stop-words; stem. Within a collection “Computers”, clusters all have the word computer as frequent term. Discriminant analysis of centroids. Perhaps better: distinctive noun phrase Prasad L 17 Hier. Cluster 50
What is a Good Clustering? n Internal criterion: A good clustering will produce high quality clusters in which: n n n the intra-class (that is, intra-cluster) similarity is high the inter-class similarity is low The measured quality of a clustering depends on both the document representation and the similarity measure used Prasad L 17 Hier. Cluster 51
External criteria for clustering quality n n Quality measured by its ability to discover some or all of the hidden patterns or latent classes in gold standard data Assesses a clustering with respect to ground truth … requires labeled data n Prasad Assume documents with C gold standard classes, while our clustering algorithms produce K clusters, ω1, ω2, …, ωK with ni members. L 17 Hier. Cluster 52
External Evaluation of Cluster Quality n n Simple measure: purity, the ratio between the dominant class in the cluster πi and the size of cluster ωi Others are entropy of classes in clusters (or mutual information between classes and clusters) Prasad L 17 Hier. Cluster 53
Purity example Cluster III Cluster I: Purity = 1/6 * (max(5, 1, 0)) = 5/6 Cluster II: Purity = 1/6 * (max(1, 4, 1)) = 4/6 Cluster III: Purity = 1/5 * (max(2, 0, 3)) = 3/5 54
Rand Index Number of points Same Cluster in clustering Different Clusters in clustering Same class in ground truth A C Different classes in ground truth B D
Rand index: symmetric version Compare with standard Precision and Recall. Prasad L 17 Hier. Cluster 56
Rand Index example: 0. 68 Number of points Same Cluster in clustering Different Clusters in clustering Same class in ground truth 20 24 Different classes in ground truth 20 72
Final word and resources n n In clustering, clusters are inferred from the data without human input (unsupervised learning) However, in practice, it’s a bit less clear: there are many ways of influencing the outcome of clustering: number of clusters, similarity measure, representation of documents, . . .
SKIP WHAT FOLLOWS Prasad L 17 Hier. Cluster 59
Term vs. document space n n So far, we clustered docs based on their similarities in term space For some applications, e. g. , topic analysis for inducing navigation structures, can “dualize” n n Prasad use docs as axes represent (some) terms as vectors proximity based on co-occurrence of terms in docs now clustering terms, not docs L 17 Hier. Cluster 60
Term vs. document space n Cosine computation n Cluster labeling n n Constant for docs in term space Grows linearly with corpus size for terms in doc space Clusters have clean descriptions in terms of noun phrase co-occurrence Application of term clusters Prasad L 17 Hier. Cluster 61
Multi-lingual docs n n E. g. , Canadian government docs. Every doc in English and equivalent French. n n Simplest: pad docs in one language with dictionary equivalents in the other n n Must cluster by concepts rather than language thus each doc has a representation in both languages Axes are terms in both languages Prasad L 17 Hier. Cluster 62
Feature selection n n Which terms to use as axes for vector space? IDF is a form of feature selection n Better to use highest weight mid-frequency words – the most discriminating terms Pseudo-linguistic heuristics, e. g. , n n Can exaggerate noise e. g. , mis-spellings drop stop-words stemming/lemmatization use only nouns/noun phrases Good clustering should “figure out” some of these Prasad L 17 Hier. Cluster 63
Evaluation of clustering n n n Perhaps the most substantive issue in data mining in general: n how do you measure goodness? Most measures focus on computational efficiency n Time and space For application of clustering to search: n Measure retrieval effectiveness Prasad L 17 Hier. Cluster 64
Approaches to evaluating n n Anecdotal Ground “truth” comparison n n Purely quantitative measures n n n Prasad Cluster retrieval Probability of generating clusters found Average distance between cluster members Microeconomic / utility L 17 Hier. Cluster 65
Anecdotal evaluation n Probably the commonest (and surely the easiest) n n “I wrote this clustering algorithm and look what it found!” No benchmarks, no comparison possible Any clustering algorithm will pick up the easy stuff like partition by languages Generally, unclear scientific value. Prasad L 17 Hier. Cluster 66
Ground “truth” comparison n Take a union of docs from a taxonomy & cluster n n Yahoo!, ODP, newspaper sections … Compare clustering results to baseline e. g. , 80% of the clusters found map “cleanly” to taxonomy nodes “Subjective” But is it the “right” answer? n There can be several equally right answers n n n For the docs given, the static prior taxonomy may be incomplete/wrong in places n Prasad the clustering algorithm may have gotten right things not in the static taxonomy 67
Microeconomic viewpoint n n Anything - including clustering - is only as good as the economic utility it provides For clustering: net economic gain produced by an approach (vs. another approach) Strive for a concrete optimization problem Examples n n recommendation systems clock time for interactive search n Prasad expensive L 17 Hier. Cluster 68
Evaluation example: Cluster retrieval n n n Ad-hoc retrieval Cluster docs in returned set Identify best cluster & only retrieve docs from it How do various clustering methods affect the quality of what’s retrieved? Concrete measure of quality: n n Precision as measured by user judgements for these queries Done with TREC queries Prasad L 17 Hier. Cluster 69
Evaluation n Compare two IR algorithms n n n 1. send query, present ranked results 2. send query, cluster results, present clusters Experiment was simulated (no users) n n n Prasad Results were clustered into 5 clusters Clusters were ranked according to percentage relevant documents Documents within clusters were ranked according to similarity to query L 17 Hier. Cluster 70
- Slides: 69