{"id":229,"date":"2018-08-27T06:39:29","date_gmt":"2018-08-27T06:39:29","guid":{"rendered":"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=229"},"modified":"2019-01-02T06:45:53","modified_gmt":"2019-01-02T06:45:53","slug":"classification-and-regression-trees-i","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/chapter\/classification-and-regression-trees-i\/","title":{"rendered":"Classification and Regression Trees &#8211; I"},"content":{"raw":"<div><span style=\"float: right\"><a href=\"https:\/\/youtu.be\/1OqZ1Qd6niI\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Welcome to the e-PG Pathshala Lecture Series on Machine Learning. In this module we will be discussing in detail the Classification and Regression Tree (CART) approach for the construction of Decision Trees.<\/p>\r\n&nbsp;\r\n\r\n<strong>Learning Objectives:<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe learning objectives of this module are as follows:\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">\u2022\u00a0 To explain CART approach to decision tree building<\/p>\r\n<p style=\"text-align: justify\">\u2022\u00a0 To outline the key features of CART<\/p>\r\n<p style=\"text-align: justify\">\u2022\u00a0 To explain the various steps of the CART approach<\/p>\r\n<p style=\"text-align: justify\">\u2022\u00a0 To discuss the recursive partitioning approach<\/p>\r\n<p style=\"text-align: justify\">\u2022\u00a0 To outline the Gini Index<\/p>\r\n&nbsp;\r\n\r\n<strong>15.1 <\/strong><strong>Decision Tree &amp; CART<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Any\u00a0 decision\u00a0 tree\u00a0 will\u00a0 successively\u00a0 split\u00a0 the\u00a0 data\u00a0 into\u00a0 smaller\u00a0 and\u00a0 smaller subsets. Ideally all the samples associated with a leaf node should be from the same class. Such a subset, or node, is considered <em>pure<\/em> in this case. A generic tree-growing methodology,\u00a0 known\u00a0 as CART, successively splits nodes until they are pure.<\/p>\r\n&nbsp;\r\n\r\n<strong>15.2\u00a0 The CART approach<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">As we have discussed Classification And Regression Trees is a generic methodology for the construction of effective decision trees. CART was developed by Breiman, Friedman, Olshen, Stone in early 80\u2019s. They are the pioneers in bringing the tree-based modeling paradigm into the statistical fold. They proposed a rigorous approach involving cross-validation to select the optimal tree. In this context Quinlan developed C4.5 a machine learning approach for generating the decision tree which was essentially an extension of based on his earlier ID3 algorithm.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">This is a non-parametric technique, using the methodology of tree building. CART are binary tree structured classifiers constructed by repeated splits of subsets (nodes) of the search space S into two descendant subsets. Each terminal subset is assigned a class label; the resulting partition of S corresponds to the classifier. The method classifies objects or predicts outcomes by selecting from among the large number of variables, that is by selecting the most important variables that affect the outcome variable. CART analysis is a form of binary recursive partitioning. We will discuss this aspect later on.<\/span><\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<strong>15.2.1 An Example from Clinical Research<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Let us consider a dataset from University of California for the development of a reliable clinical decision rule to classify new patients into categories <em>after<\/em> admission for a heart attack. The dataset has 19 variables collected during the first 24 hours for 215 patients (for those who survived the 24 hours) after their admittance to San Diego Hospital. The goal of the work is to identify the patients with high risk that is those patients who would not survive 30 days<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-230 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-147.png\" alt=\"\" width=\"505\" height=\"282\" \/>\r\n<div>\r\n<p style=\"text-align: justify\">Figure 15.1 shows a part of the decision tree where all patients are divided into two subsets (binary partitioning), one subset A of patients whose minimum systolic blood pressure over the initial 24 hour period &gt; 91 and the other subset B of patients whose minimum systolic blood pressure over the initial 24 hour period \u00a3 91. Now in the subset A, we further partition the set based on whether age &gt; 62.5 and so on.<\/p>\r\n&nbsp;\r\n\r\n<strong>15.2.2 Definition of CART<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Now let us define CART. CART builds classification or regression trees for categorical attributes (classification) or numeric attributes (regression). Tree models where the target variable can take a finite set of values are called classification trees. Regression tree analysis is where the target variable can take continuous values typically real numbers such as the price of a house,<span style=\"text-align: initial;font-size: 1em\">or a patient\u2019s length of stay in a hospital. The term <\/span><strong style=\"text-align: initial;font-size: 1em\">C<\/strong><span style=\"text-align: initial;font-size: 1em\">lassification <\/span><strong style=\"text-align: initial;font-size: 1em\">A<\/strong><span style=\"text-align: initial;font-size: 1em\">nd <\/span><strong style=\"text-align: initial;font-size: 1em\">R<\/strong><span style=\"text-align: initial;font-size: 1em\">egression<\/span><strong style=\"text-align: initial;font-size: 1em\"> T<\/strong><span style=\"text-align: initial;font-size: 1em\">ree (CART) analysis is used to refer to both types of attributes categorical and numeric. Trees used for classification and regression are similar but differ how they determine the splitting procedure.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">15.2.3 Salient Aspects of CART<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">One of the key features of CART is automated attribute or feature selection. The process can automatically select relevant fields irrespective of the total number of fields. Moreover no data preprocessing or transformation of the variables is needed. The CART is is tolerant to missing values, and there is only a moderate loss of accuracy due to missing values.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">15.3\u00a0\u00a0 CART- General Framework - The Six Questions<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Associated with CART are six questions to be answered or six issues to be addressed. The following are the questions:<\/span><\/p>\r\n&nbsp;\r\n<ol>\r\n \t<li style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">How many splits will be there at each node?<\/strong><\/li>\r\n<\/ol>\r\nShould the questions to be asked for the split at each node be binary (e.g., is gender male or female) or numeric (e.g., height is 5\u20194\u201d) or multi-valued (e.g., caste)?\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>2.\u00a0<\/strong><strong>Which properties should be tested at each node?<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The decision on which variable or feature to use for splitting is an important issue and in fact determines the efficiency of the procedure.<\/p>\r\n&nbsp;\r\n\r\n<strong>3.<\/strong><strong>When does a node become a leaf?<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">We need a criteria to determine that the subset of examples associated with a node need not be partitioned further.<\/p>\r\n&nbsp;\r\n\r\n<strong>4.<\/strong><strong>How to prune a large tree?<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Simplify the tree by pruning peripheral branches to avoid over fitting. Some parts of the tree need not be explored or partitioned further since deep trees that fit the training data well, will not generalize well to new test data<strong>.<\/strong> How do we determine this?<\/p>\r\n&nbsp;\r\n\r\n<strong>5.<\/strong><strong>If a leaf node is impure, how to assign labels?<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In case the leaf node is impure that is results in more than one output variable value, how do we assign an output value for unknown samples.<\/p>\r\n&nbsp;\r\n\r\n<strong>6.<\/strong><strong>How to handle missing data?<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The issue here is how to account for missing data of some features when decisions regarding this data are taken.<\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">15.4\u00a0 CART Steps<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n\r\nThe following are the steps used by CART for the construction of the decision tree.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">1.<strong>Initialization<\/strong>: Initially a tree is created with a single root node containing all the training data.<\/p>\r\n<p style=\"text-align: justify\">2.<strong>Tree growing: <\/strong>Recursive Partitioning is the most important component of tree construction. This procedure consists of 5 sub steps which are described below:<\/p>\r\n<p style=\"text-align: justify\">a.The first step here is the selection of the splitting criterion which in most cases is based on likelihood. For this purpose we need to find the best question for splitting each node. We then split the node that results in the greatest increase in the likelihood.<\/p>\r\n<p style=\"text-align: justify\">b.We then rank all of the best splits and then the best split in the variable is selected in terms of the reduction in impurity (heterogeneity). This aspect we will discuss later.<\/p>\r\n<p style=\"text-align: justify\">c.The Predicted classes are assigned to the nodes according to a rule that minimizes misclassification costs.<\/p>\r\n<p style=\"text-align: justify\">d.The next step is the decision about the stopping criteria that is how far to grow? We generally stop expanding a node when all the records belong to the same class or when all the records have similar attribute values. Stopping criteria decides whether to continue splitting a node.<\/p>\r\n<p style=\"text-align: justify\">e.Using surrogates program best available information is used to replace missing data, normally based on a variable that is relative to the outcome variable.<\/p>\r\n<p style=\"text-align: justify\">3.<strong>Stop tree building<\/strong>: When every aspect of the dataset has been taken into account while building the decision tree, the tree building process itself is stopped.<\/p>\r\n<p style=\"text-align: justify\">4.<strong>Tree Pruning: <\/strong>An independent test set or cross-validation is generally used to prune the tree. Pruning is carried out by trimming off parts of the tree that don\u2019t work. Another method is to first order the nodes of a large tree by contribution to tree accuracy and this ordering is used as a basis to prune nodes.<\/p>\r\n<p style=\"text-align: justify\">5.<strong>Optimal Tree Selection: <\/strong>This process is the selection of the best tree that fits dataset with a low percentage of error. The decision about the best tree is made after growing and pruning. This selection of optimal tree is also based on balancing simplicity against accuracy.<\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">15.5\u00a0 Recursive Partitioning<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n\r\nThe key idea behind the CART technique is recursive partitioning. Let us understand this concept in detail. The recursive procedure is described as follows:\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">i.Consider all the data samples.<\/p>\r\n<p style=\"text-align: justify\">ii.Consider <em>all<\/em> possible values of <em>all<\/em> variables.<\/p>\r\n<p style=\"text-align: justify\">iii.Select the variable and the value (<em>X<\/em>=<em>t<\/em><em>1<\/em>) that produces the greatest \u201cseparation\u201d in the target. This point of the variable X (<em>X<\/em>=<em>t<\/em><em>1<\/em>) is called a \u201csplit\u201d.<\/p>\r\niv.If <em>X<\/em>&lt; <em>t<\/em><em>1<\/em> then send the data to the \u201cleft\u201d; otherwise, send data point to the \u201cright\u201d.\r\n<p style=\"text-align: justify\">v.Now repeat same process on these two \u201cnodes\u201d<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">What you get as output is a \u201ctree\u201d. Note that CART only uses <em>binary<\/em> splits. The main step in the process is Recursive Partitioning (step iii) where we<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">\u2022 First we pick a value of <em>x<\/em>i, say <em>s<\/em>i, that divides the training data into two (not necessarily equal) portions<\/p>\r\n<p style=\"text-align: justify\">\u2022 Then we measure how \u201cpure\u201d or homogeneous each of the resulting portions are. In this context a partition being \u201cPure\u201d means that they contain records of mostly one class.<\/p>\r\n<p style=\"text-align: justify\">\u2022 The algorithm tries different values of <em>x<\/em>i, and <em>s<\/em>i to maximize purity in initial split<\/p>\r\n<p style=\"text-align: justify\">\u2022 After we get a \u201cmaximum purity\u201d split, we repeat the process for a second split, and so on<\/p>\r\n&nbsp;\r\n\r\n<strong>15.6\u00a0 Features of CART<\/strong>\r\n\r\n&nbsp;\r\n\r\nSome of the important features of the process of CART are as follows:\r\n<ul>\r\n \t<li style=\"text-align: justify\">Data is split into two partitions that is at every node the set is split into two subsets.<\/li>\r\n \t<li style=\"text-align: justify\">Splits at any node are based only on one variable.<\/li>\r\n \t<li style=\"text-align: justify\">Partitions can also be split into sub-partitions and hence procedure is recursive. CART tree is generated by repeated partitioning of data set where each decision node has two child nodes and so on.<\/li>\r\n<\/ul>\r\n<\/div>\r\n&nbsp;\r\n\r\n<strong>15.7\u00a0 Construction of a Tree<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">During the construction of the tree we need to first carry out the most important step that is the selection of the splits. We further need to make decisions as to whether a node is a terminal node (i.e. not to split it any further). We also need to assign a class to each terminal node.<\/p>\r\n&nbsp;\r\n\r\nThe following are the steps of tree building\r\n<ol>\r\n \t<li style=\"text-align: justify\">Start with splitting a variable at all of its split points. Pick one of the predictor variables Xi, and pick a value of the variable say Si that divides the training data into two (not necessarily equal) portions. Measure how\u201cpure\u201d or homogeneous each of the resulting portions are. As we discussed a pure partition contains records of mostly one class. Idea is to select different values Si of the variable Xi to form the partitions. These different values of the variables used for forming the partitions are called split points.<\/li>\r\n \t<li style=\"text-align: justify\">The sample set splits into two binary nodes at each split point.<\/li>\r\n \t<li style=\"text-align: justify\">Select the best split in the variable in terms of the reduction in impurity (heterogeneity)<\/li>\r\n \t<li style=\"text-align: justify\">Repeat steps 1,2 for all variables at root node.<\/li>\r\n \t<li style=\"text-align: justify\">Rank all of best splits &amp; select the variable that achieves the highest purity at root.<\/li>\r\n<\/ol>\r\n&nbsp;\r\n\r\n<strong>15.7.1 Method of Splitting<\/strong>\r\n\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-231 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-148.png\" alt=\"\" width=\"260\" height=\"353\" \/>\r\n<p style=\"text-align: justify\">We first order records according to one variable. Then we need to find midpoints between successive values. We then divide records. After evaluating that split, try the next midpoint. In the case of categorical variables, examine all possible ways in which the categories can be split. For example assume that the categories A, B, C can be split 3 ways as {A} and {B, C}, {B} and {A, C}, {C} and {A, B}. Please note that with many categories, the number of splits becomes huge. Many of the tools available support only binary categorical variables.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Now let us consider the example given in Figure 15.2. The decision variables in this example are car type, age and number of children. The output variable in this example is whether there is insurance claim or not. The decision tree is shown in Figure 15.3. In this example we start with age as the root node of the decision tree. The numerical value of age has been split as \u00a3 30 and &gt; 30. This divides the total number of 14 samples into two sets of 7 samples each. Now at the left we split the 7 examples into two sets of sedan on one side (with 3 as sedan) and 4 either sports or truck on the right. This leaves us with claim as all yes on left and all no on right. For the right side of the root we first use the number of children attribute for splitting. Here the split is taken as no children (2 samples) or having children (5 samples). At the next level we split on both sides based on car type. Now at the leaves we are left with no on one side and yes on the other. This decision helps to decide whether claim is possible or not.<\/p>\r\n<img class=\"size-full wp-image-232 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-149.png\" alt=\"\" width=\"491\" height=\"351\" \/>\r\n\r\n&nbsp;\r\n\r\nIn the Insurance Example\r\n\r\n&nbsp;\r\n<ul>\r\n \t<li style=\"text-align: justify\">Suppose we have 3 variables Type of Car :{sedan, sports, truck}, Age category:{ \u226430 &amp;&gt; 30},Number of Children :{0,1,2}<\/li>\r\n \t<li style=\"text-align: justify\">At each iteration, CART tests all splits.Some of the splits for the variable<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">Type of car having three values are - Car = {sedan} &amp; {truck &amp; sports} or { sedan &amp; truck} &amp; {sports} or {sedan &amp; sports} &amp; {truck} .For the Age variable as we can see the split point can be \u226430 &amp;&gt; 30, \u226435 &amp;&gt; 35 etc.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-233 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-150.png\" alt=\"\" width=\"429\" height=\"355\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 15.4 The Split of Samples based on Decision Tree in Figure 15.3<\/strong><\/p>\r\n\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>15.8 Selection of Split<\/strong>\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">The split has to be so selected that it results in greater increase in <\/span><em style=\"text-align: initial;font-size: 1em\">purity<\/em><span style=\"text-align: initial;font-size: 1em\">. In case of the example given in the previous section:<\/span>\r\n<div>\r\n<ul>\r\n \t<li>Perfect purity:\u00a0 each split has either all claims or all no-claims.<\/li>\r\n \t<li>Perfect impurity: each split has same proportion of claims as overall population.<\/li>\r\n<\/ul>\r\n&nbsp;\r\n\r\n<strong>15.8.1 Splitting Rules<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">As discussed before we need to select the variable value (<em>X<\/em>=<em>t<\/em><em>1<\/em>) that produces the greatest \u201cseparation\u201d in the target variable. \u201cSeparation\u201d can be defined in many ways. In the case of <strong>Regression Trees<\/strong> (continuous target), we can use sum of squared errors. In the case of <strong>Classification Trees<\/strong> (categorical target) we can use either <em>entropy<\/em>, <em>Gini measure<\/em>, or a \u201c<em>twoing<\/em>\u201d splitting rule. In the tree-based modeling for <em>discrete<\/em> target variable, various measures of <em>purity<\/em> are used. The intuition is that an ideal model would produce nodes that contain either calims only or no-claims (example in Figure 15.2) only that is completely pure nodes.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The main issue in the choice of a measure is the balance between getting pure nodes and getting equal size nodes (that is partitioning into roughly equal sized sets).<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The Gini purity of a node and Entropy of a node are discussed in the next section. The maximum entropy\/Gini index occurs when records are equally distributed among all classes implying least information and minimum entropy\/Gini index occurs when when all records belong to one class, implying most interesting information.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Gini might produce small but pure nodes. The \u201ctwoing\u201d rule strikes a balance between purity and creating roughly equal-sized nodes so that we do not always choose a split that gives pure nodes but rather choose a split that gives an almost pure nodes that gives roughly equal size partitions.<\/p>\r\n&nbsp;\r\n\r\n<strong>15.8.2 Impurity and Recursive Partitioning<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The idea is to select the split that decreases the Gini Index. We have to consider all possible places for a split. This essentially means that we have to select the variable and the possible splits in values of the variables appropriately. The chosen split points become nodes on the tree. We keep splitting until the terminal nodes have very few cases or are all pure. The best approach is to grow a larger tree than required and then to <em>prune<\/em> it. We will discuss pruning in the next module.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Now we need a measure of impurity of a node to help decide on how to split a node, or which node to split. The measure should be at a maximum when a\u00a0<span style=\"text-align: initial;font-size: 1em\">node is equally divided amongst all classes. The impurity should be zero if the node is all one class.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">There are various measures of impurity. Misclassification rate is one such measure, but this measure is not generally used since no split improves the misclassification rate, and can be equal when one option is clearly better for the next step. Other measures are Information, or Entropy and Gini Index.<\/span><\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<strong>15.8.1 Information or Entropy<\/strong>\r\n\r\n&nbsp;\r\n\r\nIf a node has a proportion of pj of each of the classes then the information or entropy is:\r\n\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-234 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-151.png\" alt=\"\" width=\"333\" height=\"92\" \/>\r\n\r\nwhere p=(p1,p2,\u2026. pn) is the relative frequency of class <em>k at the node.<\/em>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Entropy ranges between 0 (most pure) and log2(<em>m<\/em>) (equal representation of classes) where m is total number of classes.<\/p>\r\n&nbsp;\r\n\r\n<strong>15.8.2 Gini Index<\/strong>\r\n\r\n&nbsp;\r\n\r\nThis the most widely used measure of impurity by CART.If a data set contains examples from n classes, gini index, is defined as\r\n\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-235 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-152.png\" alt=\"\" width=\"415\" height=\"95\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\"><em>where p <\/em>is the proportion of cases that belong to class<em> k\u00a0<\/em><em>i(p) <\/em>= 0 when all cases belong to same class and has maximum value when all classes are equally represented (= 0.50 in binary case)<\/p>\r\n&nbsp;\r\n\r\n<strong>15.8.3 Tree Impurity<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The impurity of a tree is the sum over all terminal nodes of the impurity of a node multiplied by the proportion of cases that reach that node of the tree. Impurity of a tree with one single node, with both A and B having 400 cases (Figure 15.5), using the Gini Index is as follows:<\/p>\r\n&nbsp;\r\n\r\nProportions of the two cases\r\n\r\n= number of cases of one attribute\/total number of cases = 400\/800 ( for both attribute A and B)\r\n\r\nGini Index\r\n\r\n= <strong>1- p<\/strong><strong>2<\/strong><strong>A<\/strong><strong>- p<\/strong><strong>2<\/strong><strong>B<\/strong>\r\n\r\n=1-(0.5)2- (0.5)2 = 0.5\r\n\r\n<img class=\"size-full wp-image-236 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-153.png\" alt=\"\" width=\"574\" height=\"234\" \/>\r\n\r\n<img class=\"size-full wp-image-237 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-154.png\" alt=\"\" width=\"590\" height=\"338\" \/>\r\n<p style=\"text-align: justify\">Figure 15.6 shows another example where we show the nodes of the tree and its contribution to impurity is calculated based on Gini Index. Let us consider the calculation of Gini Index of row 1.<\/p>\r\n&nbsp;\r\n\r\nProportions of the two cases\r\n<ul>\r\n \t<li style=\"text-align: justify\">= number of cases of one attribute\/total number of cases<\/li>\r\n \t<li style=\"text-align: justify\">= 300\/400 = 0.75 (for both attribute A) and 100\/400 =0.25 (for both attribute B) Gini Index<\/li>\r\n \t<li style=\"text-align: justify\">= <strong>1- p<\/strong><strong>2<\/strong><strong>A<\/strong><strong>- p<\/strong><strong>2<\/strong><strong>B<\/strong>=1-(0.75)2- (0.25)2 = 0.375<\/li>\r\n<\/ul>\r\n<strong>15.9 Tree Structure<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The decision tree is represented by using the split points to decide which are the nodes of the tree (circles with split value in center). Rectangles represent \u201cleaves\u201d (terminal points, no further splits, classification value noted). Numbers on lines (branches) between nodes indicate the number of cases. We read down the tree from the root to derive the rule.<\/p>\r\n&nbsp;\r\n\r\n<strong>15.9.1 Determining Leaf Node Label<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Another important aspect in the construction of the tree is to assign a label to each leaf node. Each leaf node label is determined by \u201cvoting\u201d of the records within it, and by the cutoff value. Records within each leaf node are from the training data. The leaf node\u2019s label will be assigned the majority class when the default cutoff is 0.5. When the cutoff = 0.75, the requirement is that a majority of 75% or more \u201c1\u201d records in the leaf is needed to label it a \u201c1\u201d node.<\/p>\r\n&nbsp;\r\n\r\n<strong>Summary<\/strong>\r\n<ul>\r\n \t<li style=\"text-align: justify\">Explained the CART approach to decision tree building<\/li>\r\n \t<li style=\"text-align: justify\">Outlined the key features of CART<\/li>\r\n \t<li style=\"text-align: justify\">Explained the various steps of the CART approach<\/li>\r\n \t<li style=\"text-align: justify\">Discussed the recursive partitioning approach<\/li>\r\n \t<li style=\"text-align: justify\">Outlined the Gini Index<\/li>\r\n<\/ul>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on Classification and Regression Trees \u2013 I<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/1OqZ1Qd6niI\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n<strong>Web Links<\/strong>\r\n<ul>\r\n \t<li style=\"text-align: justify\">https:\/\/www.casact.org\/education\/specsem\/f2005\/handouts\/cart.ppt<\/li>\r\n \t<li style=\"text-align: justify\">www.washburn.edu\/faculty\/boncella\/...\/Lecture%207%20-%20CART.ppt<\/li>\r\n \t<li style=\"text-align: justify\">www.kdnuggets.com\/data_mining_course\/dm8-decision-tree-cart.ppt<\/li>\r\n \t<li style=\"text-align: justify\">artax.karlin.mff.cuni.cz\/~smetp0am\/odkazy\/CLASSFINAL.PPT<\/li>\r\n \t<li style=\"text-align: justify\">ww.stat.ucla.edu\/~kcli\/stat287\/lectures-287\/Lecture...\/Classification.ppt<\/li>\r\n \t<li style=\"text-align: justify\">www.cs.cornell.edu\/courses\/cs578\/2002fa\/CS578.02_DT_lecture.ppt<\/li>\r\n \t<li style=\"text-align: justify\">homes.cs.washington.edu\/~shapiro\/EE596\/notes\/InfoGain.pdf<\/li>\r\n<\/ul>","rendered":"<div><span style=\"float: right\"><a href=\"https:\/\/youtu.be\/1OqZ1Qd6niI\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Welcome to the e-PG Pathshala Lecture Series on Machine Learning. In this module we will be discussing in detail the Classification and Regression Tree (CART) approach for the construction of Decision Trees.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Learning Objectives:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The learning objectives of this module are as follows:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">\u2022\u00a0 To explain CART approach to decision tree building<\/p>\n<p style=\"text-align: justify\">\u2022\u00a0 To outline the key features of CART<\/p>\n<p style=\"text-align: justify\">\u2022\u00a0 To explain the various steps of the CART approach<\/p>\n<p style=\"text-align: justify\">\u2022\u00a0 To discuss the recursive partitioning approach<\/p>\n<p style=\"text-align: justify\">\u2022\u00a0 To outline the Gini Index<\/p>\n<p>&nbsp;<\/p>\n<p><strong>15.1 <\/strong><strong>Decision Tree &amp; CART<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Any\u00a0 decision\u00a0 tree\u00a0 will\u00a0 successively\u00a0 split\u00a0 the\u00a0 data\u00a0 into\u00a0 smaller\u00a0 and\u00a0 smaller subsets. Ideally all the samples associated with a leaf node should be from the same class. Such a subset, or node, is considered <em>pure<\/em> in this case. A generic tree-growing methodology,\u00a0 known\u00a0 as CART, successively splits nodes until they are pure.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>15.2\u00a0 The CART approach<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">As we have discussed Classification And Regression Trees is a generic methodology for the construction of effective decision trees. CART was developed by Breiman, Friedman, Olshen, Stone in early 80\u2019s. They are the pioneers in bringing the tree-based modeling paradigm into the statistical fold. They proposed a rigorous approach involving cross-validation to select the optimal tree. In this context Quinlan developed C4.5 a machine learning approach for generating the decision tree which was essentially an extension of based on his earlier ID3 algorithm.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">This is a non-parametric technique, using the methodology of tree building. CART are binary tree structured classifiers constructed by repeated splits of subsets (nodes) of the search space S into two descendant subsets. Each terminal subset is assigned a class label; the resulting partition of S corresponds to the classifier. The method classifies objects or predicts outcomes by selecting from among the large number of variables, that is by selecting the most important variables that affect the outcome variable. CART analysis is a form of binary recursive partitioning. We will discuss this aspect later on.<\/span><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>15.2.1 An Example from Clinical Research<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Let us consider a dataset from University of California for the development of a reliable clinical decision rule to classify new patients into categories <em>after<\/em> admission for a heart attack. The dataset has 19 variables collected during the first 24 hours for 215 patients (for those who survived the 24 hours) after their admittance to San Diego Hospital. The goal of the work is to identify the patients with high risk that is those patients who would not survive 30 days<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-230 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-147.png\" alt=\"\" width=\"505\" height=\"282\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-147.png 505w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-147-300x168.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-147-65x36.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-147-225x126.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-147-350x195.png 350w\" sizes=\"auto, (max-width: 505px) 100vw, 505px\" \/><\/p>\n<div>\n<p style=\"text-align: justify\">Figure 15.1 shows a part of the decision tree where all patients are divided into two subsets (binary partitioning), one subset A of patients whose minimum systolic blood pressure over the initial 24 hour period &gt; 91 and the other subset B of patients whose minimum systolic blood pressure over the initial 24 hour period \u00a3 91. Now in the subset A, we further partition the set based on whether age &gt; 62.5 and so on.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>15.2.2 Definition of CART<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Now let us define CART. CART builds classification or regression trees for categorical attributes (classification) or numeric attributes (regression). Tree models where the target variable can take a finite set of values are called classification trees. Regression tree analysis is where the target variable can take continuous values typically real numbers such as the price of a house,<span style=\"text-align: initial;font-size: 1em\">or a patient\u2019s length of stay in a hospital. The term <\/span><strong style=\"text-align: initial;font-size: 1em\">C<\/strong><span style=\"text-align: initial;font-size: 1em\">lassification <\/span><strong style=\"text-align: initial;font-size: 1em\">A<\/strong><span style=\"text-align: initial;font-size: 1em\">nd <\/span><strong style=\"text-align: initial;font-size: 1em\">R<\/strong><span style=\"text-align: initial;font-size: 1em\">egression<\/span><strong style=\"text-align: initial;font-size: 1em\"> T<\/strong><span style=\"text-align: initial;font-size: 1em\">ree (CART) analysis is used to refer to both types of attributes categorical and numeric. Trees used for classification and regression are similar but differ how they determine the splitting procedure.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">15.2.3 Salient Aspects of CART<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">One of the key features of CART is automated attribute or feature selection. The process can automatically select relevant fields irrespective of the total number of fields. Moreover no data preprocessing or transformation of the variables is needed. The CART is is tolerant to missing values, and there is only a moderate loss of accuracy due to missing values.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">15.3\u00a0\u00a0 CART- General Framework &#8211; The Six Questions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Associated with CART are six questions to be answered or six issues to be addressed. The following are the questions:<\/span><\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">How many splits will be there at each node?<\/strong><\/li>\n<\/ol>\n<p>Should the questions to be asked for the split at each node be binary (e.g., is gender male or female) or numeric (e.g., height is 5\u20194\u201d) or multi-valued (e.g., caste)?<\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>2.\u00a0<\/strong><strong>Which properties should be tested at each node?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The decision on which variable or feature to use for splitting is an important issue and in fact determines the efficiency of the procedure.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>3.<\/strong><strong>When does a node become a leaf?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">We need a criteria to determine that the subset of examples associated with a node need not be partitioned further.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>4.<\/strong><strong>How to prune a large tree?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Simplify the tree by pruning peripheral branches to avoid over fitting. Some parts of the tree need not be explored or partitioned further since deep trees that fit the training data well, will not generalize well to new test data<strong>.<\/strong> How do we determine this?<\/p>\n<p>&nbsp;<\/p>\n<p><strong>5.<\/strong><strong>If a leaf node is impure, how to assign labels?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In case the leaf node is impure that is results in more than one output variable value, how do we assign an output value for unknown samples.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>6.<\/strong><strong>How to handle missing data?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The issue here is how to account for missing data of some features when decisions regarding this data are taken.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">15.4\u00a0 CART Steps<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p>The following are the steps used by CART for the construction of the decision tree.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">1.<strong>Initialization<\/strong>: Initially a tree is created with a single root node containing all the training data.<\/p>\n<p style=\"text-align: justify\">2.<strong>Tree growing: <\/strong>Recursive Partitioning is the most important component of tree construction. This procedure consists of 5 sub steps which are described below:<\/p>\n<p style=\"text-align: justify\">a.The first step here is the selection of the splitting criterion which in most cases is based on likelihood. For this purpose we need to find the best question for splitting each node. We then split the node that results in the greatest increase in the likelihood.<\/p>\n<p style=\"text-align: justify\">b.We then rank all of the best splits and then the best split in the variable is selected in terms of the reduction in impurity (heterogeneity). This aspect we will discuss later.<\/p>\n<p style=\"text-align: justify\">c.The Predicted classes are assigned to the nodes according to a rule that minimizes misclassification costs.<\/p>\n<p style=\"text-align: justify\">d.The next step is the decision about the stopping criteria that is how far to grow? We generally stop expanding a node when all the records belong to the same class or when all the records have similar attribute values. Stopping criteria decides whether to continue splitting a node.<\/p>\n<p style=\"text-align: justify\">e.Using surrogates program best available information is used to replace missing data, normally based on a variable that is relative to the outcome variable.<\/p>\n<p style=\"text-align: justify\">3.<strong>Stop tree building<\/strong>: When every aspect of the dataset has been taken into account while building the decision tree, the tree building process itself is stopped.<\/p>\n<p style=\"text-align: justify\">4.<strong>Tree Pruning: <\/strong>An independent test set or cross-validation is generally used to prune the tree. Pruning is carried out by trimming off parts of the tree that don\u2019t work. Another method is to first order the nodes of a large tree by contribution to tree accuracy and this ordering is used as a basis to prune nodes.<\/p>\n<p style=\"text-align: justify\">5.<strong>Optimal Tree Selection: <\/strong>This process is the selection of the best tree that fits dataset with a low percentage of error. The decision about the best tree is made after growing and pruning. This selection of optimal tree is also based on balancing simplicity against accuracy.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">15.5\u00a0 Recursive Partitioning<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p>The key idea behind the CART technique is recursive partitioning. Let us understand this concept in detail. The recursive procedure is described as follows:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">i.Consider all the data samples.<\/p>\n<p style=\"text-align: justify\">ii.Consider <em>all<\/em> possible values of <em>all<\/em> variables.<\/p>\n<p style=\"text-align: justify\">iii.Select the variable and the value (<em>X<\/em>=<em>t<\/em><em>1<\/em>) that produces the greatest \u201cseparation\u201d in the target. This point of the variable X (<em>X<\/em>=<em>t<\/em><em>1<\/em>) is called a \u201csplit\u201d.<\/p>\n<p>iv.If <em>X<\/em>&lt; <em>t<\/em><em>1<\/em> then send the data to the \u201cleft\u201d; otherwise, send data point to the \u201cright\u201d.<\/p>\n<p style=\"text-align: justify\">v.Now repeat same process on these two \u201cnodes\u201d<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">What you get as output is a \u201ctree\u201d. Note that CART only uses <em>binary<\/em> splits. The main step in the process is Recursive Partitioning (step iii) where we<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">\u2022 First we pick a value of <em>x<\/em>i, say <em>s<\/em>i, that divides the training data into two (not necessarily equal) portions<\/p>\n<p style=\"text-align: justify\">\u2022 Then we measure how \u201cpure\u201d or homogeneous each of the resulting portions are. In this context a partition being \u201cPure\u201d means that they contain records of mostly one class.<\/p>\n<p style=\"text-align: justify\">\u2022 The algorithm tries different values of <em>x<\/em>i, and <em>s<\/em>i to maximize purity in initial split<\/p>\n<p style=\"text-align: justify\">\u2022 After we get a \u201cmaximum purity\u201d split, we repeat the process for a second split, and so on<\/p>\n<p>&nbsp;<\/p>\n<p><strong>15.6\u00a0 Features of CART<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Some of the important features of the process of CART are as follows:<\/p>\n<ul>\n<li style=\"text-align: justify\">Data is split into two partitions that is at every node the set is split into two subsets.<\/li>\n<li style=\"text-align: justify\">Splits at any node are based only on one variable.<\/li>\n<li style=\"text-align: justify\">Partitions can also be split into sub-partitions and hence procedure is recursive. CART tree is generated by repeated partitioning of data set where each decision node has two child nodes and so on.<\/li>\n<\/ul>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>15.7\u00a0 Construction of a Tree<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">During the construction of the tree we need to first carry out the most important step that is the selection of the splits. We further need to make decisions as to whether a node is a terminal node (i.e. not to split it any further). We also need to assign a class to each terminal node.<\/p>\n<p>&nbsp;<\/p>\n<p>The following are the steps of tree building<\/p>\n<ol>\n<li style=\"text-align: justify\">Start with splitting a variable at all of its split points. Pick one of the predictor variables Xi, and pick a value of the variable say Si that divides the training data into two (not necessarily equal) portions. Measure how\u201cpure\u201d or homogeneous each of the resulting portions are. As we discussed a pure partition contains records of mostly one class. Idea is to select different values Si of the variable Xi to form the partitions. These different values of the variables used for forming the partitions are called split points.<\/li>\n<li style=\"text-align: justify\">The sample set splits into two binary nodes at each split point.<\/li>\n<li style=\"text-align: justify\">Select the best split in the variable in terms of the reduction in impurity (heterogeneity)<\/li>\n<li style=\"text-align: justify\">Repeat steps 1,2 for all variables at root node.<\/li>\n<li style=\"text-align: justify\">Rank all of best splits &amp; select the variable that achieves the highest purity at root.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><strong>15.7.1 Method of Splitting<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-231 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-148.png\" alt=\"\" width=\"260\" height=\"353\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-148.png 260w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-148-221x300.png 221w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-148-65x88.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-148-225x305.png 225w\" sizes=\"auto, (max-width: 260px) 100vw, 260px\" \/><\/p>\n<p style=\"text-align: justify\">We first order records according to one variable. Then we need to find midpoints between successive values. We then divide records. After evaluating that split, try the next midpoint. In the case of categorical variables, examine all possible ways in which the categories can be split. For example assume that the categories A, B, C can be split 3 ways as {A} and {B, C}, {B} and {A, C}, {C} and {A, B}. Please note that with many categories, the number of splits becomes huge. Many of the tools available support only binary categorical variables.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Now let us consider the example given in Figure 15.2. The decision variables in this example are car type, age and number of children. The output variable in this example is whether there is insurance claim or not. The decision tree is shown in Figure 15.3. In this example we start with age as the root node of the decision tree. The numerical value of age has been split as \u00a3 30 and &gt; 30. This divides the total number of 14 samples into two sets of 7 samples each. Now at the left we split the 7 examples into two sets of sedan on one side (with 3 as sedan) and 4 either sports or truck on the right. This leaves us with claim as all yes on left and all no on right. For the right side of the root we first use the number of children attribute for splitting. Here the split is taken as no children (2 samples) or having children (5 samples). At the next level we split on both sides based on car type. Now at the leaves we are left with no on one side and yes on the other. This decision helps to decide whether claim is possible or not.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-232 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-149.png\" alt=\"\" width=\"491\" height=\"351\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-149.png 491w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-149-300x214.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-149-65x46.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-149-225x161.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-149-350x250.png 350w\" sizes=\"auto, (max-width: 491px) 100vw, 491px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>In the Insurance Example<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"text-align: justify\">Suppose we have 3 variables Type of Car :{sedan, sports, truck}, Age category:{ \u226430 &amp;&gt; 30},Number of Children :{0,1,2}<\/li>\n<li style=\"text-align: justify\">At each iteration, CART tests all splits.Some of the splits for the variable<\/li>\n<\/ul>\n<p style=\"text-align: justify\">Type of car having three values are &#8211; Car = {sedan} &amp; {truck &amp; sports} or { sedan &amp; truck} &amp; {sports} or {sedan &amp; sports} &amp; {truck} .For the Age variable as we can see the split point can be \u226430 &amp;&gt; 30, \u226435 &amp;&gt; 35 etc.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-233 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-150.png\" alt=\"\" width=\"429\" height=\"355\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-150.png 429w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-150-300x248.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-150-65x54.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-150-225x186.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-150-350x290.png 350w\" sizes=\"auto, (max-width: 429px) 100vw, 429px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 15.4 The Split of Samples based on Decision Tree in Figure 15.3<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>15.8 Selection of Split<\/strong><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">The split has to be so selected that it results in greater increase in <\/span><em style=\"text-align: initial;font-size: 1em\">purity<\/em><span style=\"text-align: initial;font-size: 1em\">. In case of the example given in the previous section:<\/span><\/p>\n<div>\n<ul>\n<li>Perfect purity:\u00a0 each split has either all claims or all no-claims.<\/li>\n<li>Perfect impurity: each split has same proportion of claims as overall population.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>15.8.1 Splitting Rules<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">As discussed before we need to select the variable value (<em>X<\/em>=<em>t<\/em><em>1<\/em>) that produces the greatest \u201cseparation\u201d in the target variable. \u201cSeparation\u201d can be defined in many ways. In the case of <strong>Regression Trees<\/strong> (continuous target), we can use sum of squared errors. In the case of <strong>Classification Trees<\/strong> (categorical target) we can use either <em>entropy<\/em>, <em>Gini measure<\/em>, or a \u201c<em>twoing<\/em>\u201d splitting rule. In the tree-based modeling for <em>discrete<\/em> target variable, various measures of <em>purity<\/em> are used. The intuition is that an ideal model would produce nodes that contain either calims only or no-claims (example in Figure 15.2) only that is completely pure nodes.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The main issue in the choice of a measure is the balance between getting pure nodes and getting equal size nodes (that is partitioning into roughly equal sized sets).<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The Gini purity of a node and Entropy of a node are discussed in the next section. The maximum entropy\/Gini index occurs when records are equally distributed among all classes implying least information and minimum entropy\/Gini index occurs when when all records belong to one class, implying most interesting information.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Gini might produce small but pure nodes. The \u201ctwoing\u201d rule strikes a balance between purity and creating roughly equal-sized nodes so that we do not always choose a split that gives pure nodes but rather choose a split that gives an almost pure nodes that gives roughly equal size partitions.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>15.8.2 Impurity and Recursive Partitioning<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The idea is to select the split that decreases the Gini Index. We have to consider all possible places for a split. This essentially means that we have to select the variable and the possible splits in values of the variables appropriately. The chosen split points become nodes on the tree. We keep splitting until the terminal nodes have very few cases or are all pure. The best approach is to grow a larger tree than required and then to <em>prune<\/em> it. We will discuss pruning in the next module.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Now we need a measure of impurity of a node to help decide on how to split a node, or which node to split. The measure should be at a maximum when a\u00a0<span style=\"text-align: initial;font-size: 1em\">node is equally divided amongst all classes. The impurity should be zero if the node is all one class.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">There are various measures of impurity. Misclassification rate is one such measure, but this measure is not generally used since no split improves the misclassification rate, and can be equal when one option is clearly better for the next step. Other measures are Information, or Entropy and Gini Index.<\/span><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>15.8.1 Information or Entropy<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>If a node has a proportion of pj of each of the classes then the information or entropy is:<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-234 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-151.png\" alt=\"\" width=\"333\" height=\"92\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-151.png 333w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-151-300x83.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-151-65x18.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-151-225x62.png 225w\" sizes=\"auto, (max-width: 333px) 100vw, 333px\" \/><\/p>\n<p>where p=(p1,p2,\u2026. pn) is the relative frequency of class <em>k at the node.<\/em><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Entropy ranges between 0 (most pure) and log2(<em>m<\/em>) (equal representation of classes) where m is total number of classes.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>15.8.2 Gini Index<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>This the most widely used measure of impurity by CART.If a data set contains examples from n classes, gini index, is defined as<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-235 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-152.png\" alt=\"\" width=\"415\" height=\"95\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-152.png 415w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-152-300x69.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-152-65x15.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-152-225x52.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-152-350x80.png 350w\" sizes=\"auto, (max-width: 415px) 100vw, 415px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><em>where p <\/em>is the proportion of cases that belong to class<em> k\u00a0<\/em><em>i(p) <\/em>= 0 when all cases belong to same class and has maximum value when all classes are equally represented (= 0.50 in binary case)<\/p>\n<p>&nbsp;<\/p>\n<p><strong>15.8.3 Tree Impurity<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The impurity of a tree is the sum over all terminal nodes of the impurity of a node multiplied by the proportion of cases that reach that node of the tree. Impurity of a tree with one single node, with both A and B having 400 cases (Figure 15.5), using the Gini Index is as follows:<\/p>\n<p>&nbsp;<\/p>\n<p>Proportions of the two cases<\/p>\n<p>= number of cases of one attribute\/total number of cases = 400\/800 ( for both attribute A and B)<\/p>\n<p>Gini Index<\/p>\n<p>= <strong>1- p<\/strong><strong>2<\/strong><strong>A<\/strong><strong>&#8211; p<\/strong><strong>2<\/strong><strong>B<\/strong><\/p>\n<p>=1-(0.5)2- (0.5)2 = 0.5<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-236 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-153.png\" alt=\"\" width=\"574\" height=\"234\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-153.png 574w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-153-300x122.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-153-65x26.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-153-225x92.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-153-350x143.png 350w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-237 aligncenter\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-154.png\" alt=\"\" width=\"590\" height=\"338\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-154.png 590w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-154-300x172.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-154-65x37.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-154-225x129.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2018\/08\/Untitled-154-350x201.png 350w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/p>\n<p style=\"text-align: justify\">Figure 15.6 shows another example where we show the nodes of the tree and its contribution to impurity is calculated based on Gini Index. Let us consider the calculation of Gini Index of row 1.<\/p>\n<p>&nbsp;<\/p>\n<p>Proportions of the two cases<\/p>\n<ul>\n<li style=\"text-align: justify\">= number of cases of one attribute\/total number of cases<\/li>\n<li style=\"text-align: justify\">= 300\/400 = 0.75 (for both attribute A) and 100\/400 =0.25 (for both attribute B) Gini Index<\/li>\n<li style=\"text-align: justify\">= <strong>1- p<\/strong><strong>2<\/strong><strong>A<\/strong><strong>&#8211; p<\/strong><strong>2<\/strong><strong>B<\/strong>=1-(0.75)2- (0.25)2 = 0.375<\/li>\n<\/ul>\n<p><strong>15.9 Tree Structure<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The decision tree is represented by using the split points to decide which are the nodes of the tree (circles with split value in center). Rectangles represent \u201cleaves\u201d (terminal points, no further splits, classification value noted). Numbers on lines (branches) between nodes indicate the number of cases. We read down the tree from the root to derive the rule.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>15.9.1 Determining Leaf Node Label<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Another important aspect in the construction of the tree is to assign a label to each leaf node. Each leaf node label is determined by \u201cvoting\u201d of the records within it, and by the cutoff value. Records within each leaf node are from the training data. The leaf node\u2019s label will be assigned the majority class when the default cutoff is 0.5. When the cutoff = 0.75, the requirement is that a majority of 75% or more \u201c1\u201d records in the leaf is needed to label it a \u201c1\u201d node.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary<\/strong><\/p>\n<ul>\n<li style=\"text-align: justify\">Explained the CART approach to decision tree building<\/li>\n<li style=\"text-align: justify\">Outlined the key features of CART<\/li>\n<li style=\"text-align: justify\">Explained the various steps of the CART approach<\/li>\n<li style=\"text-align: justify\">Discussed the recursive partitioning approach<\/li>\n<li style=\"text-align: justify\">Outlined the Gini Index<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on Classification and Regression Trees \u2013 I<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/1OqZ1Qd6niI\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Web Links<\/strong><\/p>\n<ul>\n<li style=\"text-align: justify\">https:\/\/www.casact.org\/education\/specsem\/f2005\/handouts\/cart.ppt<\/li>\n<li style=\"text-align: justify\">www.washburn.edu\/faculty\/boncella\/&#8230;\/Lecture%207%20-%20CART.ppt<\/li>\n<li style=\"text-align: justify\">www.kdnuggets.com\/data_mining_course\/dm8-decision-tree-cart.ppt<\/li>\n<li style=\"text-align: justify\">artax.karlin.mff.cuni.cz\/~smetp0am\/odkazy\/CLASSFINAL.PPT<\/li>\n<li style=\"text-align: justify\">ww.stat.ucla.edu\/~kcli\/stat287\/lectures-287\/Lecture&#8230;\/Classification.ppt<\/li>\n<li style=\"text-align: justify\">www.cs.cornell.edu\/courses\/cs578\/2002fa\/CS578.02_DT_lecture.ppt<\/li>\n<li style=\"text-align: justify\">homes.cs.washington.edu\/~shapiro\/EE596\/notes\/InfoGain.pdf<\/li>\n<\/ul>\n","protected":false},"author":3,"menu_order":14,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[],"contributor":[],"license":[],"class_list":["post-229","chapter","type-chapter","status-publish","hentry"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapters\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/wp\/v2\/users\/3"}],"version-history":[{"count":6,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapters\/229\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapters\/229\/revisions\/481"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapters\/229\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapter-type?post=229"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/wp\/v2\/contributor?post=229"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/wp\/v2\/license?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}