{"id":1722,"date":"2024-05-23T06:25:03","date_gmt":"2024-05-23T06:25:03","guid":{"rendered":"https:\/\/execedonline.co.in\/?p=1722"},"modified":"2024-05-25T18:31:37","modified_gmt":"2024-05-25T18:31:37","slug":"a-gentle-introduction-to-machine-learning","status":"publish","type":"post","link":"https:\/\/execedonline.co.in\/index.php\/2024\/05\/23\/a-gentle-introduction-to-machine-learning\/","title":{"rendered":"A gentle introduction to Machine Learning"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>Introduction<\/strong><\/h2>\n\n\n\n<p class=\"has-text-align-left has-black-color has-text-color has-link-color has-medium-font-size wp-elements-234d939704a60877cdf325022f4acbd2\">In today&#8217;s data driven world, ML algorithms are at work at all times, when we go about our daily lives. Whenever we make a CC transaction there is a ML algorithm that looks at it see if it is a legitimate transaction or a fraudulent one, when you are browsing for a book or a product at an e-commerce platform, it comes up with recommendations on what you might like, your healthcare service provider is probably using ML to screen the radiology images to see if a growth is benign or not. Facial recognition, driverless cars and the list of applications that use ML are ever expanding.<\/p>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-black-color has-text-color has-link-color wp-elements-0842d7327bdbdafbf87c76a834a34cd8\"><strong>ML vs Programmatic approach to problem solving<\/strong><\/h2>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-text-align-left has-black-color has-text-color has-link-color has-medium-font-size wp-elements-13a1cc2ade8cf33859d05ec5dbb8d9a8\">Before we delve into what ML algorithms are, how they work, there is a more fundamental question that must be answered. Why do we need to make the machines learn? Why can&#8217;t we code up the steps involved in solving the problem and make the computer do we what we want them to do? After all, that is a way we have been using the computers thus far. The field of Computer Sciences is all about solving problems. So long us we choose the right data structure and the steps in involved in solving the problem, no problem is too difficult to solve. Isn&#8217;t it? Then why all this fuss about making the machines to learn from data. And moreover, the ML problems are data hungry. We need humongous amount of data to train the ML models? But why? Why waste computing resources, collect so much of data so that the machines can learn to predict from the data? Isn\u2019t there a simpler way? Isn\u2019t there a way to solve the same problem programmatically? We will try and answer those questions through an example.<\/p>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-black-color has-text-color has-link-color wp-elements-be21979dcf71a1ccdce3a22b034034cd\"><strong>Computer recognition of hand-written digits<\/strong><\/h2>\n\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-text-align-left has-black-color has-text-color has-link-color has-medium-font-size wp-elements-797584cdcb56cd47e9367226e043257b\">To understand why ML is the way to solve a problem for certain application, let us consider a simple example. Say, you want the computer to recognise handwritten digits.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"848\" height=\"154\" src=\"https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/handwritten-digits.jpg\" alt=\"\" class=\"wp-image-1723\" srcset=\"https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/handwritten-digits.jpg 848w, https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/handwritten-digits-300x54.jpg 300w, https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/handwritten-digits-768x139.jpg 768w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><\/figure>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-cc2011ff07837733efdc6c4835660bfe\">In a more general term, we can describe the steps involved solving any problem in the following steps:<\/p>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li class=\"has-medium-font-size\"><strong>We have a certain input data.<\/strong><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>We are looking for a certain outcome or output.<\/strong><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>We have a rough idea of the steps in involved in getting to the desired output from the given input.<\/strong><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>We then write the detailed steps involved and get the computer to solve it for us.<\/strong><\/li>\n<\/ol>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-1e442d519a445fd1f584a486c2ed5818\">In the case of recognition of the handwritten digits, one approach is to figure out the underlying pattern of these digits. For example, the digit 1 comprises of one straight line and 4 has three straight lines arranged vertically and horizontally, 8 has two circles and so on so forth. Can we therefore develop our programme to recognise these patterns and therefore the underlying numbers? But the problem is that the handwritten digits vary widely between individuals. And writing a program to decode all the patterns is nearly impossible. And this approach has been tried and it is very error prone, meaning the number of times the program is able to correctly decode the handwritten digits is very low.<\/p>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-advanced-heading uagb-block-91c701a8\"><h2 class=\"uagb-heading-text\"><strong>What then is the solution?<\/strong><\/h2><\/div>\n\n\n\n<div style=\"height:14px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-1aafbed3de338868b43b70a815ec4580\">Instead of us trying to figure out the intricate patterns and updating the program whenever a new data \/ pattern comes along, why not let the machine learn the pattern from the data and come with a way to recognise the digits? We will outline below a method to solve this problem through machine learning.<\/p>\n\n\n\n<div style=\"height:34px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-advanced-heading uagb-block-3d86cb03\"><h2 class=\"uagb-heading-text\">Essential steps to solving a problem through ML<\/h2><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-e08032fe73b9c88eb203eff7c6e2d58b\">The general approach to solving a problem through ML comprises of the following steps: <\/p>\n\n\n\n<div style=\"height:36px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ol class=\"wp-block-list\">\n<li class=\"has-medium-font-size\"><strong>Data preparation<\/strong><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Split the data into Training set and Test Set<\/strong><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Choose a model for learning from the training set.<\/strong><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Validate the model\u2019s efficacy through test set.<\/strong><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>If the model performs well on the test set, then go live. Else, iterate through steps 3 to 5.<\/strong><\/li>\n<\/ol>\n\n\n\n<div style=\"height:36px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Data Preparation for recognition of digits<\/strong><\/h2>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-61e74876b6e6cba960087f11b22894af\">As a first step to developing a solution for recognition of the digits, we need to translate the digits into a machine-readable format. Just uploading the handwritten digits as an image, for example won&#8217;t work. We have to break up the images into small pixels and each pixel must carry the information on the colour of the pixel. Let us consider a pixel frame of 28 x 28 = 784 pixels. The colour of each pixel is represented by an 8-bit number. Each pixel value denotes the colour in greyscale. Zero means black and 255 denote white. Each digit is an array of 784 numbers with each number holding the information on which pixel is black or white or a shade of grey.<\/p>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"931\" height=\"187\" src=\"https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/Digits-in-pixel-format.jpg\" alt=\"\" class=\"wp-image-1724\" srcset=\"https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/Digits-in-pixel-format.jpg 931w, https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/Digits-in-pixel-format-300x60.jpg 300w, https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/Digits-in-pixel-format-768x154.jpg 768w\" sizes=\"(max-width: 931px) 100vw, 931px\" \/><\/figure>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1016\" height=\"776\" src=\"https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/image.png\" alt=\"\" class=\"wp-image-1725\" srcset=\"https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/image.png 1016w, https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/image-300x229.png 300w, https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/image-768x587.png 768w\" sizes=\"(max-width: 1016px) 100vw, 1016px\" \/><\/figure>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-caa4b5bbd1e376d3b221cf23df0b3eb4\">We now have the handwritten digits in the form of an array of 784 (bytes) numbers. We also need to let the machine know what digit each pixel map corresponds to. Each pixel-encoded image map has been assigned a assigned a label by a human. We will set this up in a table &#8211; where each row contains a labelled digit and its pixel-encoded image map. So, let us say we create a table of 60,000 handwritten numbers in the pixel format and their corresponding labels (digits), we then have a way of training the ML model. We need not create this table ourselves. There is a ready database available from MNIST. The MNIST database (Modified National Institute of Standards and Technology database) is a large collection of handwritten digits. It has a training set of 60,000 examples, and a test set of 10,000 examples. (Data in the Training set is used to learn the parameters of the model whereas the test set data is used to measure the efficacy of the model.)<\/p>\n\n\n\n<div style=\"height:34px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-black-color has-text-color has-link-color wp-elements-b0fabed417a81d07905f6970e801ef02\"><strong>Model selection<\/strong><\/h2>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-c59bef9907b7bf11c1878d6b2a084928\">The problem we are trying to solve here, is a multi-level classification problem. From the given input, we need to predict what number \/ digit that it is most likely to be.<\/p>\n\n\n\n<div style=\"height:17px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-50f0b814be6ff14de13a076e6fdb40ec\">Now let us say, we are given a handwritten digit and we have to pick a number from 0-9 that it represents. &nbsp;We have to compare the pixel map of the input digit with each and every entry in our training set and figure out to what entry that it is closest to. There are several algorithms to figure out how we compute the closeness of the given image with the image map of the numbers in the training set. The simplest being Euclidian distance. For example, if you plot two points (x1, y1) and (x2,y2), in a two-dimensional (x,y) plane, distance is simply the square-root of the two sides of the triangle. &nbsp;Similarly, we can use Euclidian distance as a measure of how similar two pixel images are or how dissimilar they are to each other.<\/p>\n\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-bf2768cd4681040056210468a0b8547a\">We have to compare the bit-map of the given input digit with all the pixels in the training set. Pixel by pixel, we will measure the square of the differences between the given number and the zeroth entry in the training set over all the 784 pixels of the two numbers. We then repeat the exercise for the 60,000 entries in the training set. The one digit from the training set for which the square of the error is least, is the digit that the input digit is closest to. Once we arrive at an image map which is closest to the new image for which we have to make a prediction, we just pick the digit associated with that entry in the training set and that is the predicted digit.<\/p>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-fb54f309fd8ec821bf3c08216270528b\">Once we have picked a digit from the training set that is closes to the new image for which we have to make a prediction, we can say with reasonable confidence that the new image that has been presented to us corresponds to that number from the training set.<\/p>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-black-color has-text-color has-link-color wp-elements-3538661bcbe8d1050da7a75a40f3d3a3\"><strong>Measuring the Performance of the model with the test set data<\/strong><\/h2>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-79929a159a4995a09bc16d4561cd457f\">Before we go live with model and use it to make predictions, we have to test its efficacy. That is where the role of test set comes in. The data in the test set is not present in the training set and model has not seen it before. We can therefore use the test set data to see how the model performs against it. For each and every prediction the model makes against the test set, we compute the error. Let us say the actual digit is 5 and the model says that it is 0, then the error is square of the difference. If the predicted value is correct, then there is zero error. For the test data, we can compute the squared error for all the predictions. We have to tweak the prediction algorithms such that we achieve the least error. For example, instead of basing our decision on the closest one number, we may look at closest 5 numbers and pick a number based on maximum number of occurrences out of 5. We can also use more sophisticated measures of distance measurement. Once the model performs well against the test set, we can then go live.<\/p>\n\n\n\n<div style=\"height:36px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-black-color has-text-color has-link-color wp-elements-393648a4c0ea1106d78e71a714dba824\">Summary<\/h2>\n\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-8f5ece36eeb3fa8a43b0827e8044e3af\">In this writeup, we have looked at a simple ML model to solve a multi-level classification problem where the output is a discrete variable. Where the prediction we have to make is a continuous variable, the class of problems are solved through regression. Sometimes, we have to predict the probability of occurrence of an event and not its value. All these problems also have one thing in common and in that, they are all supervised learning problems where the input data contains the labelled outcome for the features. The ML models learn the parameters of the model from the given outcomes and minimises the loss or error. In unsupervised learning, there is no output variable. What we try to do here is to see the common patterns and structures based on which we can group the data into clusters. That concludes our blog on Introduction to Machine Learning.<\/p>\n\n\n\n<div style=\"height:36px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color has-medium-font-size wp-elements-faf11da56a0e2535d8cc6202006803ed\">For comments and feedback, write to Madan Mohan Raj, &nbsp;<a href=\"mailto:athimoolam.madan@gmail.com\">athimoolam.madan@gmail.com<\/a>, Partner, Centre for Executive Learning. <a href=\"https:\/\/execedonline.co.in\/\">https:\/\/execedonline.co.in\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In today&#8217;s data driven world, ML algorithms are at work at all times, when we go about our daily lives. Whenever we make a CC transaction there is a ML algorithm that looks at it see if it is a legitimate transaction or a fraudulent one, when you are browsing for a book or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1727,"comment_status":"open","ping_status":"open","sticky":false,"template":"elementor_theme","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1722","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"uagb_featured_image_src":{"full":["https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/ai-generated-7977128_1280.png",1280,1280,false],"thumbnail":["https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/ai-generated-7977128_1280-150x150.png",150,150,true],"medium":["https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/ai-generated-7977128_1280-300x300.png",300,300,true],"medium_large":["https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/ai-generated-7977128_1280-768x768.png",768,768,true],"large":["https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/ai-generated-7977128_1280-1024x1024.png",1024,1024,true],"1536x1536":["https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/ai-generated-7977128_1280.png",1280,1280,false],"2048x2048":["https:\/\/execedonline.co.in\/wp-content\/uploads\/2024\/05\/ai-generated-7977128_1280.png",1280,1280,false]},"uagb_author_info":{"display_name":"Madan Mohan Raj","author_link":"https:\/\/execedonline.co.in\/index.php\/author\/athimoolam-madan\/"},"uagb_comment_info":17,"uagb_excerpt":"Introduction In today&#8217;s data driven world, ML algorithms are at work at all times, when we go about our daily lives. Whenever we make a CC transaction there is a ML algorithm that looks at it see if it is a legitimate transaction or a fraudulent one, when you are browsing for a book or&hellip;","_links":{"self":[{"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/posts\/1722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/comments?post=1722"}],"version-history":[{"count":12,"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/posts\/1722\/revisions"}],"predecessor-version":[{"id":1746,"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/posts\/1722\/revisions\/1746"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/media\/1727"}],"wp:attachment":[{"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/media?parent=1722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/categories?post=1722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/execedonline.co.in\/index.php\/wp-json\/wp\/v2\/tags?post=1722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}