Decision Tree Learning

Slides:



Advertisements
Similar presentations
COMP3740 CR32: Knowledge Management and Adaptive Systems
Advertisements

1 Machine Learning: Lecture 3 Decision Tree Learning (Based on Chapter 3 of Mitchell T.., Machine Learning, 1997)
1er. Escuela Red ProTIC - Tandil, de Abril, Decision Tree Learning 3.1 Introduction –Method for approximation of discrete-valued target functions.
ICS320-Foundations of Adaptive and Learning Systems
Classification Techniques: Decision Tree Learning
Decision Trees.
Decision Trees Instructor: Qiang Yang Hong Kong University of Science and Technology Thanks: Eibe Frank and Jiawei Han.
CS 391L: Machine Learning: Decision Tree Learning
Part 7.3 Decision Trees Decision tree representation ID3 learning algorithm Entropy, information gain Overfitting.
Decision Tree Algorithm
CS 590M Fall 2001: Security Issues in Data Mining Lecture 4: ID3.
Constructing Decision Trees. A Decision Tree Example The weather data example. ID codeOutlookTemperatureHumidityWindyPlay abcdefghijklmnabcdefghijklmn.
Induction of Decision Trees
1 Classification with Decision Trees I Instructor: Qiang Yang Hong Kong University of Science and Technology Thanks: Eibe Frank and Jiawei.
Decision Trees an Introduction.
Decision Trees Chapter 18 From Data to Knowledge.
Decision Tree Learning
For Monday No reading Homework: –Chapter 18, exercises 1 and 2.
Fall 2004 TDIDT Learning CS478 - Machine Learning.
Machine Learning Chapter 3. Decision Tree Learning
Learning what questions to ask. 8/29/03Decision Trees2  Job is to build a tree that represents a series of questions that the classifier will ask of.
Mohammad Ali Keyvanrad
For Wednesday No new reading Homework: –Chapter 18, exercises 3, 4, 7.
For Monday Read chapter 18, sections 5-6 Homework: –Chapter 18, exercises 1-2.
CS Machine Learning 17 Jan CS 391L: Machine Learning: Decision Tree Learning Raymond J. Mooney University of Texas at Austin.
For Wednesday Read chapter 18, section 7 Homework: –Chapter 18, exercise 11.
Lecture 7. Outline 1. Overview of Classification and Decision Tree 2. Algorithm to build Decision Tree 3. Formula to measure information 4. Weka, data.
For Friday No reading No homework. Program 4 Exam 2 A week from Friday Covers 10, 11, 13, 14, 18, Take home due at the exam.
Machine Learning Lecture 10 Decision Tree Learning 1.
CpSc 810: Machine Learning Decision Tree Learning.
Inferring Decision Trees Using the Minimum Description Length Principle J. R. Quinlan and R. L. Rivest Information and Computation 80, , 1989.
CSC 4510 – Machine Learning Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Learning from Observations Chapter 18 Through
Decision-Tree Induction & Decision-Rule Induction
Mehdi Ghayoumi MSB rm 132 Ofc hr: Thur, a Machine Learning.
Data Mining Practical Machine Learning Tools and Techniques Chapter 4: Algorithms: The Basic Methods Section 4.3: Decision Trees Rodney Nielsen Many of.
For Wednesday No reading Homework: –Chapter 18, exercise 6.
For Monday No new reading Homework: –Chapter 18, exercises 3 and 4.
CS 8751 ML & KDDDecision Trees1 Decision tree representation ID3 learning algorithm Entropy, Information gain Overfitting.
MACHINE LEARNING 10 Decision Trees. Motivation  Parametric Estimation  Assume model for class probability or regression  Estimate parameters from all.
1 Universidad de Buenos Aires Maestría en Data Mining y Knowledge Discovery Aprendizaje Automático 5-Inducción de árboles de decisión (2/2) Eduardo Poggi.
CS 5751 Machine Learning Chapter 3 Decision Tree Learning1 Decision Trees Decision tree representation ID3 learning algorithm Entropy, Information gain.
Decision Trees Binary output – easily extendible to multiple output classes. Takes a set of attributes for a given situation or object and outputs a yes/no.
1 Decision Tree Learning Original slides by Raymond J. Mooney University of Texas at Austin.
Decision Trees, Part 1 Reading: Textbook, Chapter 6.
Machine Learning Decision Trees. E. Keogh, UC Riverside Decision Tree Classifier Ross Quinlan Antenna Length Abdomen Length.
Decision Tree Learning
Decision Trees.
Outline Decision tree representation ID3 learning algorithm Entropy, Information gain Issues in decision tree learning 2.
1 CS 343: Artificial Intelligence Machine Learning Raymond J. Mooney University of Texas at Austin.
Decision Trees MSE 2400 EaLiCaRA Dr. Tom Way.
1 Machine Learning Decision Trees Some of these slides are courtesy of R.Mooney, UT Austin and E. Keogh, UC Riverside.
Decision Tree Learning DA514 - Lecture Slides 2 Modified and expanded from: E. Alpaydin-ML (chapter 9) T. Mitchell-ML.
Data Mining Chapter 4 Algorithms: The Basic Methods - Constructing decision trees Reporter: Yuen-Kuei Hsueh Date: 2008/7/24.
Review of Decision Tree Learning Bamshad Mobasher DePaul University Bamshad Mobasher DePaul University.
CSE573 Autumn /11/98 Machine Learning Administrative –Finish this topic –The rest of the time is yours –Final exam Tuesday, Mar. 17, 2:30-4:20.
DECISION TREES An internal node represents a test on an attribute.
Decision Trees an introduction.
Decision Tree Learning
For Friday No reading Homework: Program 3 due
Classification Algorithms
Artificial Intelligence
Ch9: Decision Trees 9.1 Introduction A decision tree:
Machine Learning: Decision Tree Learning
Data Science Algorithms: The Basic Methods
Decision Tree Saed Sayad 9/21/2018.
Machine Learning Chapter 3. Decision Tree Learning
Machine Learning: Lecture 3
Machine Learning Chapter 3. Decision Tree Learning
Presentation transcript:

