Data Mining Classification: Alternative Techniques Lecture Notes for Chapter Introduction to Data Mining by Tan, Steinbach, Kumar © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 Rule-Based Classifier z Classify records by using a collection of “if…then…” rules z Rule: (Condition) → y – where Condition is a conjunctions of attributes y is the class label – LHS: rule antecedent or condition – RHS: rule consequent – Examples of classification rules: (Blood Type=Warm) ∧ (Lay Eggs=Yes) → Birds (Taxable Income < 50K) ∧ (Refund=Yes) → Evade=No © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Rule-based Classifier (Example) Name Blood Type human python salmon whale frog komodo bat pigeon cat leopard shark turtle penguin porcupine eel salamander gila monster platypus owl dolphin eagle warm cold cold warm cold cold warm warm warm cold cold warm warm cold cold cold warm warm warm warm Give Birth yes no no yes no no yes no yes yes no no yes no no no no no yes no Can Fly no no no no no no yes yes no no no no no no no no no yes no yes Live in Water no no yes yes sometimes no no no no yes sometimes sometimes no yes sometimes no no no yes no Class mammals reptiles fishes mammals amphibians reptiles mammals birds mammals fishes reptiles birds mammals fishes amphibians reptiles mammals birds mammals birds R1: (Give Birth = no) ∧ (Can Fly = yes) → Birds R2: (Give Birth = no) ∧ (Live in Water = yes) → Fishes R3: (Give Birth = yes) ∧ (Blood Type = warm) → Mammals R4: (Give Birth = no) ∧ (Can Fly = no) → Reptiles R5: (Live in Water = sometimes) → Amphibians © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Application of Rule-Based Classifier z A rule r covers an instance x if the attributes of the instance satisfy the condition of the rule R1: (Give Birth = no) ∧ (Can Fly = yes) → Birds R2: (Give Birth = no) ∧ (Live in Water = yes) → Fishes R3: (Give Birth = yes) ∧ (Blood Type = warm) → Mammals R4: (Give Birth = no) ∧ (Can Fly = no) → Reptiles R5: (Live in Water = sometimes) → Amphibians Name hawk grizzly bear Blood Type warm warm Give Birth Can Fly Live in Water Class no yes yes no no no ? ? The rule R1 covers a hawk => Bird The rule R3 covers the grizzly bear => Mammal © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Rule Coverage and Accuracy Tid Refund Marital Coverage of a rule: Status Yes Single – Fraction of records No Married th t satisfy that ti f the th No Single antecedent of a rule Yes Married No Divorced z Accuracy of a rule: No Married – Fraction of records Yes Divorced that satisfy both the No Single No Married antecedent t d t and d 10 No Single consequent of a (Status=Single) → No rule z Taxable Income Class 125K No 100K No 70K No 120K No 95K Yes 60K No 220K No 85K Yes 75K No 90K Yes 10 Coverage = 40%, Accuracy = 50% © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› How does Rule-based Classifier Work? R1: (Give Birth = no) ∧ (Can Fly = yes) → Birds R2: (Give Birth = no) ∧ (Live in Water = yes) → Fishes R3: (Give Birth = yes) ∧ (Blood Type = warm) → Mammals R4: (Give Birth = no) ∧ (Can Fly = no) → Reptiles R5: (Live in Water = sometimes) → Amphibians Name lemur turtle dogfish shark Blood Type warm cold cold Give Birth Can Fly Live in Water Class yes no yes no no no no sometimes yes ? ? ? A lemur triggers rule R3, so it is classified as a mammal A turtle triggers both R4 and R5 A dogfish shark triggers none of the rules © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Characteristics of Rule-Based Classifier z Mutually exclusive rules – Classifier contains mutually exclusive rules if th rules the l are iindependent d d t off each h other th – Every record is covered by at most one rule z Exhaustive rules – Classifier has exhaustive coverage g if it accounts for every possible combination of attribute values – Each record is covered by at least one rule © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› From Decision Trees To Rules Classification Rules (Refund=Yes) ==> No Refund Yes No NO {Single, Divorced} (Refund=No, Marital Status={Single,Divorced}, Taxable Income No Marita l Status {Married} (Refund=No, Marital Status={Single,Divorced}, Taxable Income>80K) ==> Yes (Refund=No, Marital Status={Married}) ==> No NO Taxable Income < 80K NO > 80K YES Rules are mutually exclusive and exhaustive Rule set contains as much information as the tree © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Rules Can Be Simplified Tid Refund Marital Status Taxable Income Cheat Yes Single 125K No No Married 100K No No Single 70K No Yes Married 120K No No Divorced 95K No Married Yes Divorced 220K No No Single 85K Yes No Married 75K No 10 No Single 90K Yes Refund Yes No NO {Single, Divorced} Marita l Status {Married} NO Taxable Income < 80K > 80K NO YES 60K Yes No 10 Initial Rule: (Refund=No) ∧ (Status=Married) → No Simplified Rule: (Status=Married) → No © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Effect of Rule Simplification z Rules are no longer mutually exclusive – A record may trigger more than one rule – Solution? Ordered rule set Unordered rule set – use voting schemes z Rules are no longer g exhaustive – A record may not trigger any rules – Solution? Use a default class © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Ordered Rule Set z Rules are rank ordered according to their priority – An ordered rule set is known as a decision list z When a test record is presented to the classifier – It is assigned to the class label of the highest ranked rule it has triggered – If none of the rules fired, it is assigned to the default class R1: (Give Birth = no) ∧ (Can Fly = yes) → Birds R2: (Give Birth = no) ∧ (Live in Water = yes) → Fishes R3: (Give Birth = yes) ∧ (Blood Type = warm) → Mammals R4: (Give Birth = no) ∧ (Can Fly = no) → Reptiles R5: (Live in Water = sometimes) → Amphibians Name turtle © Tan,Steinbach, Kumar Blood Type Give Birth Can Fly Live in Water Class no no sometimes ? cold Introduction to Data Mining 9/25/2007 ‹#› Rule Ordering Schemes z Rule-based ordering – Individual rules are ranked based on their quality z Class based ordering Class-based – Rules that belong to the same class appear together © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Building Classification Rules z Direct Method: Extract rules directly from data e.g.: RIPPER, RIPPER CN2 CN2, H Holte’s lt ’ 1R z Indirect Method: Extract rules from other classification models (e.g decision trees, neural networks, etc) e.g: C4.5rules C4 l © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Direct Method: Sequential Covering Start from an empty rule Grow a rule using the Learn-One-Rule function Remove training records covered by the rule Repeat Step (2) and (3) until stopping criterion is met © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Example of Sequential Covering (ii) Step © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Example of Sequential Covering… R1 R1 R2 (iii) Step © Tan,Steinbach, Kumar (iv) Step Introduction to Data Mining 9/25/2007 ‹#› Aspects of Sequential Covering z Rule Growing z Instance Elimination z Rule Evaluation z Stopping Criterion z Rule Pruning © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› 9/25/2007 ‹#› Rule Growing z Two common strategies © Tan,Steinbach, Kumar Introduction to Data Mining Rule Growing (Examples) z CN2 Algorithm: – Start from an empty conjunct: {} – Add conjuncts that minimizes the entropy measure: {A}, {A,B}, … – Determine D t i th the rule l consequentt b by ttaking ki majority j it class l off iinstances t covered by the rule z RIPPER Algorithm: – Start from an empty rule: {} => class – Add conjuncts that maximizes FOIL’s information gain measure: R0: {} => class (initial rule) R1: {A} => class (rule after adding conjunct) Gain(R0, Gain(R0 R1) = t [ log (p1/(p1+n1)) – log (p0/(p0 + n0)) ] where t: number of positive instances covered by both R0 and R1 p0: number of positive instances covered by R0 n0: number of negative instances covered by R0 p1: number of positive instances covered by R1 n1: number of negative instances covered by R1 © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› 9/25/2007 ‹#› Instance Elimination z Why we need to eliminate instances? – Otherwise, the next rule is identical to previous rule z Why we remove positive instances? – Ensure that the next rule is different z Why we remove g instances? negative – Prevent underestimating accuracy of rule – Compare rules R2 and R3 in the diagram © Tan,Steinbach, Kumar Introduction to Data Mining Rule Evaluation z Metrics: – Accuracy – Laplace – = = nc n nc + n+k n + kp M-estimate = c n+k © Tan,Steinbach, Kumar Introduction to Data Mining n : Number of instances covered by rule nc : Number of instances covered by rule k : Number of classes p : Prior probability 9/25/2007 ‹#› Stopping Criterion and Rule Pruning z Stopping criterion – Compute the gain – If gain is not significant significant, discard the new rule z Rule Pruning – Similar to post-pruning of decision trees – Reduced Error Pruning: Remove one off the R th conjuncts j t in i th the rule l Compare error rate on validation set before and after pruning If error improves, prune the conjunct © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Summary of Direct Method z Grow a single rule z Remove Instances from rule z Prune the rule (if necessary) z Add rule to Current Rule Set z Repeat © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Direct Method: RIPPER z z For 2-class problem, choose one of the classes as positive class, and the other as negative class – Learn rules for positive class – Negative class will be default class For multi-class problem – Order the classes according to increasing class prevalence (fraction of instances that belong to a particular class) – Learn the rule set for smallest class first, treat the rest as negative class – Repeat with next smallest class as positive class © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Direct Method: RIPPER z Growing a rule: – Start from empty rule – Add conjuncts j as long g as they y improve p FOIL’s information gain – Stop when rule no longer covers negative examples – Prune the rule immediately using incremental reduced error pruning – Measure for pruning: v = (p-n)/(p+n) p: number of p p positive examples p covered by y the rule in the validation set n: number of negative examples covered by the rule in the validation set – Pruning method: delete any final sequence of conditions that maximizes v © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Direct Method: RIPPER z Building a Rule Set: – Use sequential covering algorithm Finds the best rule that covers the current set of positive examples Eliminate both positive and negative examples covered by the rule – Each time a rule is added to the rule set, compute the new description length stop adding new rules when the new description length is d bits longer than the smallest description length obtained so far © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Direct Method: RIPPER z Optimize the rule set: – For each rule r in the rule set R Consider alternative rules: – Replacement rule (r*): grow new rule from scratch – Revised rule(r’): add conjuncts to extend the rule r Compare the rule set for r against the rule set for r* and r’ Choose rule set that minimizes MDL p principle p – Repeat rule generation and rule optimization for the remaining positive examples © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› 9/25/2007 ‹#› Indirect Methods © Tan,Steinbach, Kumar Introduction to Data Mining Indirect Method: C4.5rules Extract rules from an unpruned decision tree z For each rule, r: A → y, – consider an alternative rule r’: r:A A’ → y where A’ A is obtained by removing one of the conjuncts in A – Compare the pessimistic error rate for r against all r’s – Prune if one of the r’s has lower p pessimistic error rate – Repeat until we can no longer improve generalization error z © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Indirect Method: C4.5rules z Instead of ordering the rules, order subsets of rules (class ordering) – Each E h subset b t iis a collection ll ti off rules l with ith th the same rule consequent (class) – Compute description length of each subset Description length = L(error) + g L(model) g is a parameter that takes into account the presence of redundant attributes in a rule set (default value = 0.5) © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Example Name Give Birth human python salmon whale frog komodo bat pigeon cat leopard shark turtle penguin porcupine eell salamander gila monster platypus owl dolphin eagle yes no no yes no no yes no yes yes no no yes no no no no no yes no Lay Eggs no yes yes no yes yes no yes no no yes yes no yes yes yes yes yes no yes © Tan,Steinbach, Kumar Can Fly no no no no no no yes yes no no no no no no no no no yes no yes Live in Water Have Legs no no yes yes sometimes no no no no yes sometimes sometimes no yes sometimes no no no yes no yes no no no yes yes yes yes yes no yes yes yes no yes yes yes yes no yes Introduction to Data Mining Class mammals reptiles fishes mammals amphibians reptiles mammals birds mammals fishes reptiles birds mammals fi h fishes amphibians reptiles mammals birds mammals birds 9/25/2007 ‹#› C4.5 versus C4.5rules versus RIPPER C4.5rules: Give Birth? (Give Birth=No, Can Fly=Yes) → Birds (Give Birth=No, Live in Water=Yes) → Fishes No Yes ((Give Birth=Yes)) → Mammals (Give Birth=No, Can Fly=No, Live in Water=No) → Reptiles Live In Water? Mammals Yes ( ) → Amphibians RIPPER: No (Live in Water=Yes) → Fishes (Have Legs=No) → Reptiles Sometimes Fishes Yes Birds © Tan,Steinbach, Kumar (Give Birth=No, Can Fly=No, Live In Water=No) → Reptiles Can Fly? Amphibians (Can Fly=Yes,Give Birth=No) → Birds No () → Mammals Reptiles Introduction to Data Mining 9/25/2007 ‹#› C4.5 versus C4.5rules versus RIPPER C4.5 and C4.5rules: PREDICT ED CLASS Amphibians Fishes Reptiles Birds 0 ACT UAL A Amphibians hibi CLASS Fishes Reptiles 0 Birds 0 M ammals 0 M ammals 0 0 M ammals 1 RIPPER: PREDICT ED CLASS Amphibians Fishes Reptiles Birds 0 ACT UAL Amphibians CLASS Fishes 0 Reptiles 0 Birds M ammals © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Advantages of Rule-Based Classifiers As highly expressive as decision trees z Easy to interpret z Easy to generate z Can classify new instances rapidly z Performance comparable to decision trees z © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Instance-Based Classifiers Set of Stored Cases Atr1 …… AtrN Class A • Store the training records • Use training records to predict the class label of unseen cases B B C A Unseen Case Atr1 …… AtrN C B © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Instance Based Classifiers z Examples: – Rote-learner Memorizes entire training data and performs classification only if attributes of record match one of the training examples exactly – Nearest neighbor Uses U k ““closest” l t” points i t ((nearestt neighbors) i hb ) ffor performing classification © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Nearest Neighbor Classifiers z Basic idea: – If it walks like a duck, quacks like a duck, then it’ probably it’s b bl a d duck k Compute Distance Training Records Test Record Choose k of the “nearest” records © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Nearest-Neighbor Classifiers Unknown record z Requires three things – The set of stored records – Distance Metric to compute distance between records – The value of k, the number of nearest neighbors to retrieve z To classify an unknown record: – Compute distance to other training records – Identify Id tif k nearestt neighbors i hb – Use class labels of nearest neighbors to determine the class label of unknown record (e.g., by taking majority vote) © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Definition of Nearest Neighbor X X (b) 2-nearest neighbor (c) 3-nearest neighbor X (a) 1-nearest neighbor K-nearest neighbors of a record x are data points that have the k smallest distance to x © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› 9/25/2007 ‹#› nearest-neighbor Voronoi Diagram © Tan,Steinbach, Kumar Introduction to Data Mining Nearest Neighbor Classification z Compute distance between two points: – Euclidean distance d ( p, q ) = z ∑ ( pi i −q ) i Determine the class from nearest neighbor list – take the majority vote of class labels among the k-nearest neighbors – Weigh the vote according to distance weight factor, w = 1/d2 © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Nearest Neighbor Classification… z Choosing the value of k: – If k is too small, sensitive to noise points – If k is i too t large, l neighborhood i hb h d may iinclude l d points i t ffrom other classes © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Nearest Neighbor Classification… z Scaling issues – Attributes may have to be scaled to prevent di t distance measures ffrom being b i d dominated i t db by one of the attributes – Example: height of a person may vary from 1.5m to 1.8m weight of a person may vary from 90lb to 300lb income of a person may vary from $10K $ to $ $1M © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Nearest Neighbor Classification… z Problem with Euclidean measure: – High dimensional data curse of dimensionality – Can produce counter-intuitive results 111111111110 100000000000 vs 011111111111 000000000001 d = 1.4142 d = 1.4142 Solution: Normalize the vectors to unit length © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Nearest neighbor Classification… z k-NN classifiers are lazy learners – It does not build models explicitly – Unlike eager learners such as decision tree induction and rule-based systems – Classifying unknown records are relatively expensive © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Example: PEBLS z PEBLS: Parallel Examplar-Based Learning System (Cost & Salzberg) – Works W k with ith both b th continuous ti and d nominal i l features For nominal features, distance between two nominal values is computed using modified value difference metric (MVDM) – Each record is assigned a weight factor – Number of nearest neighbor, k = © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› Example: PEBLS Tid Refund Marital Status Taxable Income Cheat Yes Single 125K No d(Single,Married) No Married 100K No = | 2/4 – 0/4 | + | 2/4 – 4/4 | = No Single 70K No d(Single,Divorced) Yes Married 120K No No Divorced 95K Yes No Married No d(Married,Divorced) Yes Divorced 220K No = | 0/4 – 1/2 | + | 4/4 – 1/2 | = No Single 85K Yes d(Refund=Yes,Refund=No) No Married 75K No = | 0/3 – 3/7 | + | 3/3 – 4/7 | = 6/7 10 No Single 90K Yes 60K Distance between nominal attribute values: = | 2/4 – 1/2 | + | 2/4 – 1/2 | = 10 Marital Status Class Refund Single Married Divorced Yes No © Tan,Steinbach, Kumar Class Yes No Yes No d (V1 ,V2 ) = Introduction to Data Mining ∑ i n1i n i − n1 n 9/25/2007 ‹#› Example: PEBLS Tid Refund Marital Status Taxable Income Cheat X Yes Single 125K No Y No Married 100K No 10 Distance between record X and record Y: d Δ ( X , Y ) = w X wY ∑ d ( X i , Yi ) i =1 where: wX = Number of times X is used for p prediction Number of times X predicts correctly wX ≅ if X makes accurate prediction most of the time wX > if X is not reliable for making predictions © Tan,Steinbach, Kumar Introduction to Data Mining 9/25/2007 ‹#› ... Optimize the rule set: – For each rule r in the rule set R Consider alternative rules: – Replacement rule (r*): grow new rule from scratch – Revised rule( r’): add conjuncts to extend the rule r Compare... extend the rule r Compare the rule set for r against the rule set for r* and r’ Choose rule set that minimizes MDL p principle p – Repeat rule generation and rule optimization for the remaining... may trigger more than one rule – Solution? Ordered rule set Unordered rule set – use voting schemes z Rules are no longer g exhaustive – A record may not trigger any rules – Solution? Use