Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Mining Classification: Basic Concepts, Decision Trees, and Model Evaluation Tan, Steinbach, Kumar © Tan,Steinbach, Kumar Introduction to Data Mining.

Similar presentations


Presentation on theme: "Data Mining Classification: Basic Concepts, Decision Trees, and Model Evaluation Tan, Steinbach, Kumar © Tan,Steinbach, Kumar Introduction to Data Mining."— Presentation transcript:

1 Data Mining Classification: Basic Concepts, Decision Trees, and Model Evaluation Tan, Steinbach, Kumar © Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 1

2 Classification: Definition uGiven a collection of records (training set ) wEach record contains a set of attributes, one of the attributes is the class. uFind a model for class attribute as a function of the values of other attributes. uGoal: previously unseen records should be assigned a class as accurately as possible. wA test set is used to determine the accuracy of the model. Usually, the given data set is divided into training and test sets, with training set used to build the model and test set used to validate it.

3 Example of a Decision Tree categorical continuous class Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Splitting Attributes Training Data Model: Decision Tree

4 Hunt’s Algorithm Don’t Cheat Refund Don’t Cheat Don’t Cheat YesNo Refund Don’t Cheat YesNo Marital Status Don’t Cheat Single, Divorced Married Taxable Income Don’t Cheat < 80K>= 80K Refund Don’t Cheat YesNo Marital Status Don’t Cheat Single, Divorced Married

5 Tree Induction uGreedy strategy. wSplit the records based on an attribute test that optimizes certain criterion. uIssues wDetermine how to split the records How to specify the attribute test condition? How to determine the best split? wDetermine when to stop splitting

6 Measures of Node Impurity uGini Index uEntropy uMisclassification error

7 How to Find the Best Split B? YesNo Node N3Node N4 A? YesNo Node N1Node N2 Before Splitting: M0 M1 M2M3M4 M12 M34 Gain = M0 – M12 vs M0 – M34

8 Measure of Impurity: GINI uGini Index for a given node t : (NOTE: p( j | t) is the relative frequency of class j at node t). wMaximum (1 - 1/n c ) when records are equally distributed among all classes, implying least interesting information wMinimum (0.0) when all records belong to one class, implying most interesting information

9 Examples for computing GINI P(C1) = 0/6 = 0 P(C2) = 6/6 = 1 Gini = 1 – P(C1) 2 – P(C2) 2 = 1 – 0 – 1 = 0 P(C1) = 1/6 P(C2) = 5/6 Gini = 1 – (1/6) 2 – (5/6) 2 = P(C1) = 2/6 P(C2) = 4/6 Gini = 1 – (2/6) 2 – (4/6) 2 = 0.444

10 Splitting Based on GINI uUsed in CART, SLIQ, SPRINT. uWhen a node p is split into k partitions (children), the quality of split is computed as, where,n i = number of records at child i, n = number of records at node p.

11 Binary Attributes: Computing GINI Index l Splits into two partitions l Effect of Weighing partitions: – Larger and Purer Partitions are sought for. B? YesNo Node N1Node N2 Gini(N1) = 1 – (5/6) 2 – (2/6) 2 = Gini(N2) = 1 – (1/6) 2 – (4/6) 2 = Gini(Children) = 7/12 * /12 * = 0.333

12 Categorical Attributes: Computing Gini Index uFor each distinct value, gather counts for each class in the dataset uUse the count matrix to make decisions Multi-way splitTwo-way split (find best partition of values)

13 Continuous Attributes: Computing Gini Index uUse Binary Decisions based on one value uSeveral Choices for the splitting value wNumber of possible splitting values = Number of distinct values uEach splitting value has a count matrix associated with it wClass counts in each of the partitions, A < v and A  v uSimple method to choose best v wFor each v, scan the database to gather count matrix and compute its Gini index wComputationally Inefficient! Repetition of work.

14 Continuous Attributes: Computing Gini Index... uFor efficient computation: for each attribute, wSort the attribute on values wLinearly scan these values, each time updating the count matrix and computing gini index wChoose the split position that has the least gini index Split Positions Sorted Values

15 Alternative Splitting Criteria based on Entropy uEntropy at a given node t: (NOTE: p( j | t) is the relative frequency of class j at node t). wMeasures homogeneity of a node. Maximum (log n c ) when records are equally distributed among all classes implying least information Minimum (0.0) when all records belong to one class, implying most information wEntropy based computations are similar to the GINI index computations