Decision Tree Learning

Decision Trees Tree-based classifiers for instances represented as feature-vectors. Nodes test features, there is one branch for each value of the feature, and leaves specify the category. Can represent arbitrary conjunction and disjunction. Can represent any classification function over discrete feature vectors. Can be rewritten as a set of rules, i.e. disjunctive normal form (DNF). red  circle → pos red  circle → A blue → B; red  square → B green → C; red  triangle → C color red blue green shape circle square triangle neg pos B C A

Buy a present: another toy example

A more realistic example: buy or build or stay?

Project investment (The project portfolio is optimized against a constraint (budget available).

Properties of Decision Tree Learning Continuous (real-valued) features can be handled by allowing nodes to split a real valued feature into two ranges based on a threshold (e.g. length < 3 and length 3) Classification trees have discrete class labels at the leaves, regression trees allow real-valued outputs at the leaves. Algorithms for finding consistent trees are efficient for processing large amounts of training data for data mining tasks. Methods developed for handling noisy training data (both class and feature noise). Methods developed for handling missing feature values.

Top-Down Decision Tree Induction Recursively build a tree top-down by divide and conquer. <big, red, circle>: + <small, red, circle>: + <small, red, square>:  <big, blue, circle>:  color red blue green <big, red, circle>: + <small, red, circle>: + <small, red, square>: 

Top-Down Decision Tree Induction Recursively build a tree top-down by divide and conquer. <big, red, circle>: + <small, red, circle>: + <small, red, square>:  <big, blue, circle>:  color red blue green <big, red, circle>: + <small, red, circle>: + <small, red, square>:  shape circle square triangle neg neg <big, blue, circle>:  pos neg pos <big, red, circle>: + <small, red, circle>: + <small, red, square>:  How do we decide the order in which we test attributes? How do we decide the class of nodes for which we have no examples? Let’s ignore for now these 2 issues and describe the algorithm first

Decision Tree Induction Pseudocode DTree(examples, features) returns a tree a)If all examples are in one category, return a leaf node with that category label. b)Else if the set of features is empty, return a leaf node with the category label that is the most common in examples. Else pick a feature F and create a node R for it For each possible value vi of F: Let examplesi be the subset of examples that have value vi for F Add an out-going edge E to node R labeled with the value vi. If examplesi is empty then attach a leaf node to edge E labeled with the category that else call DTree(examplesi , features – {F}) and attach the resulting tree as the subtree under edge E. Return the subtree rooted at R. color red e.g.”color” e.g. color=red a) and b) are the termination conditions

