## Decision Trees

Decision trees are powerful and popular tools for classification and prediction. The attractiveness of decision trees is due to the fact that, in contrast to neural networks, decision trees represent *rules*. Rules can readily be expressed so that humans can understand them or even directly used in a database access language like SQL so that records falling into a particular category may be retrieved.

In some applications, the accuracy of a classification or prediction is the only thing that matters. In such situations we do not necessarily care how or why the model works. In other situations, the ability to explain the reason for a decision, is crucial. In marketing one has describe the customer segments to marketing professionals, so that they can utilize this knowledge in launching a successful marketing campaign. This domain experts must recognize and approve this discovered knowledge, and for this we need good descriptions. There are a variety of algorithms for building decision trees that share the desirable quality of interpretability. A well known and frequently used over the years is C4.5 (or improved, but commercial version See5/C5.0).

### What is a decision tree ?

*Decision tree* is a classifier in the form of a tree structure (see Figure 1), where each node is either:

- a
*leaf node*- indicates the value of the target attribute (class) of examples, or - a
*decision node*- specifies some test to be carried out on a single attribute-value, with one branch and sub-tree for each possible outcome of the test.

A decision tree can be used to classify an example by starting at the root of the tree and moving through it until a leaf node, which provides the classification of the instance.

Decision tree induction is a typical inductive approach to learn knowledge on classification. The key requirements to do mining with decision trees are:

*Attribute-value description*: object or case must be expressible in terms of a fixed collection of properties or attributes. This means that we need to discretize continuous attributes, or this must have been provided in the algorithm.*Predefined classes (target attribute values)*: The categories to which examples are to be assigned must have been established beforehand (supervised data).*Discrete classes*: A case does or does not belong to a particular class, and there must be more cases than classes.*Sufficient data*: Usually hundreds or even thousands of training cases.

Figure 1: An example of a simple decision tree

### Constructing decision trees

Most algorithms that have been developed for learning decision trees are variations on a core algorithm that employs a top-down, greedy search through the space of possible decision trees. Decision tree programs construct a decision tree *T* from a set of training cases.

J. Ross Quinlan originally developed ID3 at the University of Sydney. He first presented ID3 in 1975 in a book, *Machine Learning*, vol. 1, no. 1. ID3 is based on the Concept Learning System (CLS) algorithm.

