Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Decision tree learning
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Metrics== Algorithms for constructing decision trees usually work top-down, by choosing a variable at each step that best splits the set of items.<ref name="top-downDT">{{cite journal |last1=Rokach |first1=L. |last2=Maimon |first2=O. |title=Top-down induction of decision trees classifiers-a survey |journal=IEEE Transactions on Systems, Man, and Cybernetics - Part C: Applications and Reviews |volume=35 |pages=476โ487 |year=2005 |doi=10.1109/TSMCC.2004.843247 |issue=4|citeseerx=10.1.1.458.7031 |s2cid=14808716 }}</ref> Different algorithms use different metrics for measuring "best". These generally measure the homogeneity of the target variable within the subsets. Some examples are given below. These metrics are applied to each candidate subset, and the resulting values are combined (e.g., averaged) to provide a measure of the quality of the split. Depending on the underlying metric, the performance of various heuristic algorithms for decision tree learning may vary significantly.<ref name="thask">{{Cite thesis |last=Najmann |first=Oliver |title=Techniques and heuristics for acquiring symbolic knowledge from examples. |year=1992 |publisher=Doctoral thesis |url=https://d-nb.info/921171064 }}</ref> === Estimate of Positive Correctness === A simple and effective metric can be used to identify the degree to which true positives outweigh false positives (see [[Confusion matrix]]). This metric, "Estimate of Positive Correctness" is defined below: <math> E_P = TP - FP </math> In this equation, the total false positives (FP) are subtracted from the total true positives (TP). The resulting number gives an estimate on how many positive examples the feature could correctly identify within the data, with higher numbers meaning that the feature could correctly classify more positive samples. Below is an example of how to use the metric when the full confusion matrix of a certain feature is given: '''Feature A Confusion Matrix''' {| class="wikitable" ! {{diagonal split header|Actual Class|Predicted<br />Class}} !Cancer !Non-cancer |- !Cancer |<u>8</u> |3 |- !Non-cancer |<u>2</u> |5 |} Here we can see that the TP value would be 8 and the FP value would be 2 (the underlined numbers in the table). When we plug these numbers in the equation we are able to calculate the estimate: <math>E_p = TP - FP = 8 - 2 = 6</math>. This means that using the estimate on this feature would have it receive a score of 6. However, it should be worth noting that this number is only an estimate. For example, if two features both had a FP value of 2 while one of the features had a higher TP value, that feature would be ranked higher than the other because the resulting estimate when using the equation would give a higher value. This could lead to some inaccuracies when using the metric if some features have more positive samples than others. To combat this, one could use a more powerful metric known as [[Sensitivity and specificity|Sensitivity]] that takes into account the proportions of the values from the confusion matrix to give the actual [[Sensitivity and specificity|true positive rate]] (TPR). The difference between these metrics is shown in the example below: {| |+ |'''Feature A Confusion Matrix''' {| class="wikitable" ! {{diagonal split header|Actual Class|Predicted<br />Class}} !Cancer !Non-cancer |- !Cancer |8 |3 |- !Non-cancer |2 |5 |} |style="padding-left: 4em;" | '''Feature B Confusion Matrix''' {| class="wikitable" ! {{diagonal split header|Actual Class|Predicted<br />Class}} !Cancer !Non-cancer |- !Cancer |6 |2 |- !Non-cancer |2 |8 |} |- |<math>E_p = TP - FP = 8 - 2 = 6</math> <math>TPR = TP / (TP + FN) = 8 / (8 + 3) \approx 0.73 </math> |style="padding-left: 4em;" | <math>E_p = TP - FP = 6 - 2 = 4</math> <math>TPR = TP / (TP + FN) = 6 / (6 + 2) = 0.75 </math> |} In this example, Feature A had an estimate of 6 and a TPR of approximately 0.73 while Feature B had an estimate of 4 and a TPR of 0.75. This shows that although the positive estimate for some feature may be higher, the more accurate TPR value for that feature may be lower when compared to other features that have a lower positive estimate. Depending on the situation and knowledge of the data and decision trees, one may opt to use the positive estimate for a quick and easy solution to their problem. On the other hand, a more experienced user would most likely prefer to use the TPR value to rank the features because it takes into account the proportions of the data and all the samples that should have been classified as positive. ===Gini impurity=== '''Gini impurity''', '''Gini's diversity index''',<ref>{{cite web |title=Growing Decision Trees |url=https://www.mathworks.com/help/stats/growing-decision-trees.html |website=MathWorks }}</ref> or '''[[Diversity index#GiniโSimpson index|Gini-Simpson Index]]''' in biodiversity research, is named after Italian mathematician [[Corrado Gini]] and used by the CART (classification and regression tree) algorithm for classification trees. Gini impurity measures how often a randomly chosen element of a set would be incorrectly labeled if it were labeled randomly and independently according to the distribution of labels in the set. It reaches its minimum (zero) when all cases in the node fall into a single target category. For a set of items with <math>J</math> classes and relative frequencies <math>p_i</math>, <math>i \in \{1, 2, ...,J\}</math>, the probability of choosing an item with label <math>i</math> is <math>p_i</math>, and the probability of miscategorizing that item is <math>\sum_{k \ne i} p_k = 1-p_i</math>. The Gini impurity is computed by summing pairwise products of these probabilities for each class label: :<math>\operatorname{I}_G(p) = \sum_{i=1}^J \left( p_i \sum_{k\neq i} p_k \right) = \sum_{i=1}^J p_i (1-p_i) = \sum_{i=1}^J (p_i - p_i^2) = \sum_{i=1}^J p_i - \sum_{i=1}^J p_i^2 = 1 - \sum^J_{i=1} p_i^2. </math> The Gini impurity is also an information theoretic measure and corresponds to [[Tsallis Entropy]] with deformation coefficient <math>q=2</math>, which in physics is associated with the lack of information in out-of-equilibrium, non-extensive, dissipative and quantum systems. For the limit <math>q\to 1</math> one recovers the usual Boltzmann-Gibbs or Shannon entropy. In this sense, the Gini impurity is nothing but a variation of the usual entropy measure for decision trees. ===Information gain=== {{main|Information gain in decision trees}} Used by the [[ID3 algorithm|ID3]], [[C4.5 algorithm|C4.5]] and C5.0 tree-generation algorithms. [[Information gain]] is based on the concept of [[information entropy|entropy]] and [[information content]] from [[information theory]]. Entropy is defined as below :<math>\Eta(T) = \operatorname{I}_{E}\left(p_1, p_2, \ldots, p_J\right) = - \sum^J_{i=1} p_i \log_2 p_i</math> where <math>p_1, p_2, \ldots</math> are fractions that add up to 1 and represent the percentage of each class present in the child node that results from a split in the tree.<ref name="Witten 2011 102โ103">{{Cite book|title=Data Mining|url=https://archive.org/details/dataminingpracti00witt_966|url-access=limited|last1=Witten|first1=Ian|last2=Frank|first2=Eibe|last3=Hall|first3=Mark|publisher=Morgan Kaufmann|year=2011|isbn=978-0-12-374856-0|location=Burlington, MA|pages=[https://archive.org/details/dataminingpracti00witt_966/page/n136 102]โ103}}</ref> :<math display="block"> \overbrace{IG(T,a)}^\text{information gain} = \overbrace{\Eta(T)}^\text{entropy (parent)} - \overbrace{\Eta(T\mid a)}^\text{sum of entropies (children)} </math><math>=-\sum_{i=1}^J p_i\log_2 p_i - \sum_{i=1}^J - \Pr(i\mid a)\log_2 \Pr(i\mid a)</math> Averaging over the possible values of <math>A</math>, :<math display="block"> \overbrace{E_A(\operatorname{IG}(T,a))}^\text{expected information gain} = \overbrace{I(T; A)}^{\text{mutual information between } T \text{ and } A} = \overbrace{\Eta(T)}^\text{entropy (parent)} - \overbrace{\Eta(T\mid A)}^\text{weighted sum of entropies (children)} </math><math>=-\sum_{i=1}^J p_i\log_2 p_i - \sum_a p(a)\sum_{i=1}^J-\Pr(i\mid a) \log_2 \Pr(i\mid a) </math> :Where weighted sum of entropies is given by, :<math>{\Eta(T\mid A)}= \sum_a p(a)\sum_{i=1}^J-\Pr(i\mid a) \log_2 \Pr(i\mid a)</math> That is, the expected information gain is the [[mutual information]], meaning that on average, the reduction in the entropy of ''T'' is the mutual information. Information gain is used to decide which feature to split on at each step in building the tree. Simplicity is best, so we want to keep our tree small. To do so, at each step we should choose the split that results in the most consistent child nodes. A commonly used measure of consistency is called [[Information theory|information]] which is measured in [[bit]]s. For each node of the tree, the information value "represents the expected amount of information that would be needed to specify whether a new instance should be classified yes or no, given that the example reached that node".<ref name="Witten 2011 102โ103"/> Consider an example data set with four attributes: ''outlook'' (sunny, overcast, rainy), ''temperature'' (hot, mild, cool), ''humidity'' (high, normal), and ''windy'' (true, false), with a binary (yes or no) target variable, ''play'', and 14 data points. To construct a decision tree on this data, we need to compare the information gain of each of four trees, each split on one of the four features. The split with the highest information gain will be taken as the first split and the process will continue until all children nodes each have consistent data, or until the information gain is 0. To find the information gain of the split using ''windy'', we must first calculate the information in the data before the split. The original data contained nine yes's and five no's. :<math> I_E([9,5]) = -\frac 9 {14}\log_2 \frac 9 {14} - \frac 5 {14}\log_2 \frac 5 {14} = 0.94 </math> The split using the feature ''windy'' results in two children nodes, one for a ''windy'' value of true and one for a ''windy'' value of false. In this data set, there are six data points with a true ''windy'' value, three of which have a ''play'' (where ''play'' is the target variable) value of yes and three with a ''play'' value of no. The eight remaining data points with a ''windy'' value of false contain two no's and six yes's. The information of the ''windy''=true node is calculated using the entropy equation above. Since there is an equal number of yes's and no's in this node, we have :<math> I_E([3,3]) = -\frac 3 6\log_2 \frac 3 6 - \frac 3 6\log_2 \frac 3 6 = -\frac 1 2\log_2 \frac 1 2 - \frac 1 2\log_2 \frac 1 2 = 1 </math> For the node where ''windy''=false there were eight data points, six yes's and two no's. Thus we have :<math> I_E([6,2]) = -\frac 6 8\log_2 \frac 6 8 - \frac 2 8\log_2 \frac 2 8 = -\frac 3 4\log_2 \frac 3 4 - \frac 1 4\log_2 \frac 1 4 = 0.81 </math> To find the information of the split, we take the weighted average of these two numbers based on how many observations fell into which node. :<math> I_E([3,3],[6,2]) = I_E(\text{windy or not}) = \frac 6 {14} \cdot 1 + \frac 8 {14} \cdot 0.81 = 0.89 </math> Now we can calculate the information gain achieved by splitting on the ''windy'' feature. :<math> \operatorname{IG}(\text{windy}) = I_E([9,5]) - I_E([3,3],[6,2]) = 0.94 - 0.89 = 0.05 </math> To build the tree, the information gain of each possible first split would need to be calculated. The best first split is the one that provides the most information gain. This process is repeated for each impure node until the tree is complete. This example is adapted from the example appearing in Witten et al.<ref name="Witten 2011 102โ103"/> Information gain is also known as [[Diversity index#Shannon index|Shannon index]] in bio diversity research. ===Variance reduction=== Introduced in CART,<ref name="bfos"/> variance reduction is often employed in cases where the target variable is continuous (regression tree), meaning that use of many other metrics would first require discretization before being applied. The variance reduction of a node {{mvar|N}} is defined as the total reduction of the variance of the target variable {{mvar|Y}} due to the split at this node: :<math> I_V(N) = \frac{1}{|S|^2}\sum_{i\in S} \sum_{j\in S} \frac{1}{2}(y_i - y_j)^2 - \left(\frac{|S_t|^2}{|S|^2}\frac{1}{|S_t|^2}\sum_{i\in S_t} \sum_{j\in S_t} \frac{1}{2}(y_i - y_j)^2 + \frac{|S_f|^2}{|S|^2}\frac{1}{|S_f|^2}\sum_{i\in S_f} \sum_{j\in S_f} \frac{1}{2}(y_i - y_j)^2\right) </math> where <math>S</math>, <math>S_t</math>, and <math>S_f</math> are the set of presplit sample indices, set of sample indices for which the split test is true, and set of sample indices for which the split test is false, respectively. Each of the above summands are indeed [[variance]] estimates, though, written in a form without directly referring to the mean. By replacing <math>(y_i - y_j)^2</math> in the formula above with the dissimilarity <math>d_{ij}</math> between two objects <math>i</math> and <math>j</math>, the variance reduction criterion applies to any kind of object for which pairwise dissimilarities can be computed.<ref name=":1" /> ===Measure of "goodness"=== Used by CART in 1984,<ref name="ll">{{Cite book |last=Larose |first=Daniel T. |author2=Larose, Chantal D. |title=Discovering knowledge in data: an introduction to data mining |year=2014 |publisher=John Wiley & Sons, Inc |location=Hoboken, NJ |isbn=9781118874059 }}</ref> the measure of "goodness" is a function that seeks to optimize the balance of a candidate split's capacity to create pure children with its capacity to create equally-sized children. This process is repeated for each impure node until the tree is complete. The function <math>\varphi(s\mid t)</math>, where <math>s</math> is a candidate split at node <math>t</math>, is defined as below :<math> \varphi(s\mid t) = 2P_L P_R \sum_{j=1}^\text{class count}|P(j\mid t_L) - P(j\mid t_R)| </math> where <math>t_L</math> and <math>t_R</math> are the left and right children of node <math>t</math> using split <math>s</math>, respectively; <math>P_L</math> and <math>P_R</math> are the proportions of records in <math>t</math> in <math>t_L</math> and <math>t_R</math>, respectively; and <math>P(j\mid t_L)</math> and <math>P(j\mid t_R)</math> are the proportions of class <math>j</math> records in <math>t_L</math> and <math>t_R</math>, respectively. Consider an example data set with three attributes: ''savings''(low, medium, high), ''assets''(low, medium, high), ''income''(numerical value), and a binary target variable ''credit risk''(good, bad) and 8 data points.<ref name="ll"/> The full data is presented in the table below. To start a decision tree, we will calculate the maximum value of <math>\varphi(s\mid t)</math> using each feature to find which one will split the root node. This process will continue until all children are pure or all <math>\varphi(s\mid t)</math> values are below a set threshold. {| class="wikitable" |- ! Customer !! Savings !! Assets !! Income ($1000s) !! Credit risk |- | 1 || Medium || High || 75 || Good |- | 2 || Low || Low || 50 || Bad |- | 3 || High || Medium || 25 || Bad |- | 4 || Medium || Medium || 50 || Good |- | 5 || Low || Medium || 100 || Good |- | 6 || High || High || 25 || Good |- | 7 || Low || Low || 25 || Bad |- | 8 || Medium || Medium || 75 || Good |} To find <math>\varphi(s\mid t)</math> of the feature ''savings'', we need to note the quantity of each value. The original data contained three low's, three medium's, and two high's. Out of the low's, one had a good ''credit risk'' while out of the medium's and high's, 4 had a good ''credit risk''. Assume a candidate split <math>s</math> such that records with a low ''savings'' will be put in the left child and all other records will be put into the right child. :<math> \varphi(s\mid\text{root}) = 2\cdot\frac 3 8\cdot\frac 5 8\cdot \left(\left|\left(\frac 1 3 - \frac 4 5\right)\right| + \left|\left(\frac 2 3 - \frac 1 5\right)\right|\right) = 0.44 </math> To build the tree, the "goodness" of all candidate splits for the root node need to be calculated. The candidate with the maximum value will split the root node, and the process will continue for each impure node until the tree is complete. Compared to other metrics such as information gain, the measure of "goodness" will attempt to create a more balanced tree, leading to more-consistent decision time. However, it sacrifices some priority for creating pure children which can lead to additional splits that are not present with other metrics.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)