Example (1) Examples: <big, red, circle>: + <small, red, circle>: + <small, red, square>:  <big, blue, circle>:  pick a feature F and create a node R for it, eg. color color For each possible value vi of F: Let examplesi be the subset of examples that have value vi for F Add an out-going edge E to node R labeled with the value vi. color <big, red, circle>: + <small, red, circle>: + <small, red, square>:  red if (…) else call DTree(examplesi , features – {F}) and attach the resulting tree as the subtree under edge E. Dtree( , <dimension,shape>) <big, red, circle>: + <small, red, circle>: + <small, red, square>: 

Example (2) DTree( , <dimension,shape>) <big, red, circle>: + <small, red, circle>: + <small, red, square>:  pick a feature F and create a node R for it, eg. shape color red shape circle <big, red, circle>: + <small, red, circle>: + triangle square <small, red, square>:  positive negative positive If all examples are in one category, return a leaf node with that category label. If examplesi is empty. then attach a leaf node to edge E labeled with the category that is the most common in examples.

Example (3) <big, blue, circle>:  color red blue green <big, red, circle>: + <small, red, circle>: + <small, red, square>:  shape circle square triangle neg neg <big, blue, circle>:  pos neg pos <big, red, circle>: + <small, red, circle>: + <small, red, square>:  Now we know how to decide the class when we have no examples, but how do we decide the order in which we create nodes?

Picking a Good Split Feature Goal is to have the resulting tree be as small as possible, per Occam’s razor. Finding a minimal decision tree (nodes, leaves, or depth) is an NP-hard optimization problem. Top-down divide-and-conquer method does a greedy search for a simple tree but does not guarantee to find the smallest. General lesson in ML: “Greed is good.” Want to pick a feature that creates subsets of examples that are relatively “pure” in a single class so they are “closer” to being leaf nodes. There are a variety of heuristics for picking a good test, a popular one is based on information gain that originated with the ID3 system of Quinlan (1979).

Entropy Entropy (disorder, impurity) of a set of examples, S, relative to a binary classification is: where p1 is the fraction of positive examples in S and p0 is the fraction of negatives. (Notice that Entropy(S) is an estimate of the population entropy) If all examples are in one category, entropy is zero (we define 0log(0)=0) If examples are equally mixed (p1=p0=0.5), entropy is a maximum of 1. Entropy can be viewed as the number of bits required on average to encode the class of an example in S. It is also an estimate of the initial “disorder” or “uncertainty” about a classification, given the set S. For multi-class problems with c categories, entropy generalizes to:

Entropy Plot for Binary Classification

Information Gain The information gain of a feature F (as we have seen) is the expected reduction in entropy resulting from splitting on this feature. where Sv is the subset of S having value v for feature F. Entropy of each resulting subset weighted by its relative size. Example: <big, red, circle>: + <small, red, circle>: + <small, red, square>:  <big, blue, circle>:  2+, 2  : E=1 shape circle square 2+,1 0+,1 E=0.918 E=0 Gain=1(0.750.918 + 0.250) = 0.311 2+, 2 : E=1 size big small 1+,1 1+,1 E=1 E=1 Gain=1(0.51 + 0.51) = 0 2+, 2  : E=1 color red blue 2+,1 0+,1 E=0.918 E=0 Gain=1(0.750.918 + 0.250) = 0.311

New pseudo-code DTree(examples, features) returns a tree a)If all examples are in one category, return a leaf node with that category label. b)Else if the set of features is empty, return a leaf node with the category label that is the most common in examples. Else pick the best feature F according to IG and create a node R for it For each possible value vi of F: Let examplesi be the subset of examples that have value vi for F Add an out-going edge E to node R labeled with the value vi. If examplesi is empty then attach a leaf node to edge E labeled with the category that else call DTree(examplesi , features – {F}) and attach the resulting tree as the subtree under edge E. Return the subtree rooted at R.

A complete example

A Decision Tree for weather data The weather data example. ID code Outlook Temperature Humidity Windy Play a b c d e f g h i j k l m n Sunny Overcast Rainy Hot Mild Cool High Normal False True No Yes

The Process of Constructing a Decision Tree Select an attribute to place at the root of the decision tree and make one branch for every possible value. Repeat the process recursively for each branch.