_______________________________________________________functionID3 Input: (R: a set of non-target attributes, C: the target attribute, S: a training set) returns a decision tree;beginIf S is empty, return a single node with value Failure; If S consists of records all with the same value for the target attribute, return a single leaf node with that value; If R is empty, then return a single node with the value of the most frequent of the values of the target attribute that are found in records of S; [in that case there may be be errors, examples that will be improperly classified]; Let A be the attribute with largest Gain(A,S) among attributes in R; Let {aj| j=1,2, .., m} be the values of attribute A; Let {Sj| j=1,2, .., m} be the subsets of S consisting respectively of records with value aj for A; Return a tree with root labeled A and arcs labeled a1, a2, .., am going respectively to the trees (ID3(R-{A}, C, S1), ID3(R-{A}, C, S2), .....,ID3(R-{A}, C, Sm); Recursively applyID3tosubsets {Sj| j=1,2, .., m} until they are emptyend_______________________________________________________

Figure 2: ID3 Decision Tree Algorithm

ID3 searches through the attributes of the training instances and extracts the attribute that best separates the given examples. If the attribute perfectly classifies the training sets then ID3 stops; otherwise it recursively operates on the m (where m = number of possible values of an attribute) partitioned subsets to get their "best" attribute. The algorithm uses a greedy search, that is, it picks the best attribute and never looks back to reconsider earlier choices. Note that ID3 may misclassify data.

The central focus of the decision tree growing algorithm is selecting which attribute to test at each node in the tree. For the selection of the attribute with the most inhomogeneous class distribution the algorithm uses the concept of entropy, which is explained next

### Which attribute is the best classifier?

The estimation criterion in the decision tree algorithm is the selection of an attribute to test at each decision node in the tree. The goal is to select the attribute that is most useful for classifying examples. A good quantitative measure of the worth of an attribute is a statistical property called *information gain* that measures how well a given attribute separates the training examples according to their target classification. This measure is used to select among the candidate attributes at each step while growing the tree.

### Entropy - a measure of homogeneity of the set of examples

In order to define information gain precisely, we need to define a measure commonly used in information theory, called entropy, that characterizes the (im)purity of an arbitrary collection of examples. Given a set S, containing only positive and negative examples of some target concept (a 2 class problem), the entropy of set S relative to this simple, binary classification is defined as:

Entropy(S) = - p_{p}log_{2} p_{p }– p_{n}log_{2} p_{n}

where p_{p}is the proportion of positive examples in S and p_{n }is the proportion of negative examples in S. In all calculations involving entropy we define 0log0 to be 0.

To illustrate, suppose S is a collection of 25 examples, including 15 positive and 10 negative examples [15+, 10-]. Then the entropy of S relative to this classification is

Entropy(S) = - (15/25) log_{2} (15/25) - (10/25) log_{2} (10/25) = 0.970

Notice that the entropy is 0 if all members of S belong to the same class. For example, if all members are positive (p_{p}= 1 ), then p_{n }is 0, and Entropy(S) = -1´ log_{2}(1) - 0´ log_{2}0 = -1´ 0 - 0´ log_{2}0 = 0. Note the entropy is 1 (at its maximum!) when the collection contains an equal number of positive and negative examples. If the collection contains unequal numbers of positive and negative examples, the entropy is between 0 and 1. Figure 3 shows the form of the entropy function relative to a binary classification, as p_{+} varies between 0 and 1.

Figure 3: The entropy function relative to a binary classification, as the proportion of positive

examples p_{p }varies between 0 and 1.

One interpretation of entropy from information theory is that it specifies the minimum number of bits of information needed to encode the classification of an arbitrary member of S (i.e., a member of S drawn at random with uniform probability). For example, if p_{p} is 1, the receiver knows the drawn example will be positive, so no message need be sent, and the entropy is 0. On the other hand, if p_{p} is 0.5, one bit is required to indicate whether the drawn example is positive or negative. If p_{p }is 0.8, then a collection of messages can be encoded using on average less than 1 bit per message by assigning shorter codes to collections of positive examples and longer codes to less likely negative examples.

Thus far we have discussed entropy in the special case where the target classification is binary. If the target attribute takes on *c* different values, then the entropy of S relative to this *c*-wise classification is defined as

where *p _{i}* is the proportion of S belonging to class

*i*. Note the logarithm is still base 2 because entropy is a measure of the expected encoding length measured in bits. Note also that if the target attribute can take on c possible values, the maximum possible entropy is log

_{2}c.

### Information gain measures the expected reduction in entropy

Given entropy as a measure of the impurity in a collection of training examples, we can now define a measure of the effectiveness of an attribute in classifying the training data. The measure we will use, called *information gain*, is simply the expected reduction in entropy caused by partitioning the examples according to this attribute. More precisely, the information gain, *Gain (S, A) *of an attribute *A*, relative to a collection of examples S, is defined as

where *Values(A)* is the set of all possible values for attribute *A*, and *S _{v}* is the subset of

*S*for which attribute

*A*has value

*v*(i.e.,

*S*{s Î S |

_{v}=*A(s) = v*}). Note the first term in the equation for

*Gain*is just the entropy of the original collection

*S*and the second term is the expected value of the entropy after S is partitioned using attribute

*A*. The expected entropy described by this second term is simply the sum of the entropies of each subset

*S*, weighted by the fraction of examples |

_{v}*S*|/|S| that belong to

_{v}*S*.

_{v}*Gain (S,A)*is therefore the expected reduction in entropy caused by knowing the value of attribute

*A*. Put another way,

*Gain(S,A)*is the information provided about the target attribute value, given the value of some other attribute A. The value of

*Gain(S,A)*is the number of bits saved when encoding the target value of an arbitrary member of

*S*, by knowing the value of attribute

*A*.

The process of selecting a new attribute and partitioning the training examples is now repeated for each non-terminal descendant node, this time using only the training examples associated with that node. Attributes that have been incorporated higher in the tree are excluded, so that any given attribute can appear at most once along any path through the tree. This process continues for each new leaf node until either of two conditions is met:

- every attribute has already been included along this path through the tree, or
- the training examples associated with this leaf node all have the same target attribute value (i.e., their entropy is zero).

### Issues in data mining with decision trees

Practical issues in learning decision trees include determining how deeply to grow the decision tree, handling continuous attributes, choosing an appropriate attribute selection measure, handling training data with missing attribute values, handing attributes with differing costs, and improving computational efficiency. Below we discuss each of these issues and extensions to the basic ID3 algorithm that address them.

### Avoiding over-fitting the data

In principle decision tree algorithm described in Figure 2 can grow each branch of the tree just deeply enough to perfectly classify the training examples. While this is sometimes a reasonable strategy, in fact it can lead to difficulties when there is noise in the data, or when the number of training examples is too small to produce a representative sample of the true target function. In either of these cases, this simple algorithm can produce trees that* over-fit *the training examples.

Over-fitting is a significant practical difficulty for decision tree learning and many other learning methods. There are several approaches to avoiding over-fitting in decision tree learning. These can be grouped into two classes:

- approaches that stop growing the tree earlier, before it reaches the point where it perfectly classifies the training data,
- approaches that allow the tree to over-fit the data, and then post prune the tree.

Although the first of these approaches might seem more direct, the second approach of post-pruning over-fit trees has been found to be more successful in practice. This is due to the difficulty in the first approach of estimating precisely when to stop growing the tree.

Regardless of whether the correct tree size is found by stopping early or by post-pruning, a key question is what criterion is to be used to determine the correct final tree size. Approaches include:

- Use a separate set of examples, distinct from the training examples, to evaluate the utility of post-pruning nodes from the tree.
- Use all the available data for training, but apply a statistical test to estimate whether expanding (or pruning) a particular node is likely to produce an improvement beyond the training set.
- Use an explicit measure of the complexity for encoding the training examples and the decision tree, halting growth of the tree when this encoding size is minimized. This approach is based on a heuristic called the Minimum Description Length principle.

The first of the above approaches is the most common and is often referred to as a training and validation set approach. In this approach, the available data are separated into two sets of examples: a *training set*, which is used to form the learned hypothesis, and a separate *validation set*, which is used to evaluate the accuracy of this hypothesis over subsequent data and, in particular, to evaluate the impact of pruning this hypothesis.

### Incorporating Continuous-Valued Attributes

The initial definition of ID3 is restricted to attributes that take on a discrete set of values. First, the target attribute whose value is predicted by the learned tree must be discrete valued. Second, the attributes tested in the decision nodes of the tree must also be discrete valued. This second restriction can easily be removed so that continuous-valued decision attributes can be incorporated into the learned tree. This can be accomplished by dynamically defining new discrete-valued attributes that partition the continuous attribute value into a discrete set of intervals. In particular, for an attribute *A* that is continuous-valued, the algorithm can dynamically create a new Boolean attribute *A _{c}* that is true if

*A*<

*c*and false otherwise. The only question is how to select the best value for the threshold

*c*. Clearly, we would like to pick a threshold,

*c*, that produces the greatest information gain. By sorting the examples according to the continuous attribute

*A*, then identifying adjacent examples that differ in their target classification, we can generate a set of candidate thresholds midway between the corresponding values of

*A*. It can be shown that the value of

*c*that maximizes information gain must always lie at such a boundary. These candidate thresholds can then be evaluated by computing the information gain associated with each. The information gain can then be computed for each of the candidate attributes, and the best can be selected. This dynamically created Boolean attribute can then compete with the other discrete-valued candidate attributes available for growing the decision tree.

### Handling Training Examples with Missing Attribute Values

In certain cases, the available data may be missing values for some attributes. For example, in a medical domain in which we wish to predict patient outcome based on various laboratory tests, it may be that the lab test Blood-Test-Result is available only for a subset of the patients. In such cases, it is common to estimate the missing attribute value based on other examples for which this attribute has a known value.

Consider the situation in which *Gain(S, A) *is to be calculated at node n in the decision tree to evaluate whether the attribute *A* is the best attribute to test at this decision node. Suppose that <*x, c(x)>* is one of the training examples in *S* and that the value *A(x)* is unknown, where *c(x)* is the class label of *x*.

One strategy for dealing with the missing attribute value is to assign it the value that is most common among training examples at node n. Alternatively, we might assign it the most common value among examples at node n that have the classification *c(x).* The elaborated training example using this estimated value for *A(x)* can then be used directly by the existing decision tree learning algorithm.

A second, more complex procedure is to assign a probability to each of the possible values of *A* rather than simply assigning the most common value to *A(x)*. These probabilities can be estimated again based on the observed frequencies of the various values for *A* among the examples at node n. For example, given a Boolean attribute *A*, if node n contains six known examples with *A* = 1 and four with *A* = 0, then we would say the probability that *A(x)* = 1 is 0.6, and the probability that *A(x)* = 0 is 0.4. A fractional 0.6 of instance x is now distributed down the branch for *A* = 1 and a fractional 0.4 of x down the other tree branch. These fractional examples are used for the purpose of computing information *Gain* and can be further subdivided at subsequent branches of the tree if a second missing attribute value must be tested. This same fractioning of examples can also be applied after learning, to classify new instances whose attribute values are unknown. In this case, the classification of the new instance is simply the most probable classification, computed by summing the weights of the instance fragments classified in different ways at the leaf nodes of the tree. This method for handling missing attribute values is used in C4.5.

### Strengths and Weakness of Decision Tree Methods

The strengths of decision tree methods are:

- Decision trees are able to generate understandable rules.
- Decision trees perform classification without requiring much computation.
- Decision trees are able to handle both continuous and categorical variables.
- Decision trees provide a clear indication of which fields are most important for prediction or classification.

### The weaknesses of decision tree methods

- Decision trees are less appropriate for estimation tasks where the goal is to predict the value of a continuous attribute.
- Decision trees are prone to errors in classification problems with many class and relatively small number of training examples.
- Decision tree can be computationally expensive to train. The process of growing a decision tree is computationally expensive. At each node, each candidate splitting field must be sorted before its best split can be found. In some algorithms, combinations of fields are used and a search must be made for optimal combining weights. Pruning algorithms can also be expensive since many candidate sub-trees must be formed and compared.
- Decision trees do not treat well non-rectangular regions. Most decision-tree algorithms only examine a single field at a time. This leads to rectangular classification boxes that may not correspond well with the actual distribution of records in the decision space.

### Links to online tutorials on decision trees

**Overview of Decision Trees**

by H.Hamilton. E. Gurak, L. Findlater W. Olive

http://www.cs.uregina.ca/~dbd/cs831/notes/ml/dtrees/4_dtrees1.html

© 2001 LIS - Rudjer Boskovic Institute

Last modified: November 24 2014 09:22:38.