A Decision Tree (Decision Tree) is a very simple and effective method for constructing a classifier, and training decision trees is one of the most successful techniques currently available. A decision tree is a tree of classifiers (Decision Stumps) in which each internal node is associated with a particular “question” about a feature (feature). As many branches as there are possible values of the feature extend from this node, eventually reaching the leaves, which indicate the category associated with the decision. Special attention is generally paid to binary decision nodes.
A good “question” divides samples from heterogeneous classes into subsets with sufficiently homogeneous labels, stratifying the data so that each stratum has low variance.
To achieve this, it is necessary to define a metric that measures this impurity.
Let be a subset of samples from a particular training set consisting of
possible classes.
is in fact a random variable that takes only discrete values (the continuous case is analogous).
Each discrete value
, which can take
, can be associated with the probability distribution
.
is a data set consisting of
classes, and
is the relative frequency of class
within the set
.
Given the definition of , the following metrics are widely used in decision trees:
| (5.73) |
| (5.74) |
| (5.75) |
Intuitively, a node with class distribution has minimum impurity, whereas a node with a uniform distribution
has maximum impurity.
A “question” , with
possible answers, divides the set
into the subsets
.
To assess how well the condition performs, the impurity of the child nodes must be compared with that of the parent node: the greater the difference, the better the selected condition.
Given a metric that measures impurity, the gain
is a criterion that can be used to determine the quality of the split:
| (5.76) |
When entropy is used as the metric, the gain is known as Information Gain (TSK06).
Decision trees induce algorithms that choose a test condition maximizing the gain .
Since
is the same for all possible classifiers and
is constant, maximizing the gain is equivalent to minimizing the weighted sum of the impurities of the child nodes:
| (5.77) |
For binary classifiers, the Gini metric is widely used, since the gain to be minimized reduces to
| (5.78) |
Decision trees adapt very well and quickly to the training data and consequently, if unrestricted, systematically suffer from overfitting. A refinement algorithm (pruning) is normally applied to trees to reduce the problem of overfitting wherever possible. There are usually two pruning approaches: pre-pruning and post-pruning. Pre-pruning stops tree growth under certain conditions to avoid excessive specialization, for example, by imposing a maximum tree depth. Post-pruning, on the other hand, refines an already constructed tree by removing branches that fail to satisfy certain conditions on a previously selected validation set.
This technique for constructing a decision tree is usually referred to as Classification and regression trees (CART) (B$^+$84). In the realistic case where the analyzed features are statistical quantities, one does not speak of creating a classification tree, but rather of constructing a regression tree. Finding the optimal partition of the data is an NP-complete problem; therefore, greedy algorithms such as the one shown in the section are normally used.
Paolo medici