Question? Leave a message!




Classification and regression

Classification and regression
Classification WWW.ThesisScientist.comClassification and regression  What is classification What is regression  Classification by decision tree induction  Bayesian Classification  Other Classification Methods  Rule based  KNN  SVM  Bagging/Boosting WWW.ThesisScientist.comRuleBased Classifier Classify records by using a collection of “if…then…” rules 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 WWW.ThesisScientist.comRulebased Classifier (Example) Name Blood Type Give Birth Can Fly Live in Water Class human warm yes no no mammals python cold no no no reptiles salmon cold no no yes fishes whale warm yes no yes mammals frog cold no no sometimes amphibians komodo cold no no no reptiles bat warm yes yes no mammals pigeon warm no yes no birds cat warm yes no no mammals leopard shark cold yes no yes fishes turtle cold no no sometimes reptiles penguin warm no no sometimes birds porcupine warm yes no no mammals eel cold no no yes fishes salamander cold no no sometimes amphibians gila monster cold no no no reptiles platypus warm no no no mammals owl warm no yes no birds dolphin warm yes no yes mammals eagle warm no yes no 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 WWW.ThesisScientist.comApplication of RuleBased Classifier  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 Blood Type Give Birth Can Fly Live in Water Class hawk warm no yes no grizzly bear warm yes no no The rule R1 covers a hawk = Bird The rule R3 covers the grizzly bear = Mammal WWW.ThesisScientist.comRule Coverage and Accuracy Tid Refund Marital Taxable Class Status Income Coverage of a rule: 1 Yes Single 125K No  Fraction of records 2 No Married 100K No that satisfy the 3 No Single 70K No antecedent of a rule 4 Yes Married 120K No 5 No Divorced 95K Yes Accuracy of a rule: 6 No Married 60K No  Fraction of records 7 Yes Divorced 220K No that satisfy both the 8 No Single 85K Yes antecedent and 9 No Married 75K No consequent of a 10 No Single 90K Yes 10 rule (Status=Single)  No WWW.ThesisScientist.com Coverage = 40, Accuracy = 50How does Rulebased 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 Blood Type Give Birth Can Fly Live in Water Class lemur warm yes no no turtle cold no no sometimes dogfish shark cold yes no 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 WWW.ThesisScientist.comCharacteristics of RuleBased Classifier Mutually exclusive rules  Classifier contains mutually exclusive rules if the rules are independent of each other  Every record is covered by at most one rule Exhaustive rules  Classifier has exhaustive coverage if it accounts for every possible combination of attribute values  Each record is covered by at least one rule WWW.ThesisScientist.comFrom Decision Trees To Rules Classification Rules Refund (Refund=Yes) == No Yes No (Refund=No, Marital Status=Single,Divorced, NO NO Marital Taxable Income80K) == No Status Single, (Refund=No, Marital Status=Single,Divorced, Married Divorced Taxable Income80K) == Yes NO NO Taxable (Refund=No, Marital Status=Married) == No Income 80K 80K NO NO Y YE ES S Rules are mutually exclusive and exhaustive Rule set contains as much information as the tree WWW.ThesisScientist.comRules Can Be Simplified Tid Refund Marital Taxable Refund Cheat Status Income Yes No 1 Yes Single 125K No NO NO Marital 2 No 100K Married No Status Single, Married 3 No Single 70K No Divorced 4 Yes Married 120K No NO NO Taxable 5 No Divorced 95K Yes Income 6 No Married 60K No 80K 80K 7 Yes Divorced 220K No NO NO Y YE ES S 8 No Single 85K Yes 9 No Married 75K No 10 No Single 90K Yes 10 Initial Rule: (Refund=No)  (Status=Married)  No WWW.ThesisScientist.com Simplified Rule: (Status=Married)  NoEffect of Rule Simplification Rules are no longer mutually exclusive  A record may trigger more than one rule  Solution  Ordered rule set  Unordered rule set – use voting schemes Rules are no longer exhaustive  A record may not trigger any rules  Solution  Use a default class WWW.ThesisScientist.comOrdered Rule Set  Rules are rank ordered according to their priority  An ordered rule set is known as a decision list  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 Blood Type Give Birth Can Fly Live in Water Class WWW.ThesisScientist.com turtle cold no no sometimes Rule Ordering Schemes Rulebased ordering  Individual rules are ranked based on their quality Classbased ordering  Rules that belong to the same class appear together Rulebased Ordering Classbased Ordering (Refund=Yes) == No (Refund=Yes) == No (Refund=No, Marital Status=Single,Divorced, (Refund=No, Marital Status=Single,Divorced, Taxable Income80K) == No Taxable Income80K) == No (Refund=No, Marital Status=Single,Divorced, (Refund=No, Marital Status=Married) == No Taxable Income80K) == Yes (Refund=No, Marital Status=Single,Divorced, (Refund=No, Marital Status=Married) == No Taxable Income80K) == Yes WWW.ThesisScientist.comBuilding Classification Rules Direct Method:  Extract rules directly from data  e.g.: RIPPER, CN2, Holte’s 1R Indirect Method:  Extract rules from other classification models (e.g. decision trees, etc).  e.g: C4.5 rules WWW.ThesisScientist.comDirect Method: Sequential Covering 1. Start from an empty rule 2. Grow a rule using the LearnOneRule function 3. Remove training records covered by the rule 4. Repeat Step (2) and (3) until stopping criterion is met WWW.ThesisScientist.comExample of Sequential Covering (i) Original Data (ii) Step 1 WWW.ThesisScientist.comExample of Sequential Covering… R1 R1 R2 (iii) Step 2 (iv) Step 3 WWW.ThesisScientist.comAspects of Sequential Covering Rule Growing Instance Elimination Rule Evaluation Stopping Criterion Rule Pruning WWW.ThesisScientist.comRule Growing  Two common strategies Yes: 3 Refund=No, Refund=No, No: 4 Status=Single, Status=Single, Income=85K Income=90K (Class=Yes) (Class=Yes) Income Refund= Refund=No, Status = Status = Status = ... 80K No Single Divorced Status = Single Married (Class = Yes) Yes: 3 Yes: 2 Yes: 1 Yes: 0 Yes: 3 No: 4 No: 1 No: 0 No: 3 No: 1 (b) Specifictogeneral (a) Generaltospecific WWW.ThesisScientist.comRule Growing (Examples)  CN2 Algorithm:  Start from an empty conjunct:  Add conjuncts that minimizes the entropy measure: A, A,B, …  Determine the rule consequent by taking majority class of instances covered by the rule  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, 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 WWW.ThesisScientist.comInstance Elimination  Why do we need to eliminate instances R3 R2  Otherwise, the next rule R1 + + + + + is identical to previous + + + + + + + + rule + + + class = + + + + + + + + + +  Why do we remove + + + + positive instances  Ensure that the next rule class = is different  Why do we remove negative instances  Prevent underestimating accuracy of rule  Compare rules R2 and R3 in the diagram WWW.ThesisScientist.comRule Evaluation Metrics: n c   Accuracy n n : Number of instances n1 c covered by rule  Laplace  nk n : Number of instances c covered by rule k : Number of classes nkp c  Mestimate  p : Prior probability nk WWW.ThesisScientist.comStopping Criterion and Rule Pruning Stopping criterion  Compute the gain  If gain is not significant, discard the new rule Rule Pruning  Similar to postpruning of decision trees  Reduced Error Pruning:  Remove one of the conjuncts in the rule  Compare error rate on validation set before and after pruning  If error improves, prune the conjunct WWW.ThesisScientist.comSummary of Direct Method Grow a single rule Remove Instances from rule Prune the rule (if necessary) Add rule to Current Rule Set Repeat WWW.ThesisScientist.comDirect Method: RIPPER  For 2class 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 multiclass 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 WWW.ThesisScientist.comDirect Method: RIPPER  Growing a rule:  Start from empty rule  Add conjuncts as long as they improve FOIL’s information gain  Stop when rule no longer covers positive examples  Prune the rule immediately using incremental reduced error pruning  Measure for pruning: v = (pn)/(p+n)  p: number of positive examples covered by 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 WWW.ThesisScientist.comDirect Method: RIPPER 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 WWW.ThesisScientist.comIndirect Methods P No Yes Rule Set Q R No Yes No Yes r1: (P=No,Q=No) == r2: (P=No,Q=Yes) == + Q + + r3: (P=Yes,R=No) == + r4: (P=Yes,R=Yes,Q=No) == No Yes r5: (P=Yes,R=Yes,Q=Yes) == + + WWW.ThesisScientist.comIndirect Method: C4.5rules Extract rules from an unpruned decision tree For each rule, r: A  y,  consider an alternative rule r’: A’  y where 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 pessimistic error rate  Repeat until we can no longer improve generalization error WWW.ThesisScientist.comIndirect Method: C4.5rules Instead of ordering the rules, order subsets of rules (class ordering)  Each subset is a collection of rules with 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) WWW.ThesisScientist.comExample Name Give Birth Lay Eggs Can Fly Live in Water Have Legs Class human yes no no no yes mammals python no yes no no no reptiles salmon no yes no yes no fish whale yes no no yes no mammals frog no yes no sometimes yes amphibians komodo no yes no no yes reptiles bat yes no yes no yes mammals pigeon no yes yes no yes birds cat yes no no no yes mammals leopard shark yes no no yes no fish turtle no yes no sometimes yes reptiles penguin no yes no sometimes yes birds porcupine yes no no no yes mammals eel no yes no yes no fish salamander no yes no sometimes yes amphibians gila monster no yes no no yes reptiles platypus no yes no no yes mammals owl no yes yes no yes birds dolphin yes no no yes no mammals eagle no yes yes no yes birds WWW.ThesisScientist.comC4.5 versus C4.5rules versus RIPPER C4.5rules: Give (Give Birth=No, Can Fly=Yes)  Birds Birth (Give Birth=No, Live in Water=Yes)  Fish Yes No (Give Birth=Yes)  Mammals (Give Birth=No, Can Fly=No, Live in Water=No)  Reptiles Mammals Live In ( )  Amphibians Water RIPPER: Yes No (Live in Water=Yes)  Fish (Have Legs=No)  Reptiles Sometimes (Give Birth=No, Can Fly=No, Live In Water=No)  Reptiles Can Fishes Amphibians Fly (Can Fly=Yes,Give Birth=No)  Birds ()  Mammals No Yes Birds Reptiles WWW.ThesisScientist.comC4.5 versus C4.5rules versus RIPPER C4.5 and C4.5rules: PREDICTED CLASS Amphibians Fishes Reptiles Birds Mammals ACTUAL Amphibians 2 0 0 0 0 CLASS Fishes 0 2 0 0 1 Reptiles 1 0 3 0 0 Birds 1 0 0 3 0 Mammals 0 0 1 0 6 RIPPER: PREDICTED CLASS Amphibians Fishes Reptiles Birds Mammals ACTUAL Amphibians 0 0 0 0 2 CLASS Fishes 0 3 0 0 0 Reptiles 0 0 3 0 1 Birds 0 0 1 2 1 Mammals 0 2 1 0 4 WWW.ThesisScientist.comAdvantages of RuleBased Classifiers As highly expressive as decision trees Easy to interpret Easy to generate Can classify new instances rapidly Performance comparable to decision trees WWW.ThesisScientist.comNearest Neighbor Classifiers Basic idea:  If it walks like a duck, quacks like a duck, then it’s probably a duck Compute Test Distance Record Training Choose k of the Records “nearest” records WWW.ThesisScientist.comNearestNeighbor Classifiers  Requires three things Unknown record – The set of stored records – Distance Metric to compute distance between records – The value of k, the number of nearest neighbors to retrieve  To classify an unknown record: – Compute distance to other training records – Identify k nearest neighbors – Use class labels of nearest neighbors to determine the class label of unknown record (e.g., by taking majority vote) WWW.ThesisScientist.comDefinition of Nearest Neighbor X X X (a) 1nearest neighbor (b) 2nearest neighbor (c) 3nearest neighbor Knearest neighbors of a record x are data points that have the k smallest distance to x WWW.ThesisScientist.comNearest Neighbor Classification Compute distance between two points:  Euclidean distance 2 d(p,q)(pq ) i i i Determine the class from nearest neighbor list  take the majority vote of class labels among the knearest neighbors  Weigh the vote according to distance 2  weight factor, w = 1/d WWW.ThesisScientist.comNearest Neighbor Classification… Choosing the value of k:  If k is too small, sensitive to noise points  If k is too large, neighborhood may include points from other classes X WWW.ThesisScientist.comNearest Neighbor Classification… Scaling issues  Attributes may have to be scaled to prevent distance measures from being dominated 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 WWW.ThesisScientist.comNearest Neighbor Classification… Problem with Euclidean measure:  High dimensional data  curse of dimensionality  Can produce counterintuitive results 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 vs 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 d = 1.4142 d = 1.4142  Solution: Normalize the vectors to unit length WWW.ThesisScientist.comNearest neighbor Classification… kNN classifiers are lazy learners  It does not build models explicitly  Unlike eager learners such as decision tree induction and rulebased systems  Classifying unknown records are relatively expensive WWW.ThesisScientist.comSupport Vector Machines  Find a linear hyperplane (decision boundary) that will separate WWW.ThesisScientist.com the dataSupport Vector Machines B 1  One Possible Solution WWW.ThesisScientist.comSupport Vector Machines B 2  Another possible solution WWW.ThesisScientist.comSupport Vector Machines B 2  Other possible solutions WWW.ThesisScientist.comSupport Vector Machines B 1 B 2  Which one is better B1 or B2  How do you define better WWW.ThesisScientist.comSupport Vector Machines B 1 B 2 b 21 b 22 margin b 11 b 12  Find hyperplane maximizes the margin = B1 is better than B2 WWW.ThesisScientist.comSupport Vector Machines B 1  wxb 0  wxb1  wxb1 b 11 2 Margin   b 2 12  w 1 if w x b 1  f (x)   1 if w x b1  WWW.ThesisScientist.comSupport Vector Machines 2 We want to maximize: Margin   2 w  2 w  Which is equivalent to minimizing: L(w) 2  But subjected to the following constraints:  1 if w x b 1   i f (x )   i 1 if w x b1  i  This is a constrained optimization problem  Numerical approaches to solve it (e.g., quadratic programming) WWW.ThesisScientist.comSupport Vector Machines What if the problem is not linearly separable WWW.ThesisScientist.comSupport Vector Machines What if the problem is not linearly separable  Introduce slack variables  2 N w  k  Need to minimize: L(w)C   i 2  i1  Subject to:  1 if w x b 1   i i f (x )   i 1 if w x b1  i i WWW.ThesisScientist.comNonlinear Support Vector Machines What if decision boundary is not linear WWW.ThesisScientist.comNonlinear Support Vector Machines Transform data into higher dimensional space WWW.ThesisScientist.comEnsemble Methods Construct a set of classifiers from the training data Predict class label of previously unseen records by aggregating predictions made by multiple classifiers WWW.ThesisScientist.comGeneral Idea Original D Training data Step 1: .... Create Multiple D D D D 2 1 t1 t Data Sets Step 2: Build Multiple C C C C 1 2 t 1 t Classifiers Step 3: Combine C Classifiers WWW.ThesisScientist.comWhy does it work Suppose there are 25 base classifiers  Each classifier has error rate,  = 0.35  Assume classifiers are independent  Probability that the ensemble classifier makes a wrong prediction: 25 25  i 25i  (1 ) 0.06    i i13  WWW.ThesisScientist.comExamples of Ensemble Methods How to generate an ensemble of classifiers  Bagging  Boosting WWW.ThesisScientist.com(Evaluating the Accuracy of a Classifier)  Bootstrap  Works well with small data sets  Samples the given training tuples uniformly with replacement  i.e., each time a tuple is selected, it is equally likely to be selected again and readded to the training set  Several boostrap methods, and a common one is .632 boostrap  Suppose we are given a data set of d tuples. The data set is sampled d times, with replacement, resulting in a training set of d samples. The data tuples that did not make it into the training set end up forming the test set. About 63.2 of the original data will end up in the bootstrap, and d 1 the remaining 36.8 will form the test set (since (1 – 1/d) ≈ e = 0.368)  Repeat the sampling procedue k times, overall accuracy of the k acc(M ) (0.632acc(M )0.368acc(M ) )  i test set i trainset model: i1 WWW.ThesisScientist.comBagging Sampling with replacement Original Data 1 2 3 4 5 6 7 8 9 10 Bagging (Round 1) 7 8 10 8 2 5 10 10 5 9 Bagging (Round 2) 1 4 9 1 2 3 2 7 3 2 Bagging (Round 3) 1 8 5 10 5 5 9 6 3 7 Build classifier on each bootstrap sample n Each sample has probability (1 – 1/n) of being selected WWW.ThesisScientist.comBoosting An iterative procedure to adaptively change distribution of training data by focusing more on previously misclassified records  Initially, all N records are assigned equal weights  Unlike bagging, weights may change at the end of boosting round WWW.ThesisScientist.comBoosting Records that are wrongly classified will have their weights increased Records that are classified correctly will have their weights decreased Original Data 1 2 3 4 5 6 7 8 9 10 Boosting (Round 1) 7 3 2 8 7 9 4 10 6 3 Boosting (Round 2) 5 4 9 4 2 5 1 7 4 2 Boosting (Round 3) 4 4 8 10 4 5 4 6 3 4 • Example 4 is hard to classify • Its weight is increased, therefore it is more likely to be chosen again in subsequent rounds WWW.ThesisScientist.comExample: AdaBoost  Base classifiers: C , C , …, C 1 2 T  Error rate: N 1  wC (x ) y  i j i j j N j1  Importance of a classifier:  1 1 i   ln i  2  i WWW.ThesisScientist.comExample: AdaBoost Weight update:  j ( j)  exp if C (x ) y w  ( j1) j i i i w  i j Z exp if C (x ) y  j j i i  where Z is the normalization factor j If any intermediate rounds produce error rate higher than 50, the weights are reverted back to 1/n and the resampling procedure is repeated T Classification: C (x) arg maxC (x) y  j j WWW.ThesisScientist.com y j1Evaluating the Accuracy of a Classifier or Predictor (I)  Holdout method  Given data is randomly partitioned into two independent sets  Training set (e.g., 2/3) for model construction  Test set (e.g., 1/3) for accuracy estimation  Random sampling: a variation of holdout  Repeat holdout k times, accuracy = avg. of the accuracies obtained  Crossvalidation (kfold, where k = 10 is most popular)  Randomly partition the data into k mutually exclusive subsets, each approximately equal size  At ith iteration, use D as test set and others as training set i  Leaveoneout: k folds where k = of tuples, for small sized data  Stratified crossvalidation: folds are stratified so that class dist. in each fold is approx. the same as that in the initial data WWW.ThesisScientist.comEvaluating the Accuracy of a Classifier or Predictor (II)  Bootstrap  Works well with small data sets  Samples the given training tuples uniformly with replacement  i.e., each time a tuple is selected, it is equally likely to be selected again and readded to the training set  Several boostrap methods, and a common one is .632 boostrap  Suppose we are given a data set of d tuples. The data set is sampled d times, with replacement, resulting in a training set of d samples. The data tuples that did not make it into the training set end up forming the test set. About 63.2 of the original data will end up in the bootstrap, and d 1 the remaining 36.8 will form the test set (since (1 – 1/d) ≈ e = 0.368) k acc(M ) (0.632acc(M )0.368acc(M ) )  Repeat the sampling procedue k times, overall accuracy of the  i test set i trainset i1 model: WWW.ThesisScientist.comModel Selection: ROC Curves  ROC (Receiver Operating Characteristics) curves: for visual comparison of classification models  Originated from signal detection theory  Shows the tradeoff between the true positive rate and the false positive rate  Vertical axis represents  The area under the ROC curve is a the true positive rate measure of the accuracy of the model  Horizontal axis rep. the  Rank the test tuples in decreasing false positive rate order: the one that is most likely to  The plot also shows a belong to the positive class appears at diagonal line the top of the list  A model with perfect  The closer to the diagonal line (i.e., the accuracy will have an area of 1.0 closer the area is to 0.5), the less accurate is the model WWW.ThesisScientist.com
Website URL
Comment