Download
lecture 7 classification n.
Skip this Video
Loading SlideShow in 5 Seconds..
Lecture 7 Classification PowerPoint Presentation
Download Presentation
Lecture 7 Classification

Lecture 7 Classification

408 Views Download Presentation
Download Presentation

Lecture 7 Classification

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Lecture 7 Classification ITCS 6163

  2. Chapter 7. Classification and Prediction • What is classification? What is prediction? • Classification by decision tree induction • Bayesian Classification • Other Classification Methods (SVM) • Classification accuracy • Prediction • Summary

  3. Classification problem • Given: • Tuples each assigned a class level. • Develop a model for each class • Example: • Good creditor : (age in [25,40]) AND (income > 50K) AND (status = MARRIED) • Applications: • Credit approval (good, bad) • Store locations (good, fair, poor) • Emergency situations (emergency, non-emergency)

  4. Classification vs. Prediction • Classification: • predicts categorical class labels • classifies data (constructs a model) based on the training set and the values (class labels) in a classifying attribute and uses it in classifying new data • Prediction: • models continuous-valued functions, i.e., predicts unknown or missing values • Typical Applications • credit approval • target marketing • medical diagnosis • treatment effectiveness analysis

  5. Classification—A Two-Step Process • Model construction: describing a set of predetermined classes • Each tuple/sample is assumed to belong to a predefined class, as determined by the class label attribute • The set of tuples used for model construction: training set • The model is represented as classification rules, decision trees, or mathematical formulae • Model usage: for classifying future or unknown objects • Estimate accuracy of the model • The known label of test sample is compared with the classified result from the model • Accuracy rate is the percentage of test set samples that are correctly classified by the model • Test set is independent of training set, otherwise over-fitting will occur

  6. Supervised vs. Unsupervised Learning • Supervised learning (classification) • Supervision: The training data (observations, measurements, etc.) are accompanied by labels indicating the class of the observations • New data is classified based on the training set • Unsupervised learning(clustering) • The class labels of training data is unknown • Given a set of measurements, observations, etc. with the aim of establishing the existence of classes or clusters in the data

  7. Chapter 7. Classification and Prediction • What is classification? What is prediction? • Classification by decision tree induction • Bayesian Classification • Other Classification Methods • Classification accuracy • Prediction • Summary

  8. Classification by Decision Tree Induction • Decision tree • A flow-chart-like tree structure • Internal node denotes a test on an attribute • Branch represents an outcome of the test • Leaf nodes represent class labels or class distribution • Decision tree generation consists of two phases • Tree construction • At start, all the training examples are at the root • Partition examples recursively based on selected attributes • Tree pruning • Identify and remove branches that reflect noise or outliers • Use of decision tree: Classifying an unknown sample • Test the attribute values of the sample against the decision tree

  9. Training Dataset This follows an example from Quinlan’s ID3

  10. Output: A Decision Tree for “buys_computer” age? <=30 overcast >40 30..40 student? credit rating? yes no yes fair excellent no yes no yes

  11. Algorithm for Decision Tree Induction • Basic algorithm (a greedy algorithm) • Tree is constructed in a top-down recursive divide-and-conquer manner • At start, all the training examples are at the root • Attributes are categorical (if continuous-valued, they are discretized in advance) • Examples are partitioned recursively based on selected attributes • Test attributes are selected on the basis of a heuristic or statistical measure (e.g., information gain) • Conditions for stopping partitioning • All samples for a given node belong to the same class • There are no remaining attributes for further partitioning – majority voting is employed for classifying the leaf • There are no samples left

  12. Decision trees Training set Salary < 20000 Y N Education = G A N Y A R

  13. Decision trees • Pros: • Fast. • Rules easy to interpret. • High dimensional data • Cons: • No correlations • Axis-parallel cuts.

  14. Decision trees(cont.) • Machine learning: • ID3 (Quinlan86) • C4.5 (Quinlan93 ) • CART (Breiman, Friedman, Olshen, Stone, Classification and Regression Trees 1984) • Database: • SLIQ (Metha, Agrawal and Rissanen, EDBT96) • SPRINT (Shafer, Agrawal, Metha, VLDB96) • Rainforest (Gherke, Ramakrishnan, Ghanti VLDB98)

  15. Decision trees • Finding the best tree is NP-Hard • We look at non-backtracking algorithms (never look back at a previous decision) • Assume we have a test with n outcomes that partitions T into subsets T1, T2,…, Tn If the test is to be evaluated without exploring subsequent dimensions of the Ti’s, the only information available for guidance is the distribution of classes in T and its subsets.

  16. Decision tree algorithms • Building phase: • Recursively split nodes using best splitting attribute and value for node • Pruning phase: • Smaller (yet imperfect) tree achieves better prediction accuracy. • Prune leaf nodes recursively to avoid over-fitting.

  17. Predictor variables (attributes) • Numerically ordered: values are ordered and they can be represented in real line. ( E.g., salary.) • Categorical: takes values from a finite set not having any natural ordering. (E.g., color.) • Ordinal: takes values from a finite set whose values posses a clear ordering, but the distances between them are unknown. (E.g., preference scale: good, fair, bad.)

  18. Binary Splits Recursive (binary) partitioning • Univariate split on numerically ordered or ordinal X X <= c • on categorical X X  A • Linear combination on numerical  ai Xi <= c c and A are chosen to maximize separation.

  19. Some probability... S = cases freq(Ci,S) = # cases in S that belong to Ci Gain entropic meassure: Prob(“this case belongs to Ci”) = freq(Ci,S)/|S| Information conveyed: -log (freq(Ci,S)/|S|) Entropy = expected information = -  (freq(Ci,S)/|S|) log (freq(Ci,S)/|S|) = info(S)

  20. Gain Test X: infoX (T) =  |Ti|/T info(Ti) gain(X) = info (T) - infoX(T)

  21. 5/14 (-2/5 log(2/5)-3/5 log(3/5))+ 7/14(-4/7log(4/7)-3/7 log(3/7)) 4/14 (-4/4 log(4/4)) + +7/14(-5/7log(5/7)-2/7log(2/(7)) 5/14 (-3/5 log(3/5) - 2/5 log(2/5)) Example Info(T) (9 play, 5 don’t) info(T) = -9/14log(9/14)- 5/14log(5/14) = 0.94 (bits) Test: outlook infoOutlook = Test Windy infowindy= gainOutlook = 0.94-0.64= 0.3 = 0.278 gainWindy = 0.94-0.278= 0.662 = 0.64 (bits) Windy is a better test

  22. Problem with Gain Strong bias towards test with many outcomes. Example: Z = Name |Ti| = 1 (each name unique) infoZ (T) =  1/|T| (- 1/N log (1/N))  0 Maximal gain!! (but useless division--- overfitting--)

  23. Split Split-info (X) = -  |Ti|/|T| log (|Ti|/|T|) gain-ratio(X) = gain(X)/split-info(X) Gain <= log(k) Split <= log(n) ratio small

  24. Extracting Classification Rules from Trees • Represent the knowledge in the form of IF-THEN rules • One rule is created for each path from the root to a leaf • Each attribute-value pair along a path forms a conjunction • The leaf node holds the class prediction • Rules are easier for humans to understand • Example IF age = “<=30” AND student = “no” THEN buys_computer = “no” IF age = “<=30” AND student = “yes” THEN buys_computer = “yes” IF age = “31…40” THEN buys_computer = “yes” IF age = “>40” AND credit_rating = “excellent” THEN buys_computer = “yes” IF age = “<=30” AND credit_rating = “fair” THEN buys_computer = “no”

  25. OVERFITTING • Decision trees can grow so long that there is a leaf for each training example. • Extremes: • Overfitted: “Whatever I haven’t seen can’t be classified” • Too General: “If it is green, it is a tree”

  26. Avoid Overfitting in Classification • The generated tree may overfit the training data • Too many branches, some may reflect anomalies due to noise or outliers • Result is in poor accuracy for unseen samples • Two approaches to avoid overfitting • Prepruning: Halt tree construction early—do not split a node if this would result in the goodness measure falling below a threshold • Difficult to choose an appropriate threshold • Postpruning: Remove branches from a “fully grown” tree—get a sequence of progressively pruned trees • Use a set of data different from the training data to decide which is the “best pruned tree”

  27. Approaches to Determine the Final Tree Size • Separate training (2/3) and testing (1/3) sets • Use cross validation, e.g., 10-fold cross validation • Use all the data for training • but apply a statistical test (e.g., chi-square) to estimate whether expanding or pruning a node may improve the entire distribution • Use minimum description length (MDL) principle: • halting growth of the tree when the encoding is minimized

  28. Enhancements to basic decision tree induction • Allow for continuous-valued attributes • Dynamically define new discrete-valued attributes that partition the continuous attribute value into a discrete set of intervals • Handle missing attribute values • Assign the most common value of the attribute • Assign probability to each of the possible values • Attribute construction • Create new attributes based on existing ones that are sparsely represented • This reduces fragmentation, repetition, and replication

  29. Classification in Large Databases • Classification—a classical problem extensively studied by statisticians and machine learning researchers • Scalability: Classifying data sets with millions of examples and hundreds of attributes with reasonable speed • Why decision tree induction in data mining? • relatively faster learning speed (than other classification methods) • convertible to simple and easy to understand classification rules • can use SQL queries for accessing databases • comparable classification accuracy with other methods

  30. Scalable Decision Tree Induction Methods in Data Mining Studies • SLIQ (EDBT’96 — Mehta et al.) • builds an index for each attribute and only class list and the current attribute list reside in memory • SPRINT (VLDB’96 — J. Shafer et al.) • constructs an attribute list data structure • PUBLIC (VLDB’98 — Rastogi & Shim) • integrates tree splitting and tree pruning: stop growing the tree earlier • RainForest (VLDB’98 — Gehrke, Ramakrishnan & Ganti) • separates the scalability aspects from the criteria that determine the quality of the tree • builds an AVC-list (attribute, value, class label)

  31. SPRINT For large data sets. Age < 25 Car = Sports H H L

  32. Gini Index (IBM IntelligentMiner) • If a data set T contains examples from n classes, gini index, gini(T) is defined as where pj is the relative frequency of class j in T. • If a data set T is split into two subsets T1 and T2 with sizes N1 and N2 respectively, the gini index of the split data contains examples from n classes, the gini index gini(T) is defined as • The attribute provides the smallest ginisplit(T) is chosen to split the node (need to enumerate all possible splitting points for each attribute).

  33. SPRINT Partition (S) if all points of S are in the same class return; else for each attribute A do evaluate_splits on A; use best split to partition into S1,S2; Partition(S1); Partition(S2);

  34. SPRINT Data Structures Training set Age Car Attribute lists

  35. Splits Age < 27.5 Group2 Group1

  36. Histograms For continuous attributes Associated with node (Cabove, Cbelow) to process already processed

  37. ginisplit0 = 0/6 gini(S1) + 6/6 gini(S2) gini(S2) = 1 - [(4/6)2 +(2/6)2 ] = 0.444 ginisplit1 = 1/6 gini(S1) +5/6 gini(S2) gini(S1) = 1 - [(1/1) 2 ] = 0 gini(S2) = 1 - [(3/4)2 +(2/4)2 ] = 0.1875 ginisplit2 = 2/6 gini(S1) +4/6 gini(S2) gini(S1) = 1 - [(2/2) 2 ] = 0 gini(S2) = 1 - [(2/4)2 +(2/4)2 ] = 0.5 ginisplit3 =3/6 gini(S1) +3/6 gini(S2) gini(S1) = 1 - [(3/3) 2 ] = 0 gini(S2) = 1 - [(1/3)2 +(2/3)2 ] = 0.444 ginisplit4 =4/6 gini(S1) +2/6 gini(S2) gini(S1) = 1 - [(3/4) 2 +(1/4) 2 ] = 0.375 gini(S2) = 1 - [(1/2)2 +(1/2)2 ] = 0.5 ginisplit5 =5/6 gini(S1) +1/6 gini(S2) gini(S1) = 1 - [(4/5) 2 +(1/5) 2 ] = 0.320 gini(S2) = 1 - [(1/1)2 ] = 0 ginisplit5 =6/6 gini(S1) +0/6 gini(S2) gini(S1) = 1 - [(4/6) 2 +(2/6) 2 ] = 0.320 Example ginisplit0 = 0.444 ginisplit1= 0.156 ginisplit2= 0.333 ginisplit3= 0.222 ginisplit4= 0.416 ginisplit5= 0.222 Age <= 18.5 ginisplit6= 0.444

  38. Splitting categorical attributes Single scan through the attribute list collecting counts on count matrix for each combination of class label + attribute value

  39. ginisplit(family)= 3/6 gini(S1) + 3/6 gini(S2) gini(S1) = 1 - [(2/3)2 + (1/3)2] = 4/9 gini(S2) = 1- [(2/3)2 + (1/3)2] = 4/9 ginisplit((sports)= 2/6 gini(S1) + 4/6 gini(S2) gini(S1) = 1 - [(2/2)2] = 0 gini(S2) = 1- [(2/4)2 + (2/4)2] = 0.5 ginisplit(truck)= 1/6 gini(S1) + 5/6 gini(S2) gini(S1) = 1 - [(1/1)2] = 0 gini(S2) = 1- [(4/5)2 + (1/5)2] = 0.32 Example ginisplit(family)= 0.444 ginisplit((sports) )= 0.333 ginisplit(truck) )= 0.266 Car Type = Truck

  40. Example (2 attributes) The winner is Age <= 18.5 Y N H

  41. Performing the split • Create 2 child nodes • Split attribute lists for winning attribute • For the remaining • Insert Tuple Ids in Hash Table (which child) • Scan lists of attributes and probe hash table (may be too large and need several steps).

  42. Drawbacks • Large explosion of space (possibly tripling the size of database). • Costly Hash-Join.

  43. Chapter 7. Classification and Prediction • What is classification? What is prediction? • Classification by decision tree induction • Bayesian Classification • Other methods (SVM) • Classification accuracy • Prediction • Summary

  44. Bayesian Theorem • Given training data D, posteriori probability of a hypothesis h, P(h|D) follows the Bayes theorem • MAP (maximum posteriori) hypothesis • Practical difficulty: require initial knowledge of many probabilities, significant computational cost

  45. Naïve Bayes Classifier (I) • A simplified assumption: attributes are conditionally independent: • Greatly reduces the computation cost, only count the class distribution.

  46. Example

  47. Naive Bayesian Classifier (II) • Given a training set, we can compute the probabilities

  48. (2/9x 3/9 x 6/9 x Example E ={outlook = sunny, temp = [64,70], humidity= [65,70], windy = y} = {E1,E2,E3,E4} Pr[“Play”/E] = (Pr[E1/Play] x Pr[E2/Play] x Pr[E3/Play] x Pr[E4/Play] x Pr[Play]) / Pr[E] = 3/9x 9/14)/Pr[E] = 0.0105/Pr[E] Pr[“Don’t”/E] = (3/5 x 1/5 x 1/5 x 3/5 x 5/14)/Pr[E] = 0.005/Pr[E] With E: Pr[“Play”/E] = 67.7 %, Pr[“Don’t”/E] = 32.3 %

  49. Bayesian Belief Networks (I) Family History Smoker (FH, S) (FH, ~S) (~FH, S) (~FH, ~S) LC 0.7 0.8 0.5 0.1 LungCancer Emphysema ~LC 0.3 0.2 0.5 0.9 The conditional probability table for the variable LungCancer PositiveXRay Dyspnea Bayesian Belief Networks

  50. Bayesian Belief Networks (II) • Bayesian belief network allows a subset of the variables conditionally independent • A graphical model of causal relationships • Several cases of learning Bayesian belief networks • Given both network structure and all the variables: easy • Given network structure but only some variables • When the network structure is not known in advance