Question? Leave a message!




Cluster Analysis

Cluster Analysis
Cluster Analysis www.ThesisScientist.comCluster Analysis  What is Cluster Analysis  Types of Data in Cluster Analysis  A Categorization of Major Clustering Methods  Partitioning Methods  Hierarchical Methods  DensityBased Methods  GridBased Methods  Subspace Clustering/Biclustering  ModelBased Clustering www.ThesisScientist.comWhat is Cluster Analysis  Finding groups of objects such that the objects in a group will be similar (or related) to one another and different from (or unrelated to) the objects in other groups Intercluster Intracluster distances are distances are maximized minimized www.ThesisScientist.comWhat is Cluster Analysis  Cluster: a collection of data objects  Similar to one another within the same cluster  Dissimilar to the objects in other clusters  Cluster analysis  Grouping a set of data objects into clusters  Clustering is unsupervised classification: no predefined classes  Clustering is used:  As a standalone tool to get insight into data distribution  Visualization of clusters may unveil important information  As a preprocessing step for other algorithms  Efficient indexing or compression often relies on clustering www.ThesisScientist.comSome Applications of Clustering  Pattern Recognition  Image Processing  cluster images based on their visual content  Bioinformatics  WWW and IR  document classification  cluster Weblog data to discover groups of similar access patterns www.ThesisScientist.comWhat Is Good Clustering  A good clustering method will produce high quality clusters with  high intraclass similarity  low interclass similarity  The quality of a clustering result depends on both the similarity measure used by the method and its implementation.  The quality of a clustering method is also measured by its ability to discover some or all of the hidden patterns. www.ThesisScientist.comRequirements of Clustering in Data Mining  Scalability  Ability to deal with different types of attributes  Discovery of clusters with arbitrary shape  Minimal requirements for domain knowledge to determine input parameters  Able to deal with noise and outliers  Insensitive to order of input records  High dimensionality  Incorporation of userspecified constraints  Interpretability and usability www.ThesisScientist.comOutliers  Outliers are objects that do not belong to any cluster or form clusters of very small cardinality cluster outliers  In some applications we are interested in discovering outliers, not clusters (outlier www.ThesisScientist.com analysis)Data Structures attributes/dimensions  data matrix x ... x ... x  11 1f 1p   (two modes) ... ... ... ... ...   x ... x ... x i1 if ip  the “classic” data input ... ... ... ... ...   x ... x ... x n1 nf np   objects  dissimilarity or distance 0   matrix d(2,1) 0   d(3,1) d(3,2) 0  (one mode)  : : : Assuming simmetric distance   d(i,j) = d(j, i) d(n,1) d(n,2) ... ... 0  www.ThesisScientist.com objects tuples/objectsMeasuring Similarity in Clustering  Dissimilarity/Similarity metric:  The dissimilarity d(i, j) between two objects i and j is expressed in terms of a distance function, which is typically a metric:  d(i, j)0 (nonnegativity)  d(i, i)=0 (isolation)  d(i, j)= d(j, i) (symmetry)  d(i, j) ≤ d(i, h)+d(h, j) (triangular inequality)  The definitions of distance functions are usually different for intervalscaled, boolean, categorical, ordinal and ratioscaled variables.  Weights may be associated with different variables www.ThesisScientist.com based on applications and data semantics.Type of data in cluster analysis  Intervalscaled variables  e.g., salary, height  Binary variables  e.g., gender (M/F), hascancer(T/F)  Nominal (categorical) variables  e.g., religion (Christian, Muslim, Buddhist, Hindu, etc.)  Ordinal variables  e.g., military rank (soldier, sergeant, lutenant, captain, etc.)  Ratioscaled variables  population growth (1,10,100,1000,...)  Variables of mixed types www.ThesisScientist.com  multiple attributes with various typesSimilarity and Dissimilarity Between Objects  Distance metrics are normally used to measure the similarity or dissimilarity between two data objects  The most popular conform to Minkowski distance: 1/ p  p p p  L (i, j) xx xx ...xx  p  in jn i1 j1 i2 j2  where i = (x , x , …, x ) and j = (x , x , …, x ) are two i1 i2 in j1 j2 jn ndimensional data objects, and p is a positive integer  If p = 1, L is the Manhattan (or city block) 1 distance: L (i, j)xx xx ...xx i1 j1 i2 j2 in jn 1 www.ThesisScientist.comSimilarity and Dissimilarity Between Objects (Cont.)  If p = 2, L is the Euclidean distance: 2 2 2 2 d(i, j) (xx xx ...xx ) i1 j1 i2 j2 in jn  Properties d(i,j) 0 d(i,i) = 0 d(i,j) = d(j,i) d(i,j) d(i,k) + d(k,j)  Also one can use weighted distance: 2 2 2 d(i, j) (w xx w xx ...w xx ) n i1 j1 i2 j2 in jn 1 2 www.ThesisScientist.comBinary Variables  A binary variable has two states: 0 absent, 1 present  A contingency table for binary data object j 1 0 sum i= (0011101001) 1 a b ab J=(1001100110) 0 c d cd object i sum ac bd p  Simple matching coefficient distance (invariant, if the binary variable is symmetric): b c d(i, j)  a b c d  Jaccard coefficient distance (noninvariant if the binary b c variable is asymmetric): d(i, j)  a b c www.ThesisScientist.comBinary Variables  Another approach is to define the similarity of two objects and not their distance.  In that case we have the following:  Simple matching coefficient similarity: ad s(i, j) abcd  Jaccard coefficient similarity: a s(i, j) abc Note that: s(i,j) = 1 – d(i,j) www.ThesisScientist.comDissimilarity between Binary Variables  Example (Jaccard coefficient) Name Fever Cough Test1 Test2 Test3 Test4 Jack 1 0 1 0 0 0 Mary 1 0 1 0 1 0 Jim 1 1 0 0 0 0  all attributes are asymmetric binary  1 denotes presence or positive test  0 denotes absence or negative test 0 1 d( jack ,mary ) 0.33 2 0 1 1 1 d( jack , jim) 0.67 1 1 1 1 2 d( jim,mary ) 0.75 www.ThesisScientist.com 1 1 2A simpler definition  Each variable is mapped to a bitmap (binary vector) Name Fever Cough Test1 Test2 Test3 Test4 Jack 1 0 1 0 0 0 Mary 1 0 1 0 1 0 Jim 1 1 0 0 0 0  Jack: 101000  Mary: 101010  Jim: 110000  Simple match distance: number of non common bit positions d(i, j) total number of bits  Jaccard coefficient: number of 1's in i j d(i, j)1 www.ThesisScientist.com number of 1's in i j Variables of Mixed Types  A database may contain all the six types of variables  symmetric binary, asymmetric binary, nominal, ordinal, interval and ratioscaled.  One may use a weighted formula to combine their effects. p ( f ) ( f )  d f 1 ij ij d(i, j) p ( f )  f 1 ij www.ThesisScientist.comMajor Clustering Approaches  Partitioning algorithms: Construct random partitions and then iteratively refine them by some criterion  Hierarchical algorithms: Create a hierarchical decomposition of the set of data (or objects) using some criterion  Densitybased: based on connectivity and density functions  Gridbased: based on a multiplelevel granularity structure  Modelbased: A model is hypothesized for each of the clusters and the idea is to find the best fit of that model to www.ThesisScientist.com each otherPartitioning Algorithms: Basic Concept  Partitioning method: Construct a partition of a database D of n objects into a set of k clusters  kmeans (MacQueen’67): Each cluster is represented by the center of the cluster  kmedoids or PAM (Partition around medoids) (Kaufman Rousseeuw’87): Each cluster is represented by one of the objects in the cluster www.ThesisScientist.comKmeans Clustering  Partitional clustering approach  Each cluster is associated with a centroid (center point)  Each point is assigned to the cluster with the closest centroid  Number of clusters, K, must be specified  The basic algorithm is very simple www.ThesisScientist.comKmeans Clustering – Details  Initial centroids are often chosen randomly.  Clusters produced vary from one run to another.  The centroid is (typically) the mean of the points in the cluster.  ‘Closeness’ is measured by Euclidean distance, cosine similarity, correlation, etc.  Most of the convergence happens in the first few iterations.  Often the stopping condition is changed to ‘Until relatively few points change clusters’  Complexity is O( n K I d )  n = number of points, K = number of clusters, I = number of iterations, d = number of attributes www.ThesisScientist.comTwo different Kmeans Clusterings 3 2.5 2 Original Points 1.5 1 0.5 0 2 1.5 1 0.5 0 0.5 1 1.5 2 x 3 3 2.5 2.5 2 2 1.5 1.5 1 1 0.5 0.5 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 x x Optimal Clustering Suboptimal Clustering www.ThesisScientist.com y y yEvaluating Kmeans Clusters  For each point, the error is the distance to the nearest cluster  To get SSE, we square these errors and sum them. K 2 SSE dist (m , x)  i i1 xC i  x is a data point in cluster C and m is the i i representative point for cluster C i  can show that m corresponds to the center (mean) of the i cluster  Given two clusters, we can choose the one with the smallest error www.ThesisScientist.comSolutions to Initial Centroids Problem Multiple runs  Helps, but probability is not on your side Sample and use hierarchical clustering to determine initial centroids Select more than k initial centroids and then select among these initial centroids  Select most widely separated Postprocessing Bisecting Kmeans  Not as susceptible to initialization issues www.ThesisScientist.comLimitations of Kmeans Kmeans has problems when clusters are of differing  Sizes  Densities  Nonspherical shapes Kmeans has problems when the data contains outliers. Why www.ThesisScientist.comThe KMedoids Clustering Method  Find representative objects, called medoids, in clusters  PAM (Partitioning Around Medoids, 1987)  starts from an initial set of medoids and iteratively replaces one of the medoids by one of the nonmedoids if it improves the total distance of the resulting clustering  PAM works effectively for small data sets, but does not scale well for large data sets  CLARA (Kaufmann Rousseeuw, 1990)  CLARANS (Ng Han, 1994): Randomized sampling www.ThesisScientist.comPAM (Partitioning Around Medoids) (1987)  PAM (Kaufman and Rousseeuw, 1987), built in statistical package S+  Use a real object to represent the a cluster 1. Select k representative objects arbitrarily 2. For each pair of a nonselected object h and a selected object i, calculate the total swapping cost TC ih 3. For each pair of i and h,  If TC 0, i is replaced by h ih  Then assign each nonselected object to the most similar representative object 4. repeat steps 23 until there is no change www.ThesisScientist.comPAM Clustering: Total swapping cost TC =C ih j jih  i is a current medoid, h is a non selected object  Assume that i is replaced by h in the set of medoids  TC = 0; ih  For each nonselected object j ≠ h:  TC += d(j,newmed )d(j,prevmed ): ih j j newmed = the closest medoid to j after i is j replaced by h prevmed = the closest medoid to j before i j www.ThesisScientist.com is replaced by hPAM Clustering: Total swapping cost TC =C ih j jih 10 10 9 9 j 8 8 t t 7 7 6 6 j 5 5 4 4 h i h 3 3 i 2 2 1 1 0 0 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 C = 0 jih C = d(j, h) d(j, i) jih 10 10 9 9 8 8 h 7 7 j 6 6 5 i 5 4 i 4 h j t 3 3 2 2 t 1 1 0 0 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 www.ThesisScientist.com C = d(j, h) d(j, t) C = d(j, t) d(j, i) jih jihCLARA (Clustering Large Applications)  CLARA (Kaufmann and Rousseeuw in 1990)  Built in statistical analysis packages, such as S+  It draws multiple samples of the data set, applies PAM on each sample, and gives the best clustering as the output  Strength: deals with larger data sets than PAM  Weakness:  Efficiency depends on the sample size  A good clustering based on samples will not necessarily represent a good clustering of the whole data set if the www.ThesisScientist.com sample is biasedCLARANS (“Randomized” CLARA)  CLARANS (A Clustering Algorithm based on Randomized Search) (Ng and Han’94)  CLARANS draws sample of neighbors dynamically  The clustering process can be presented as searching a graph where every node is a potential solution, that is, a set of k medoids  If the local optimum is found, CLARANS starts with new randomly selected node in search for a new local optimum  It is more efficient and scalable than both PAM and CLARA  Focusing techniques and spatial access structures may further improve its performance (Ester et al.’95) www.ThesisScientist.comCluster Analysis  What is Cluster Analysis  Types of Data in Cluster Analysis  A Categorization of Major Clustering Methods  Partitioning Methods  Hierarchical Methods  DensityBased Methods  GridBased Methods  ModelBased Clustering Methods  Outlier Analysis  Summary www.ThesisScientist.comHierarchical Clustering  Use distance matrix as clustering criteria. This method does not require the number of clusters k as an input, but needs a termination condition Step 1 Step 2 Step 3 Step 4 Step 0 agglomerative (AGNES) a a b b a b c d e c c d e d d e e divisive www.ThesisScientist.com Step 3 Step 2 Step 1 Step 0 Step 4 (DIANA)AGNES (Agglomerative Nesting)  Implemented in statistical analysis packages, e.g., Splus  Use the SingleLink method and the dissimilarity matrix.  Merge objects that have the least dissimilarity  Go on in a nondescending fashion  Eventually all objects belong to the same cluster 10 10 10 9 9 9 8 8 8 7 7 7 6 6 6 5 5 5 4 4 4 3 3 3 2 2 2 1 1 1 0 0 0 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10  SingleLink: each time merge the clusters (C ,C ) which are 1 2 connected by the shortest single link of objects, i.e., www.ThesisScientist.com min dist(p,q) pC1,qC2A Dendrogram Shows How the Clusters are Merged Hierarchically Decompose data objects into d a several levels of nested e partitioning (tree of clusters), b a called a dendrogram. c A clustering of the data level 4 objects is obtained by cutting the dendrogram at the level 3 desired level, then each connected component forms a cluster. level 2 E.g., level 1 gives 4 clusters: level 1 a,b,c,d,e, level 2 gives 3 clusters: a,b,c,d,e level 3 gives 2 clusters: a b c d e a,b,c,d,e, etc. www.ThesisScientist.comDIANA (Divisive Analysis)  Implemented in statistical analysis packages, e.g., Splus  Inverse order of AGNES  Eventually each node forms a cluster on its own 10 10 10 9 9 9 8 8 8 7 7 7 6 6 6 5 5 5 4 4 4 3 3 3 2 2 2 1 1 1 0 0 0 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 www.ThesisScientist.comMore on Hierarchical Clustering Methods  Major weakness of agglomerative clustering methods 2  do not scale well: time complexity of at least O(n ), where n is the number of total objects  can never undo what was done previously  Integration of hierarchical with distancebased clustering  BIRCH (1996): uses CFtree and incrementally adjusts the quality of subclusters  CURE (1998): selects wellscattered points from the cluster and then shrinks them towards the center of the cluster by a specified fraction  CHAMELEON (1999): hierarchical clustering using dynamic www.ThesisScientist.com modelingBIRCH (1996)  Birch: Balanced Iterative Reducing and Clustering using Hierarchies, by Zhang, Ramakrishnan, Livny (SIGMOD’96)  Incrementally construct a CF (Clustering Feature) tree, a hierarchical data structure for multiphase clustering  Phase 1: scan DB to build an initial inmemory CF tree (a multilevel compression of the data that tries to preserve the inherent clustering structure of the data)  Phase 2: use an arbitrary clustering algorithm to cluster the leaf nodes of the CFtree  Scales linearly: finds a good clustering with a single scan and improves the quality with a few additional scans www.ThesisScientist.comClustering Feature Vector Clustering Feature: CF = (N, LS, SS) N: Number of data points N LS:  X i=1 i N 2 CF = (5, (16,30),244) SS:  (X ) i=1 i 10 (3,4) 9 8 7 (2,6) 6 5 (4,5) 4 3 2 (4,7) 1 0 0 1 2 3 4 5 6 7 8 9 10 (3,8) www.ThesisScientist.comSome Characteristics of CFVs  Two CFVs can be aggregated.  Given CF1=(N1, LS1, SS1), CF2 = (N2, LS2, SS2),  If combined into one cluster, CF=(N1+N2, LS1+LS2, SS1+SS2).  The centroid and radius can both be computed from CF.  centroid is the center of the cluster  radius is the average distance between an object and the centroid. N N 2  x i i1 ( )   x x i 0 x i1 0 R N N Other statistical features as well... www.ThesisScientist.comCFTree in BIRCH A CF tree is a heightbalanced tree that stores the clustering features for a hierarchical clustering  A nonleaf node in a tree has (at most) B descendants or “children”  The nonleaf nodes store sums of the CFs of their children  A leaf node contains up to L CF entries  A CF tree has two parameters  Branching factor B: specify the maximum number of children.  threshold T: max radius of a subcluster stored in a leaf node www.ThesisScientist.comCF Tree (a multiway tree, like the Btree) Root CF CF CF CF 1 2 3 6 child child child child 1 2 3 6 Nonleaf node CF CF CF CF 1 2 3 5 child child child child 1 2 3 5 Leaf node Leaf node prev next prev next CF CF CF CF CF CF 1 2 6 1 2 4 www.ThesisScientist.comCFTree Construction  Scan through the database once.  For each object, insert into the CFtree as follows:  At each level, choose the subtree whose centroid is closest.  In a leaf page, choose a cluster that can absort it (new radius T). If no cluster can absorb it, create a new cluster.  Update upper levels. www.ThesisScientist.com