{"id":267,"date":"2018-07-19T10:46:14","date_gmt":"2018-07-19T10:46:14","guid":{"rendered":"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=267"},"modified":"2018-07-19T10:46:14","modified_gmt":"2018-07-19T10:46:14","slug":"classification","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/chapter\/classification\/","title":{"rendered":"Classification"},"content":{"raw":"<div>\r\n\r\n<strong>Classification<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In this session, we continue our examination of classification methods for data mining. One attractive classification method involves the construction of a <em>decision tree<\/em>, a collection of <em>decision<\/em> <em>nodes<\/em>, connected by<em> branches<\/em>, extending downward from the<em> root node <\/em>until terminating in<em> leaf nodes<\/em>. Beginning at the root node, which by convention is placed at the top of the decision tree diagram, attributes are tested at the decision nodes, with each possible outcome resulting in a branch. Each branch then leads either to another decision node or to a terminating leaf node. Figure 1 provides an example of a simple decision tree. The target variable for the decision tree in Figure 1 is <em>credit risk<\/em>, with potential customers being classified as either good or bad credit risks.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The predictor variables are <em>savings<\/em> (low, medium, and high), <em>assets<\/em> (low or not low), and <em>income<\/em> (\u2264$50,000 or <em>&gt;<\/em>$50,000). Here, the root node represents a decision node, testing whether each record has a low, medium, or high savings level (as defined by the analyst or domain expert). The data set is partitioned, or <em>split<\/em>, according to the values of this attribute.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Those records with low savings are sent via the leftmost branch (<em>savings<\/em> = <em>low<\/em>) to another decision node. The records with high savings are sent via the rightmost branch to a different decision node. The records with medium savings are sent via the middle branch directly to a leaf node, indicating the termination of this branch. Why a leaf node and not another decision node? Because, in the data set (not shown), all of the records with medium savings levels have been classified as good credit risks. There is no need for another decision node, because our knowledge that the customer has medium savings predicts good credit with 100% accuracy in the data set. For customers with low savings, the next decision node tests whether the customer has low assets. Those with low assets are then classified as bad credit risks; the others are classified as good credit risks. For customers with high savings, the next decision node tests whether the customer has an income of at most $30,000.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Customers with incomes of $30,000 or less are then classified as bad credit risks, with the others classified as good credit risks. When no further splits can be made, the decision tree algorithm stops growing new nodes. For example, suppose that all of the branches terminate in \u201cpure\u201d leaf nodes, where the target variable is unary for the records in that node (e.g., each record in the leaf node is a good credit risk). Then no further splits are necessary, so no further nodes are grown. However, there are instances when a particular node contains \u201cdiverse\u201d attributes (with nonunary values for the target attribute), and yet the decision tree cannot make a split. For example, suppose that we consider the records from Figure 1 with high savings and low income (\u2264$30,000).<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Suppose that there are five records with these values, all of which also have low assets. Finally, suppose that three of these five customers have been classified as bad credit risks and two as good credit risks, as shown in Table 1. In the real world, one often encounters situations such as this, with varied values for the response variable, even for exactly the same values for the predictor variables.<\/p>\r\n<p style=\"text-align: justify\">such customers is \u201cbad,\u201d with 60% confidence, as determined by the three-fifths of customers in this node who are bad credit risks. Note that not all attributes are tested for all records. Customers with low savings and low assets, for example, are not tested with regard to income in this example.<\/p>\r\n&nbsp;\r\n\r\n<\/div>\r\n<div>\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-268 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-129.png\" alt=\"\" width=\"607\" height=\"419\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><strong>Table 1: Sample records that lead to pure leaf node<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-269 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-130.png\" alt=\"\" width=\"623\" height=\"206\" \/><\/p>\r\n&nbsp;\r\n\r\nCertain requirements must be met before decision tree algorithms may be applied:\r\n<ol>\r\n \t<li style=\"text-align: justify\"><span style=\"font-size: 1em\">Decision tree algorithms represent supervised learning, and as such require pre-classified target variables. A training data set must be supplied which provides the algorithm with the values of the target variable.<\/span><\/li>\r\n \t<li style=\"text-align: justify\"><span style=\"font-size: 1em\">This training data set should be rich and varied, providing the algorithm with a healthy cross section of the types of records for which classification may be needed in the future. Decision trees learn by example, and if examples are systematically lacking for a definable subset of records, classification and prediction for this subset will be problematic or impossible.<\/span><\/li>\r\n \t<li style=\"text-align: justify\"><span style=\"font-size: 1em\">T<\/span><span style=\"font-size: 1em\">he target attribute classes must be discrete. That is, one cannot apply decision tree analysis to a continuous target variable. Rather, the target variable must take on values that are clearly demarcated as either belonging to a particular class or not belonging.<\/span><\/li>\r\n<\/ol>\r\n<\/div>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Why in the example above, did the decision tree choose the savings attribute for the root node split? Why did it not choose assets or income instead? Decision trees seek to create a set of leaf nodes that are as \u201cpure\u201d as possible, that is, where each of the records in a particular leaf node has the same classification. In this way, the decision tree may provide classification assignments with the highest measure of confidence available.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">However, how does one measure uniformity, or conversely, how does one measure heterogeneity? We shall examine two of the many methods for measuring leaf node purity, which lead to the two leading algorithms for constructing decision trees:<\/p>\r\n&nbsp;\r\n\r\nClassification and regression trees (CART) algorithm C4.5 algorithm.\r\n\r\n&nbsp;\r\n\r\n<strong>COMPARISON OF THE C5.0 AND CART ALGORITHMS APPLIED TO REAL DATA<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Next, we apply decision tree analysis using Clementine on a real-world data set. The data set <em>adult<\/em> was abstracted from U.S. census data by Kohavi and is available online from the University of California at Irvine Machine Learning Repository.<\/p>\r\n<p style=\"text-align: justify\"><\/p>\r\n<p style=\"text-align: justify\">Here, we are interested in classifying whether or not a person\u2019s income is less than $50,000, based on the following set of predictor fields.<\/p>\r\n&nbsp;\r\n\r\n<strong>Numerical variables<\/strong>\r\n\r\n&nbsp;\r\n\r\nAge, Years of education, Capital gains, Capital losses, Hours worked per week.\r\n\r\nCategorical variables, Race, Gender, Work class, Marital status.\r\n<p style=\"text-align: justify\">The numerical\u00a0 variables\u00a0 were normalized so that all values\u00a0 ranged between zero and 1.Some\u00a0 collapsing\u00a0 of\u00a0 low-frequency\u00a0 classes\u00a0 was\u00a0 carried\u00a0 out\u00a0 on the\u00a0 work class and marital\u00a0 status categories.Clementine\u00a0 was used to compare\u00a0 the C5.0\u00a0 algorithm (an\u00a0 update\u00a0 of\u00a0 the\u00a0 C4.5\u00a0 algorithm)\u00a0 with\u00a0 CART,\u00a0 examining\u00a0 a\u00a0 training\u00a0 set of\u00a0 24,986 records. The decision tree produced by the CART algorithm.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center\"><img class=\"size-full wp-image-270 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-131.png\" alt=\"\" width=\"629\" height=\"359\" \/><\/p>","rendered":"<div>\n<p><strong>Classification<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In this session, we continue our examination of classification methods for data mining. One attractive classification method involves the construction of a <em>decision tree<\/em>, a collection of <em>decision<\/em> <em>nodes<\/em>, connected by<em> branches<\/em>, extending downward from the<em> root node <\/em>until terminating in<em> leaf nodes<\/em>. Beginning at the root node, which by convention is placed at the top of the decision tree diagram, attributes are tested at the decision nodes, with each possible outcome resulting in a branch. Each branch then leads either to another decision node or to a terminating leaf node. Figure 1 provides an example of a simple decision tree. The target variable for the decision tree in Figure 1 is <em>credit risk<\/em>, with potential customers being classified as either good or bad credit risks.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The predictor variables are <em>savings<\/em> (low, medium, and high), <em>assets<\/em> (low or not low), and <em>income<\/em> (\u2264$50,000 or <em>&gt;<\/em>$50,000). Here, the root node represents a decision node, testing whether each record has a low, medium, or high savings level (as defined by the analyst or domain expert). The data set is partitioned, or <em>split<\/em>, according to the values of this attribute.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Those records with low savings are sent via the leftmost branch (<em>savings<\/em> = <em>low<\/em>) to another decision node. The records with high savings are sent via the rightmost branch to a different decision node. The records with medium savings are sent via the middle branch directly to a leaf node, indicating the termination of this branch. Why a leaf node and not another decision node? Because, in the data set (not shown), all of the records with medium savings levels have been classified as good credit risks. There is no need for another decision node, because our knowledge that the customer has medium savings predicts good credit with 100% accuracy in the data set. For customers with low savings, the next decision node tests whether the customer has low assets. Those with low assets are then classified as bad credit risks; the others are classified as good credit risks. For customers with high savings, the next decision node tests whether the customer has an income of at most $30,000.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Customers with incomes of $30,000 or less are then classified as bad credit risks, with the others classified as good credit risks. When no further splits can be made, the decision tree algorithm stops growing new nodes. For example, suppose that all of the branches terminate in \u201cpure\u201d leaf nodes, where the target variable is unary for the records in that node (e.g., each record in the leaf node is a good credit risk). Then no further splits are necessary, so no further nodes are grown. However, there are instances when a particular node contains \u201cdiverse\u201d attributes (with nonunary values for the target attribute), and yet the decision tree cannot make a split. For example, suppose that we consider the records from Figure 1 with high savings and low income (\u2264$30,000).<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Suppose that there are five records with these values, all of which also have low assets. Finally, suppose that three of these five customers have been classified as bad credit risks and two as good credit risks, as shown in Table 1. In the real world, one often encounters situations such as this, with varied values for the response variable, even for exactly the same values for the predictor variables.<\/p>\n<p style=\"text-align: justify\">such customers is \u201cbad,\u201d with 60% confidence, as determined by the three-fifths of customers in this node who are bad credit risks. Note that not all attributes are tested for all records. Customers with low savings and low assets, for example, are not tested with regard to income in this example.<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-268 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-129.png\" alt=\"\" width=\"607\" height=\"419\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-129.png 607w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-129-300x207.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-129-65x45.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-129-225x155.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-129-350x242.png 350w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><strong>Table 1: Sample records that lead to pure leaf node<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-269 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-130.png\" alt=\"\" width=\"623\" height=\"206\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-130.png 623w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-130-300x99.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-130-65x21.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-130-225x74.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-130-350x116.png 350w\" sizes=\"auto, (max-width: 623px) 100vw, 623px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Certain requirements must be met before decision tree algorithms may be applied:<\/p>\n<ol>\n<li style=\"text-align: justify\"><span style=\"font-size: 1em\">Decision tree algorithms represent supervised learning, and as such require pre-classified target variables. A training data set must be supplied which provides the algorithm with the values of the target variable.<\/span><\/li>\n<li style=\"text-align: justify\"><span style=\"font-size: 1em\">This training data set should be rich and varied, providing the algorithm with a healthy cross section of the types of records for which classification may be needed in the future. Decision trees learn by example, and if examples are systematically lacking for a definable subset of records, classification and prediction for this subset will be problematic or impossible.<\/span><\/li>\n<li style=\"text-align: justify\"><span style=\"font-size: 1em\">T<\/span><span style=\"font-size: 1em\">he target attribute classes must be discrete. That is, one cannot apply decision tree analysis to a continuous target variable. Rather, the target variable must take on values that are clearly demarcated as either belonging to a particular class or not belonging.<\/span><\/li>\n<\/ol>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Why in the example above, did the decision tree choose the savings attribute for the root node split? Why did it not choose assets or income instead? Decision trees seek to create a set of leaf nodes that are as \u201cpure\u201d as possible, that is, where each of the records in a particular leaf node has the same classification. In this way, the decision tree may provide classification assignments with the highest measure of confidence available.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">However, how does one measure uniformity, or conversely, how does one measure heterogeneity? We shall examine two of the many methods for measuring leaf node purity, which lead to the two leading algorithms for constructing decision trees:<\/p>\n<p>&nbsp;<\/p>\n<p>Classification and regression trees (CART) algorithm C4.5 algorithm.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>COMPARISON OF THE C5.0 AND CART ALGORITHMS APPLIED TO REAL DATA<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Next, we apply decision tree analysis using Clementine on a real-world data set. The data set <em>adult<\/em> was abstracted from U.S. census data by Kohavi and is available online from the University of California at Irvine Machine Learning Repository.<\/p>\n<p style=\"text-align: justify\">\n<p style=\"text-align: justify\">Here, we are interested in classifying whether or not a person\u2019s income is less than $50,000, based on the following set of predictor fields.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Numerical variables<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Age, Years of education, Capital gains, Capital losses, Hours worked per week.<\/p>\n<p>Categorical variables, Race, Gender, Work class, Marital status.<\/p>\n<p style=\"text-align: justify\">The numerical\u00a0 variables\u00a0 were normalized so that all values\u00a0 ranged between zero and 1.Some\u00a0 collapsing\u00a0 of\u00a0 low-frequency\u00a0 classes\u00a0 was\u00a0 carried\u00a0 out\u00a0 on the\u00a0 work class and marital\u00a0 status categories.Clementine\u00a0 was used to compare\u00a0 the C5.0\u00a0 algorithm (an\u00a0 update\u00a0 of\u00a0 the\u00a0 C4.5\u00a0 algorithm)\u00a0 with\u00a0 CART,\u00a0 examining\u00a0 a\u00a0 training\u00a0 set of\u00a0 24,986 records. The decision tree produced by the CART algorithm.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-270 aligncenter\" src=\"http:\/\/csp4.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-131.png\" alt=\"\" width=\"629\" height=\"359\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-131.png 629w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-131-300x171.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-131-65x37.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-131-225x128.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-content\/uploads\/sites\/47\/2018\/07\/a2-131-350x200.png 350w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/p>\n","protected":false},"author":4,"menu_order":36,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-r-baskaran"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-267","chapter","type-chapter","status-publish","hentry","contributor-dr-r-baskaran"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":1,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/267\/revisions"}],"predecessor-version":[{"id":271,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/267\/revisions\/271"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapters\/267\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/media?parent=267"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/pressbooks\/v2\/chapter-type?post=267"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/contributor?post=267"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp4\/wp-json\/wp\/v2\/license?post=267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}