16 Examples for computing Entropy P(C1) = 0/6 = 0 P(C2) = 6/6 = 1 Entropy = – 0 log 0 – 1 log 1 = – 0 – 0 = 0 P(C1) = 1/6 P(C2) = 5/6 Entropy = – (1/6) log 2 (1/6) – (5/6) log 2 (1/6) = 0.65 P(C1) = 2/6 P(C2) = 4/6 Entropy = – (2/6) log 2 (2/6) – (4/6) log 2 (4/6) = 0.92

17 Splitting Based on INFO... uInformation Gain: Parent Node, p is split into k partitions; n i is number of records in partition i wMeasures Reduction in Entropy achieved because of the split. Choose the split that achieves most reduction (maximizes GAIN) wUsed in ID3 and C4.5 wDisadvantage: Tends to prefer splits that result in large number of partitions, each being small but pure.

18 Splitting Based on INFO... uGain Ratio: Parent Node, p is split into k partitions n i is the number of records in partition i wAdjusts Information Gain by the entropy of the partitioning (SplitINFO). Higher entropy partitioning (large number of small partitions) is penalized! wUsed in C4.5 wDesigned to overcome the disadvantage of Information Gain

19 Tree Induction uGreedy strategy. wSplit the records based on an attribute test that optimizes certain criterion. uIssues wDetermine how to split the records How to specify the attribute test condition? How to determine the best split? wDetermine when to stop splitting

20 Stopping Criteria for Tree Induction uStop expanding a node when all the records belong to the same class uStop expanding a node when all the records have similar attribute values uEarly termination (to be discussed later)

21 Decision Tree Based Classification uAdvantages: wInexpensive to construct wExtremely fast at classifying unknown records wEasy to interpret for small-sized trees wAccuracy is comparable to other classification techniques for many simple data sets

22 Metrics for Model Evaluation uFocus on the predictive capability of a model wRather than how fast it takes to classify or build models, scalability, etc. uConfusion Matrix: PREDICTED CLASS ACTUAL CLASS Class=YesClass=No Class=Yesab Class=Nocd a: TP (true positive) b: FN (false negative) c: FP (false positive) d: TN (true negative)

23 Metrics for Performance Evaluation… uMost widely-used metric: PREDICTED CLASS ACTUAL CLASS Class=YesClass=No Class=Yesa (TP) b (FN) Class=Noc (FP) d (TN)

24 Limitation of Accuracy uConsider a 2-class problem wNumber of Class 0 examples = 9990 wNumber of Class 1 examples = 10 uIf model predicts everything to be class 0, accuracy is 9990/10000 = 99.9 % wAccuracy is misleading because model does not detect any class 1 example

25 Cost Matrix PREDICTED CLASS ACTUAL CLASS C(i|j) Class=YesClass=No Class=YesC(Yes|Yes)C(No|Yes) Class=NoC(Yes|No)C(No|No) C(i|j): Cost of misclassifying class j example as class i

26 Computing Cost of Classification Cost Matrix PREDICTED CLASS ACTUAL CLASS C(i|j) Model M 1 PREDICTED CLASS ACTUAL CLASS Model M 2 PREDICTED CLASS ACTUAL CLASS Accuracy = 80% Cost = 3910 Accuracy = 90% Cost = 4255

27 Cost-Sensitive Measures l Precision is biased towards C(Yes|Yes) & C(Yes|No) l Recall is biased towards C(Yes|Yes) & C(No|Yes) l F-measure is biased towards all except C(No|No)

28 Data Mining Cluster Analysis: Basic Concepts and Algorithms

29 What is Cluster Analysis? uFinding 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 Inter-cluster distances are maximized Intra-cluster distances are minimized

30 Notion of a Cluster can be Ambiguous How many clusters? Four ClustersTwo Clusters Six Clusters

31 Types of Clusterings uA clustering is a set of clusters uImportant distinction between hierarchical and partitional sets of clusters uPartitional Clustering wA division data objects into non-overlapping subsets (clusters) such that each data object is in exactly one subset uHierarchical clustering wA set of nested clusters organized as a hierarchical tree

32 Partitional Clustering Original Points A Partitional Clustering

33 Hierarchical Clustering Traditional Hierarchical Clustering Non-traditional Hierarchical Clustering Non-traditional Dendrogram Traditional Dendrogram

34 Other Distinctions Between Sets of Clusters uExclusive versus non-exclusive wIn non-exclusive clusterings, points may belong to multiple clusters. wCan represent multiple classes or ‘border’ points uFuzzy versus non-fuzzy wIn fuzzy clustering, a point belongs to every cluster with some weight between 0 and 1 wWeights must sum to 1 wProbabilistic clustering has similar characteristics uPartial versus complete wIn some cases, we only want to cluster some of the data uHeterogeneous versus homogeneous wCluster of widely different sizes, shapes, and densities

