Data Mining Algorithms Clustering
M.Vijayalakshmi VESIT BE(IT) Data Mining Clustering Outline Goal: Provide an overview of the clustering problem and introduce some of the basic algorithms Clustering Problem Overview Clustering Techniques Hierarchical Algorithms Partitional Algorithms Genetic Algorithm Clustering Large Databases M.Vijayalakshmi VESIT BE(IT) Data Mining
What 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 Typical applications As a stand-alone tool to get insight into data distribution As a preprocessing step for other algorithms M.Vijayalakshmi VESIT BE(IT) Data Mining
General Applications of Clustering Pattern Recognition Spatial Data Analysis create thematic maps in GIS by clustering feature spaces detect spatial clusters and explain them in spatial data mining Image Processing Economic Science (especially market research) WWW Document classification Cluster Weblog data to discover groups of similar access patterns M.Vijayalakshmi VESIT BE(IT) Data Mining
Examples of Clustering Applications Marketing: Help marketers discover distinct groups in their customer bases, and then use this knowledge to develop targeted marketing programs Land use: Identification of areas of similar land use in an earth observation database Insurance: Identifying groups of motor insurance policy holders with a high average claim cost City-planning: Identifying groups of houses according to their house type, value, and geographical location Earth-quake studies: Observed earth quake epicenters should be clustered along continent faults M.Vijayalakshmi VESIT BE(IT) Data Mining
Clustering vs. Classification No prior knowledge Number of clusters Meaning of clusters Cluster results are dynamic Unsupervised learning M.Vijayalakshmi VESIT BE(IT) Data Mining
Classification vs. Clustering Classification: Supervised learning: Learns a method for predicting the instance class from pre-labeled (classified) instances M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Clustering Unsupervised learning: Finds “natural” grouping of instances given un-labeled data M.Vijayalakshmi VESIT BE(IT) Data Mining
Clustering Houses Geographic Distance Based Size Based M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Clustering Methods Many different method and algorithms: For numeric and/or symbolic data Deterministic vs. probabilistic Exclusive vs. overlapping Hierarchical vs. flat Top-down vs. bottom-up M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Clustering Issues Outlier handling Dynamic data Interpreting results Evaluating results Number of clusters Data to be used Scalability M.Vijayalakshmi VESIT BE(IT) Data Mining
Impact of Outliers on Clustering M.Vijayalakshmi VESIT BE(IT) Data Mining
Clustering Evaluation Manual inspection Benchmarking on existing labels Cluster quality measures distance measures high similarity within a cluster, low across clusters M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Data Structures Data matrix Dissimilarity matrix M.Vijayalakshmi VESIT BE(IT) Data Mining
Measure the Quality of Clustering Dissimilarity/Similarity metric: Similarity is expressed in terms of a distance function, which is typically metric: d(i, j) There is a separate “quality” function that measures the “goodness” of a cluster. The definitions of distance functions are usually very different for interval-scaled, boolean, categorical, ordinal and ratio variables. Weights should be associated with different variables based on applications and data semantics. It is hard to define “similar enough” or “good enough” the answer is typically highly subjective. M.Vijayalakshmi VESIT BE(IT) Data Mining
Type of data in clustering analysis Interval-scaled variables: Binary variables: Nominal, ordinal, and ratio variables: Variables of mixed types: M.Vijayalakshmi VESIT BE(IT) Data Mining
Similarity and Dissimilarity Between Objects Distances are normally used to measure the similarity or dissimilarity between two data objects Some popular ones include: Minkowski distance: where i = (xi1, xi2, …, xip) and j = (xj1, xj2, …, xjp) are two p-dimensional data objects, and q is a positive integer If q = 1, d is Manhattan distance M.Vijayalakshmi VESIT BE(IT) Data Mining
Similarity and Dissimilarity Between Objects (Cont.) If q = 2, d is Euclidean distance: Properties d(i,j) 0 d(i,i) = 0 d(i,j) = d(j,i) d(i,j) d(i,k) + d(k,j) M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Binary Variables A contingency table for binary data Simple matching coefficient (invariant, if the binary variable is symmetric): Jaccard coefficient (noninvariant if the binary variable is asymmetric): Object j Object i M.Vijayalakshmi VESIT BE(IT) Data Mining
Dissimilarity between Binary Variables Example gender is a symmetric attribute the remaining attributes are asymmetric binary let the values Y and P be set to 1, and the value N be set to 0 M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Nominal Variables A generalization of the binary variable in that it can take more than 2 states, e.g., red, yellow, blue, green Method 1: Simple matching m: # of matches, p: total # of variables Method 2: use a large number of binary variables creating a new binary variable for each of the M nominal states M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Clustering Problem Given a database D={t1,t2,…,tn} of tuples and an integer value k, the Clustering Problem is to define a mapping f:Dg{1,..,k} where each ti is assigned to one cluster Kj, 1<=j<=k. A Cluster, Kj, contains precisely those tuples mapped to it. Unlike classification problem, clusters are not known a priori. M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Types of Clustering Hierarchical – Nested set of clusters created. Partitional – One set of clusters created. Incremental – Each element handled one at a time. Simultaneous – All elements handled together. Overlapping/Non-overlapping M.Vijayalakshmi VESIT BE(IT) Data Mining
Major Clustering Approaches Partitioning algorithms: Construct various partitions and then evaluate them by some criterion Hierarchy algorithms: Create a hierarchical decomposition of the set of data (or objects) using some criterion Density-based: based on connectivity and density functions Grid-based: based on a multiple-level granularity structure Model-based: A model is hypothesized for each of the clusters and the idea is to find the best fit of that model to each other M.Vijayalakshmi VESIT BE(IT) Data Mining
Clustering Approaches Hierarchical Partitional Categorical Large DB Agglomerative Divisive Sampling Compression M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Cluster Parameters M.Vijayalakshmi VESIT BE(IT) Data Mining
Distance Between Clusters Single Link: smallest distance between points Complete Link: largest distance between points Average Link: average distance between points Centroid: distance between centroids M.Vijayalakshmi VESIT BE(IT) Data Mining
Hierarchical Clustering Clusters are created in levels actually creating sets of clusters at each level. Agglomerative Initially each item in its own cluster Iteratively clusters are merged together Bottom Up Divisive Initially all items in one cluster Large clusters are successively divided Top Down M.Vijayalakshmi VESIT BE(IT) Data Mining
Hierarchical 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 0 Step 1 Step 2 Step 3 Step 4 b d c e a a b d e c d e a b c d e agglomerative (AGNES) divisive (DIANA) M.Vijayalakshmi VESIT BE(IT) Data Mining
Hierarchical Algorithms Single Link MST Single Link Complete Link Average Link M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Dendrogram A tree data structure which illustrates hierarchical clustering techniques. Each level shows clusters for that level. Leaf – individual clusters Root – one cluster A cluster at level i is the union of its children clusters at level i+1. M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Levels of Clustering M.Vijayalakshmi VESIT BE(IT) Data Mining
Agglomerative Example B C D E 1 2 3 4 5 A B E C D Threshold of 1 2 3 4 5 A B C D E M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining MST Example A B A B C D E 1 2 3 4 5 E C D M.Vijayalakshmi VESIT BE(IT) Data Mining
Agglomerative Algorithm M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Single Link View all items with links (distances) between them. Finds maximal connected components in this graph. Two clusters are merged if there is at least one edge which connects them. Uses threshold distances at each level. Could be agglomerative or divisive. M.Vijayalakshmi VESIT BE(IT) Data Mining
MST Single Link Algorithm M.Vijayalakshmi VESIT BE(IT) Data Mining
Single Link Clustering M.Vijayalakshmi VESIT BE(IT) Data Mining
AGNES (Agglomerative Nesting) Implemented in statistical analysis packages, e.g., Splus Use the Single-Link method and the dissimilarity matrix. Merge nodes that have the least dissimilarity Go on in a non-descending fashion Eventually all nodes belong to the same cluster M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining A Dendrogram Shows How the Clusters are Merged Hierarchically Decompose data objects into a several levels of nested partitioning (tree of clusters), called a dendrogram. A clustering of the data objects is obtained by cutting the dendrogram at the desired level, then each connected component forms a cluster. M.Vijayalakshmi VESIT BE(IT) Data Mining
DIANA (Divisive Analysis) Implemented in statistical analysis packages, e.g., Splus Inverse order of AGNES Eventually each node forms a cluster on its own M.Vijayalakshmi VESIT BE(IT) Data Mining
Partitional Clustering Nonhierarchical Creates clusters in one step as opposed to several steps. Since only one set of clusters is output, the user normally has to input the desired number of clusters, k. Usually deals with static sets. M.Vijayalakshmi VESIT BE(IT) Data Mining
Partitioning Algorithms Partitioning method: Construct a partition of a database D of n objects into a set of k clusters Given a k, find a partition of k clusters that optimizes the chosen partitioning criterion Global optimal: exhaustively enumerate all partitions Heuristic methods: k-means and k-medoids algorithms k-means: Each cluster is represented by the center of the cluster k-medoids or PAM (Partition around medoids): Each cluster is represented by one of the objects in the cluster M.Vijayalakshmi VESIT BE(IT) Data Mining
Partitional Algorithms MST Squared Error K-Means Nearest Neighbor PAM BEA GA M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining MST Algorithm M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining K-Means Initial set of clusters randomly chosen. Iteratively, items are moved among sets of clusters until the desired set is reached. High degree of similarity among elements in a cluster is obtained. Given a cluster Ki={ti1,ti2,…,tim}, the cluster mean is mi = (1/m)(ti1 + … + tim) M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining K-Means Example Given: {2,4,10,12,3,20,30,11,25}, k=2 Randomly assign means: m1=3,m2=4 K1={2,3}, K2={4,10,12,20,30,11,25}, m1=2.5,m2=16 K1={2,3,4},K2={10,12,20,30,11,25}, m1=3,m2=18 K1={2,3,4,10},K2={12,20,30,11,25}, m1=4.75,m2=19.6 K1={2,3,4,10,11,12},K2={20,30,25}, m1=7,m2=25 Stop as the clusters with these means are the same. M.Vijayalakshmi VESIT BE(IT) Data Mining
The K-Means Clustering Method Given k, the k-means algorithm is implemented in 4 steps: Partition objects into k nonempty subsets Compute seed points as the centroids of the clusters of the current partition. The centroid is the center (mean point) of the cluster. Assign each object to the cluster with the nearest seed point. Go back to Step 2, stop when no more new assignment. M.Vijayalakshmi VESIT BE(IT) Data Mining
Comments on the K-Means Method Strength Relatively efficient: O(tkn), where n is # objects, k is # clusters, and t is # iterations. Normally, k, t << n. Often terminates at a local optimum. The global optimum may be found using techniques such as: deterministic annealing and genetic algorithms Weakness Applicable only when mean is defined, then what about categorical data? Need to specify k, the number of clusters, in advance Unable to handle noisy data and outliers Not suitable to discover clusters with non-convex shapes M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Nearest Neighbor Items are iteratively merged into the existing clusters that are closest. Incremental Threshold, t, used to determine if items are added to existing clusters or a new cluster is created. M.Vijayalakshmi VESIT BE(IT) Data Mining
Variations of the K-Means Method A few variants of the k-means which differ in Selection of the initial k means Dissimilarity calculations Strategies to calculate cluster means Handling categorical data: k-modes Replacing means of clusters with modes Using new dissimilarity measures to deal with categorical objects Using a frequency-based method to update modes of clusters A mixture of categorical and numerical data: k-prototype method M.Vijayalakshmi VESIT BE(IT) Data Mining
The K-Medoids Clustering Method Find representative objects, called medoids, in clusters PAM (Partitioning Around Medoids,) starts from an initial set of medoids and iteratively replaces one of the medoids by one of the non-medoids 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 CLARANS): Randomized sampling Focusing + spatial data structure M.Vijayalakshmi VESIT BE(IT) Data Mining
PAM (Partitioning Around Medoids) PAM - Use real object to represent the cluster Select k representative objects arbitrarily For each pair of non-selected object h and selected object i, calculate the total swapping cost TCih For each pair of i and h, If TCih < 0, i is replaced by h Then assign each non-selected object to the most similar representative object repeat steps 2-3 until there is no change M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining PAM Partitioning Around Medoids (PAM) (K-Medoids) Handles outliers well. Ordering of input does not impact results. Does not scale well. Each cluster represented by one item, called the medoid. Initial set of k medoids randomly chosen. M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining PAM M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining PAM Algorithm M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining DBSCAN Density Based Spatial Clustering of Applications with Noise Outliers will not effect creation of cluster. Input MinPts – minimum number of points in cluster Eps – for each point in cluster there must be another point in it less than this distance away. M.Vijayalakshmi VESIT BE(IT) Data Mining
M.Vijayalakshmi VESIT BE(IT) Data Mining Density Concepts M.Vijayalakshmi VESIT BE(IT) Data Mining
Comparison of Clustering Techniques M.Vijayalakshmi VESIT BE(IT) Data Mining