{"id":3557,"date":"2024-09-02T20:44:19","date_gmt":"2024-09-02T20:44:19","guid":{"rendered":"https:\/\/workhouse.sweetdishy.com\/?p=3557"},"modified":"2024-09-02T20:44:20","modified_gmt":"2024-09-02T20:44:20","slug":"classification-techniques","status":"publish","type":"post","link":"https:\/\/workhouse.sweetdishy.com\/index.php\/2024\/09\/02\/classification-techniques\/","title":{"rendered":"\u00a0Classification Techniques"},"content":{"rendered":"\n<p id=\"Arti00001721\">In this section, we will read about some widely used classification algorithms. These algorithms predict the probability that the data that follows will fall into one of the predetermined categories.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Arti00001722\"><a><\/a><strong>2.4.1 K-Nearest Algorithm<\/strong><\/h4>\n\n\n\n<p id=\"Arti00001723\">The k-nearest neighbour algorithm is a supervised learning algorithm in which the output value of data is known but how to get the output is not known. For example, if we have several groups of labeled samples and all items available are homogeneous, then to find which group an item with unknown label belongs, we will find similarities between the item (at hand) and with items in each group. Finally, we will conclude that the item belongs to the group to which it is most similar. The k-nn algorithm works in exactly the same way.<\/p>\n\n\n\n<p id=\"Arti00001724\">The k nearest neighbours\u2019 algorithm stores all available cases and classifies new cases by a majority vote of its k neighbours. The algorithm segregates unlabelled data values into well-defined groups.<\/p>\n\n\n\n<p id=\"Arti00001725\">Technically speaking,&nbsp;<strong><em>k-nn is a non-parametric supervised learning algorithm<\/em><\/strong>&nbsp;which classifies data into a particular category with the help of training set. Here, the word non-parametric means that it makes assumptions on the underlying data distribution. Non-parametric methods do not have fixed numbers of parameters in the model. The parameters in the model grows with the training data set.<\/p>\n\n\n\n<p id=\"Arti00001726\">In the k-nn algorithm, the value for a new instance (x) is predicted by searching the training set for the k most similar cases (neighbours) and summarizing the output values for those k cases. In other words, this is the mode (or most common) value.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Arti00001727\"><a><\/a><strong>2.4.1.1 Choosing an Appropriate K Value<\/strong><\/h4>\n\n\n\n<p id=\"Arti00001728\">The most important thing to do in the knn algorithm is to determine an appropriate value of k, that is, the number of nearest neighbours. A large value of k reduces the noisy data. But if we have more data points in one group then we may ignore the smaller patterns which may have useful insights.<\/p>\n\n\n\n<p id=\"Arti00001729\">&nbsp;<\/p>\n\n\n\n<p id=\"Arti00001731\">k-nn uses all of the data for training while classifying a new data point or instance.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Arti00001732\"><a><\/a><strong>2.4.1.2 Example of Knn Algorithm<\/strong><\/h4>\n\n\n\n<p id=\"Arti00001733\">Suppose we have n number of students rated on two parameters \u2013 Academic Score and EC Score on a scale of 1 to 10 as given in\u00a0Table 2.1.<\/p>\n\n\n\n<p id=\"Arti00001734\">&nbsp;<\/p>\n\n\n\n<p id=\"Arti00001736\"><a><\/a><strong>TABLE 2.1<\/strong>&nbsp;Academic Score and EC Score<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p98-1.png\" alt=\"images\" width=\"618\" height=\"133\"><\/p>\n\n\n\n<p id=\"Arti00001738\">Then, academic score is an indication of how well the student performs academically and EC score is the score obtained by the student in extra-curricular activities.<\/p>\n\n\n\n<p id=\"Arti00001739\">Now, if we have a new student to categorize then we will calculate distance between \u2018New Student\u2019 and its nearest neighbours (\u2018Outstanding\u2019, \u2018Sporty\u2019, \u2018Academically Sound\u2019 and \u2018Below Average\u2019) using the Euclidean distance formula as shown in\u00a0Fig. 2.15.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p98-2.png\" alt=\"images\" width=\"400\" height=\"246\"><\/p>\n\n\n\n<p id=\"Arti00001742\"><a><\/a><strong>FIGURE 2.15<\/strong>&nbsp;Euclidean distance between two points<\/p>\n\n\n\n<p id=\"Arti00001743\">Assuming that co-ordinates of the New Student are (8,2), we calculate the distance between Below Average (2,1) and New Student as:<\/p>\n\n\n\n<p id=\"Arti00001744\"><em>dist(Below Average, New Student) = 6.08<\/em><\/p>\n\n\n\n<p id=\"Arti00001745\">Similarly, calculate the distance of New Student from each of its nearest neighbours as shown in\u00a0Table 2.2.<\/p>\n\n\n\n<p id=\"Arti00001746\">&nbsp;<\/p>\n\n\n\n<p id=\"Arti00001748\"><a><\/a><strong>TABLE 2.2<\/strong>&nbsp;Scores including New Data<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p98-3.png\" alt=\"images\" width=\"618\" height=\"153\"><\/p>\n\n\n\n<p id=\"Arti00001750\"><a><\/a>We see that the distance between New Student and Academically Sound is the least so the New Student belongs to the group of academically sound students.<\/p>\n\n\n\n<p id=\"Arti00001751\">k-NN algorithm can also be used for prediction. It is extensively used in pharmaceutical industry to detect the growth of oncogenic (cancer) cells or presence of disease.<\/p>\n\n\n\n<p id=\"Arti00001752\"><strong>Another Example<\/strong><\/p>\n\n\n\n<p id=\"Arti00001753\">Consider\u00a0Fig. 2.16. If we have to two classes \u2013 class A denoted by red stars and class B indicated by blue triangles, then to classify a new green square object the value of k plays an important role. If k=3, then according to\u00a0<a href=\"https:\/\/learning.oreilly.com\/library\/view\/artificial-intelligence-beyond\/9789357053778\/xhtml\/chapter002.xhtml#fig2-16\">Fig. 2.16<\/a>, the 3 nearest neighbours belong to class B. So, the new object is placed in class B. but if we take k = 7, then the new object will be a member of class A. If we take k = 1, then the new object will belong to class B. Hence, value of k greatly influences the classification.<\/p>\n\n\n\n<p id=\"Arti00001754\">&nbsp;<\/p>\n\n\n\n<p id=\"Arti00001756\">The K-nearest neighbour can be used for regression when dependent variable is continuous. In this case, the predicted value is the average of the values of its k nearest neighbours.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learning.oreilly.com\/api\/v2\/epubs\/urn:orm:book:9789357053778\/files\/images\/img_p99.png\" alt=\"images\" width=\"173\" height=\"157\"><\/p>\n\n\n\n<p id=\"Arti00001759\"><a><\/a><strong>FIGURE 2.16<\/strong>&nbsp;Finding nearest neighbor for the new data point (green). The new data will either belong to the group represented by red star or to the one represented as blue triangle<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Arti00001760\"><a><\/a><strong>2.4.1.3 Pros and Cons of Knn Algorithm<\/strong><\/h4>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Arti00001761\"><strong>Pros<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\" id=\"Arti00001762\">\n<li>The kNN algorithm is a very simple and effective algorithm.<\/li>\n\n\n\n<li>Users can easily implement the algorithm which has made the algorithm quite popular with data professionals.<\/li>\n\n\n\n<li>The algorithm is highly unbiased in nature and does not make any prior assumption of the underlying data.<\/li>\n\n\n\n<li>The kNN algorithm works well with multi-class algorithms<\/li>\n\n\n\n<li>The algorithm can be applied to both classification and regression.<\/li>\n<\/ol>\n\n\n\n<p id=\"Arti00001769\">KNN is a non-parametric learning algorithm, which means that it doesn&#8217;t assume anything about the underlying data.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Arti00001770\"><strong>Cons<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\" id=\"Arti00001771\">\n<li>Usually, simple things are not very powerful; same is the case with kNN algorithm.<\/li>\n\n\n\n<li>Although the algorithm trains the model really fast, the prediction time is high<\/li>\n\n\n\n<li>Many a time, useful insights may get ignored.<\/li>\n\n\n\n<li><a><\/a>The algorithm is sensitive to the scale of data so data must first be standardized<\/li>\n\n\n\n<li>The performance of the algorithm deteriorated when there are multiple independent variables<\/li>\n\n\n\n<li>The algorithm requires more memory and is computationally expensive<\/li>\n\n\n\n<li>It does not work well if the target variable is skewed<\/li>\n\n\n\n<li>The accuracy of the algorithm depends on k value. For any given problem, a small value of k will lead to a large variance in predictions. And setting k to a large value may lead to a large model bias.<\/li>\n<\/ol>\n\n\n\n<p id=\"Arti00001780\">&nbsp;<\/p>\n\n\n\n<p id=\"Arti00001782\"><strong>Handling categorical variables in KNN<\/strong><\/p>\n\n\n\n<p id=\"Arti00001783\">If you have categorical variables, then create k dummy variables out of that categorical variable. For example, if a categorical variable named \u201cDesignation\u201d has 3 unique levels \/ categories then create 3 dummy variables. Each dummy variable has 1 against its designation and 0 otherwise.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this section, we will read about some widely used classification algorithms. These algorithms predict the probability that the data that follows will fall into one of the predetermined categories. 2.4.1 K-Nearest Algorithm The k-nearest neighbour algorithm is a supervised learning algorithm in which the output value of data is known but how to get [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3333,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[452],"tags":[],"class_list":["post-3557","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence-technologies"],"jetpack_featured_media_url":"https:\/\/workhouse.sweetdishy.com\/wp-content\/uploads\/2024\/08\/artificial-intelligence.png","_links":{"self":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/comments?post=3557"}],"version-history":[{"count":1,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3557\/revisions"}],"predecessor-version":[{"id":3558,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/posts\/3557\/revisions\/3558"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/media\/3333"}],"wp:attachment":[{"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/media?parent=3557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/categories?post=3557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/workhouse.sweetdishy.com\/index.php\/wp-json\/wp\/v2\/tags?post=3557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}