Information Gained by Knowing the Result of a Decision In the weather data example, there are 9 instances of which the decision to play is “yes” and there are 5 instances of which the decision to play is “no’. Then, the information gained by knowing the result of the decision is

The General Form for Calculating the Information Gain Entropy of a decision = P1, P2, …, Pn are the probabilities of the n possible outcomes.

Information Further Required If “Outlook” Is Placed at the Root yes no sunny overcast rainy

Information Gained by Placing Each of the 4 Attributes Gain(outlook) = 0.940 bits – 0.693 bits = 0.247 bits. Gain(temperature) = 0.029 bits. Gain(humidity) = 0.152 bits. Gain(windy) = 0.048 bits.

The Strategy for Selecting an Attribute to Place at a Node Select the attribute that gives us the largest information gain. In this example, it is the attribute “Outlook”. Outlook 2 “yes” 3 “no” 4 “yes” 3 “yes” 2 “no” sunny overcast rainy

The Recursive Procedure for Constructing a Decision Tree Apply to each branch recursively to construct the decision tree. For example, for the branch “Outlook = Sunny”, we evaluate the information gained by applying each of the remaining 3 attributes. Gain(Outlook=sunny;Temperature) = 0.971 – 0.4 = 0.571 Gain(Outlook=sunny;Humidity) = 0.971 – 0 = 0.971 Gain(Outlook=sunny;Windy) = 0.971 – 0.951 = 0.02

Recursive selection Similarly, we also evaluate the information gained by applying each of the remaining 3 attributes for the branch “Outlook = rainy”. Gain(Outlook=rainy;Temperature) = 0.971 – 0.951 = 0.02 Gain(Outlook=rainy;Humidity) = 0.971 – 0.951 = 0.02 Gain(Outlook=rainy;Windy) =0.971 – 0 = 0.971

The resulting tree Outlook humidity windy yes no sunny overcast rainy high normal false true

DT can be represented as a set of rules Outlook humidity windy yes no sunny overcast rainy high normal false true IF Outlook=sunny AND humidity=high  no IF Outlook=sunny AND humidity=normal yes IF Outlook=overcast  yes IF Outlook=rainy AND windy=false yes IF Outlook=rainy AND windy=true no

Support and Confidence Each rule as a support |Sv|/|S| represented by the set of examples that fit the rule Each rule has also a confidence which might or might not be equal to support. Remember one of the 2 “exit” conditions in the algorithm: Else if the set of features is empty, return a leaf node with the category label that is the most common in examples. Hence the set of examples |Sv| does NOT has a uniform classification, but, say, |Sv+| positive and |Sv-| negative, if |Sv+| >|Sv-| class is pos, support is |Sv+|/|S| and confidence is |Sv+| /|Sv|

Example Outlook 2 “yes” 3 “no” 4 “yes” 3 “yes” 2 “no” sunny overcast rainy Support=3/14 Confidence=3/5 IF Outlook=sunny THEN no

Hypothesis Space Search in DL Performs batch learning that processes all training instances at once rather than incremental learning (e.g. like VS) that updates a hypothesis after each example. Performs hill-climbing (greedy search) that may only find a locally-optimal solution. Guaranteed to find a tree consistent with any conflict-free training set (i.e. identical feature vectors always assigned the same class), but not necessarily the simplest tree. Finds a single discrete hypothesis, so there is no way to provide confidences or create useful queries.

Bias in Decision-Tree Induction Information-gain gives a bias for trees with minimal depth. Implements a search (preference) bias instead of a language (restriction) bias (e.g. conjunctive hypotheses only as for VS).

History of Decision-Tree Research Hunt and colleagues use exhaustive search decision-tree methods (CLS) to model human concept learning in the 1960’s. In the late 70’s, Quinlan developed ID3 with the information gain heuristic to learn expert systems from examples. Simulataneously, Breiman and Friedman and colleagues develop CART (Classification and Regression Trees), similar to ID3. In the 1980’s a variety of improvements are introduced to handle noise, continuous features, missing features, and improved splitting criteria. Various expert-system development tools results. Quinlan’s updated decision-tree package (C4.5) released in 1993. Weka includes Java version of C4.5 called J48.

Computational Complexity Worst case builds a complete tree where every path test every feature. Assume n examples and m features. At each level, i, in the tree, must examine the remaining m i features for each instance at that level to calculate info gains. However, learned tree is rarely complete (number of leaves is  n). In practice, complexity is linear in both number of features (m) and number of training examples (n).  F1 Fm  Maximum of n examples spread across all nodes at each of the m levels