35 Types of Clusters u Well-separated clusters u Center-based clusters u Contiguous clusters u Density-based clusters uProperty or Conceptual uDescribed by an Objective Function

36 Types of Clusters: Well-Separated uWell-Separated Clusters: wA cluster is a set of points such that any point in a cluster is closer (or more similar) to every other point in the cluster than to any point not in the cluster. 3 well-separated clusters

37 Types of Clusters: Center-Based uCenter-based w A cluster is a set of objects such that an object in a cluster is closer (more similar) to the “center” of a cluster, than to the center of any other cluster wThe center of a cluster is often a centroid, the average of all the points in the cluster, or a medoid, the most “representative” point of a cluster 4 center-based clusters

38 Types of Clusters: Contiguity-Based uContiguous Cluster (Nearest neighbor or Transitive) wA cluster is a set of points such that a point in a cluster is closer (or more similar) to one or more other points in the cluster than to any point not in the cluster. 8 contiguous clusters

39 Types of Clusters: Density-Based uDensity-based wA cluster is a dense region of points, which is separated by low-density regions, from other regions of high density. wUsed when the clusters are irregular or intertwined, and when noise and outliers are present. 6 density-based clusters

40 Types of Clusters: Conceptual Clusters uShared Property or Conceptual Clusters wFinds clusters that share some common property or represent a particular concept.. 2 Overlapping Circles

41 Clustering Algorithms uK-means and its variants uHierarchical clustering uDensity-based clustering

42 K-means Clustering uPartitional clustering approach uEach cluster is associated with a centroid (center point) uEach point is assigned to the cluster with the closest centroid uNumber of clusters, K, must be specified uThe basic algorithm is very simple

43 K-means Clustering – Details uInitial centroids are often chosen randomly. wClusters produced vary from one run to another. uThe centroid is (typically) the mean of the points in the cluster. u‘Closeness’ is measured by Euclidean distance, cosine similarity, correlation, etc. uK-means will converge for common similarity measures mentioned above. uMost of the convergence happens in the first few iterations. wOften the stopping condition is changed to ‘Until relatively few points change clusters’ uComplexity is O( n * K * I * d ) wn = number of points, K = number of clusters, I = number of iterations, d = number of attributes

44 Two different K-means Clusterings Sub-optimal ClusteringOptimal Clustering Original Points

45 Importance of Choosing Initial Centroids

46 Importance of Choosing Initial Centroids …

47 Evaluating K-means Clusters uMost common measure is Sum of Squared Error (SSE) wFor each point, the error is the distance to the nearest cluster wTo get SSE, we square these errors and sum them. wx is a data point in cluster C i and m i is the representative point for cluster C i can show that m i corresponds to the center (mean) of the cluster wGiven two clusters, we can choose the one with the smallest error wOne easy way to reduce SSE is to increase K, the number of clusters A good clustering with smaller K can have a lower SSE than a poor clustering with higher K

48 Limitations of K-means uK-means has problems when clusters are of differing wSizes wDensities wNon-globular shapes uK-means has problems when the data contains outliers.

49 Limitations of K-means: Differing Sizes Original Points K-means (3 Clusters)

50 Limitations of K-means: Differing Density Original Points K-means (3 Clusters)

51 Limitations of K-means: Non-globular Shapes Original Points K-means (2 Clusters)

52 Overcoming K-means Limitations Original PointsK-means Clusters One solution is to use many clusters. Find parts of clusters, but need to put together.

53 Overcoming K-means Limitations Original PointsK-means Clusters

54 Overcoming K-means Limitations Original PointsK-means Clusters

55 Hierarchical Clustering uProduces a set of nested clusters organized as a hierarchical tree uCan be visualized as a dendrogram wA tree like diagram that records the sequences of merges or splits

56 Strengths of Hierarchical Clustering uDo not have to assume any particular number of clusters wAny desired number of clusters can be obtained by ‘cutting’ the dendogram at the proper level uThey may correspond to meaningful taxonomies wExample in biological sciences (e.g., animal kingdom, phylogeny reconstruction, …)

57 Hierarchical Clustering uTwo main types of hierarchical clustering wAgglomerative: Start with the points as individual clusters At each step, merge the closest pair of clusters until only one cluster (or k clusters) left wDivisive: Start with one, all-inclusive cluster At each step, split a cluster until each cluster contains a point (or there are k clusters) uTraditional hierarchical algorithms use a similarity or distance matrix wMerge or split one cluster at a time


Download ppt "Data Mining Classification: Basic Concepts, Decision Trees, and Model Evaluation Tan, Steinbach, Kumar © Tan,Steinbach, Kumar Introduction to Data Mining."

Similar presentations


Ads by Google