Overfitting Learning a tree that classifies the training data perfectly may not lead to the tree with the best generalization to unseen data. There may be noise in the training data that the tree is erroneously fitting. The algorithm may be making poor decisions towards the leaves of the tree that are based on very little data and may not reflect reliable trends. A hypothesis, h, is said to overfit the training data is there exists another hypothesis, h´, such that h has less error than h´ on the training data but greater error on independent test data. hypothesis complexity accuracy on training data on test data

Overfitting example (1)

Overfitting Example (2) Testing Ohms Law: V = IR (I = (1/R)V) Perfect fit to training data with an 9th degree polynomial (can fit n points exactly with an n-1 degree polynomial) Experimentally measure 10 points Fit a curve to the Resulting data. current (I) voltage (V) Ohm was wrong, we have found a more accurate function!

Overfitting Example (3) Testing Ohms Law: V = IR (I = (1/R)V) current (I) voltage (V) Better generalization with a linear function that fits training data less accurately.

Overfitting Noise in Decision Trees Category or feature noise can easily cause overfitting. Add noisy instance <medium, blue, circle>: pos (but really neg) color red blue green shape neg neg circle square triangle pos neg pos

Overfitting Noise in Decision Trees Category or feature noise can easily cause overfitting. Add noisy instance <medium, blue, circle>: pos (but really neg) color red blue green <big, blue, circle>:  <medium, blue, circle>: + shape neg small med big pos neg circle square triangle pos neg pos Conflicting examples can also arise if the features are incomplete and inadequate to determine the class or if the target concept is non-deterministic.

Example (inadequate features) X(has-4-legs, has-tail, has-long-nose, has-big-ears,can-be-ridden) Classes: horse, camel, elephant The missing feature has-hump does not allow to correctly classify a camel

Overfitting Prevention (Pruning) Methods Two basic approaches for decision trees Prepruning: Stop growing tree as some point during top-down construction when there is no longer sufficient data to make reliable decisions (e.g. |Svi|<k). Postpruning: Grow the full tree, then remove subtrees that do not have sufficient evidence. Label leaf resulting from pruning with the majority class of the remaining data, or a class probability distribution. Method for determining which subtrees to prune: Cross-validation: Reserve some training data as a hold-out set (validation set, tuning set) to evaluate utility of subtrees. Statistical test: Use a statistical test on the training data to determine if any observed regularity can be dismisses, as likely due to random chance. Minimum description length (MDL): Determine if the additional complexity of the hypothesis is less complex than just explicitly remembering any exceptions resulting from pruning (e.g. for mammals: wings=false, except for bats).

Reduced Error Pruning A post-pruning, cross-validation approach. Partition training data D in “learning” L and “test” T sets. Build a complete tree from the L data. Until accuracy on validation set decreases do: For each non-leaf node, n, in the tree do: Temporarily prune the subtree below n and replace it with a leaf labeled with the current majority class at that node. Measure and record the accuracy of the pruned tree on the validation set. Permanently prune the node that results in the greatest increase in accuracy on the validation set.

Example <big, blue, circle>:  <medium, blue, circle>: + <small, blue, circle>:  triangle blue shape circle square red green pos neg neg small med big pos neg Majority of “removed” examples under the pruned sub-tree is neg

Issues with Reduced Error Pruning The problem with this approach is that it potentially “wastes” training data on the validation set. Severity of this problem depends where we are on the learning curve: test accuracy number of training examples A learning curve shows the accuracy, e.g. the learning rate, as the number of training examples grows.

Cross-Validating without Loosing Training Data If the algorithm is modified to grow trees breadth-first rather than depth-first (e.g. test all values of a feature first and create all nodes at level i), we can stop growing after reaching any specified tree complexity. First, run several trials of reduced error-pruning using different random splits of learning and test sets. Record the complexity of the pruned tree learned in each trial. Let C be the average pruned-tree complexity (nodes+ edges). Grow a final tree breadth-first from all the training data but stop when the complexity reaches C. Similar cross-validation approach can be used to set arbitrary algorithm parameters in general.

Summary Decision tree algorithm Ordering nodes (Information Gain) Testing and pruning