{"id":175,"date":"2018-01-21T18:39:00","date_gmt":"2018-01-21T17:39:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2018\/01\/21\/understanding-clustering-k-means-in-machine-learning-unsupervised-learning\/"},"modified":"2020-08-22T09:21:36","modified_gmt":"2020-08-22T07:21:36","slug":"understanding-clustering-k-means-in-machine-learning-unsupervised-learning","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/understanding-clustering-k-means-in-machine-learning-unsupervised-learning\/","title":{"rendered":"Understanding Clustering (k-Means) in Machine Learning (Unsupervised Learning)"},"content":{"rendered":"<div style=\"color: #555555; font-size: 18px; line-height: 30px; text-align: justify;\">\n<div style=\"font-family: 'segoe ui';\">In this lesson we are going discuss clustering under the following topic:<\/p>\n<ol>\n<li><span style=\"color: #990000;\">Introduction to Clustering<\/span><\/li>\n<p><span style=\"color: #990000;\"><\/span><\/p>\n<li><span style=\"color: #990000;\">Formalized Definition of k-Means Clustering<\/span><\/li>\n<p><span style=\"color: #990000;\"><\/span><\/p>\n<li><span style=\"color: #990000;\">1-of-K Coding Scheme<\/span><\/li>\n<p><span style=\"color: #990000;\"><\/span><\/p>\n<li><span style=\"color: #990000;\">The Expectation and Maximization Algorithm&nbsp; <\/span><\/li>\n<\/ol>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/3.bp.blogspot.com\/-7Xf3GCijblY\/WmTeHDToo_I\/AAAAAAAAA4w\/a2kRC1U0SCkEwjQMWp3Kuj0r6nzytkv5wCLcBGAs\/s1600\/Clustering%2528k-means%2Bin%2BMachine%2BLearning%2529.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"626\" data-original-width=\"1285\" height=\"155\" src=\"https:\/\/3.bp.blogspot.com\/-7Xf3GCijblY\/WmTeHDToo_I\/AAAAAAAAA4w\/a2kRC1U0SCkEwjQMWp3Kuj0r6nzytkv5wCLcBGAs\/s320\/Clustering%2528k-means%2Bin%2BMachine%2BLearning%2529.jpg\" width=\"320\" \/><\/a><\/div>\n<p><b>Introduction to Clustering<\/b><br \/>Clustering is a class of unsupervised learning concept or machine learning whose goal is to identify groups or clusters within datapoints in a multi-dimensional space.<br \/>Suppose we have data sets <span style=\"color: black;\"><i>{x<sub>1<\/sub>, x<sub>2<\/sub>, &#8230;, x<sub>n<\/sub>}<\/i><\/span> consisting of N observations of a random D-dimensional Euclidean variable x. The goal is to partition the data into K clusters when the value of K is preknown.<br \/>We can define a cluster as a group of data points whose inter-point distances are minimal compared with the distance with points that are outside the cluster.<\/p>\n<p><b>Formalization of k-Means Clustering<\/b><br \/>Let&#8217;s assume a set of D-dimensional vectors&nbsp;   \u03bc<sub>k<\/sub> where k = 1, 2, &#8230;, K and  <span style=\"color: black;\">\u03bc<sub>k<\/sub> <\/span>represents the centroid of the cluster k. Take centroid to be the mean of data points in the cluster.<br \/>Our goal is to find the assignment&nbsp; of data points to clusters as well as a set of vectors <span style=\"color: black;\">{ \u03bc<sub>k<\/sub>}<\/span> such that the sum of squares of distances of each data point to its closest vector&nbsp; \u03bc<sub>k<\/sub>&nbsp; is at a minimum.<\/p>\n<p><b>1-of-K Coding Scheme<\/b><br \/>The 1-of-k Coding Scheme is a coding scheme applied to a K-dimensional vector x in which one of the elements x<sub>k<\/sub> equals 1 and all the remaining elements 0. This means that a data point cannot belong to two clusters at the same time.<\/p>\n<p>In this case, for each data point x, we introduce a corresponding set of binary indicator variables<span style=\"color: black;\"><span style=\"font-family: &quot;times&quot; , &quot;times new roman&quot; , serif;\"><i> r<sub>nk<\/sub> \u2208 {0,1}.<\/i><\/span><\/span><br \/>If x<sub>n<\/sub> is assigned to \u03bc<sub>k<\/sub> then<i><span style=\"font-family: &quot;times&quot; , &quot;times new roman&quot; , serif;\"> r<sub>nk<\/sub> = 1<\/span><\/i> and r<sub>nj<\/sub> = 0 for j \u2260 k<br \/>We can then define an objective function J know as distortion measure<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/1.bp.blogspot.com\/-QbfsdR34CXQ\/WmS1acOJiuI\/AAAAAAAAA4g\/FbZWR86wLbgKbCic76PxhctHRo682IElwCLcBGAs\/s1600\/Distortion%2BMeasure%2528objective%2Bfunction%2529.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" data-original-height=\"215\" data-original-width=\"874\" height=\"78\" src=\"https:\/\/1.bp.blogspot.com\/-QbfsdR34CXQ\/WmS1acOJiuI\/AAAAAAAAA4g\/FbZWR86wLbgKbCic76PxhctHRo682IElwCLcBGAs\/s320\/Distortion%2BMeasure%2528objective%2Bfunction%2529.jpg\" width=\"320\" \/><\/a><\/div>\n<p>This represents the sum of the squares of the distances of each of the data points from its assigned vector <span style=\"color: black;\">\u03bc<sub>k<\/sub><\/span><br \/>&nbsp;The goal is to choose values for <span style=\"color: black;\">{r<sub>nk<\/sub>}<\/span> and <span style=\"color: black;\">{\u03bc<sub>k<\/sub>}<\/span> so as to minimize J. This brings us to the next section where we would examine the algorithm.<\/p>\n<p><b>The Expectation and Maximization Algorithm(k-Means)<\/b><br \/>&nbsp;The algorithm is an iterative algorithm where for each iteration, two steps are taken that optimizes the variables<i><span style=\"font-family: &quot;times&quot; , &quot;times new roman&quot; , serif;\"><span style=\"color: black;\"> r<sub>nk<\/sub> <\/span><\/span><\/i>and \u03bc<sub>k<\/sub><\/p>\n<p><span style=\"color: black;\"><i>The algorithm goes this way. <\/i><\/span><br \/>First, choose an initial value for \u03bc<sub>k<\/sub>&nbsp; <br \/>In the first phase: we minimize J with respect to <i><span style=\"color: black;\">r<sub>nk<\/sub><\/span><\/i> while keeping <i><span style=\"color: black;\">\u03bc<sub>k<\/sub><\/span><\/i> fixed.<br \/>In the second phase, we minimize J with respect to \u03bc<sub>k<\/sub>&nbsp; while keeping <i><span style=\"color: black;\">r<sub>nk<\/sub><\/span><\/i>&nbsp; fixed.<br \/>Repeat the two steps until convergence.<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this lesson we are going discuss clustering under the following topic: Introduction to Clustering Formalized Definition of k-Means Clustering 1-of-K Coding Scheme The Expectation &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[15,11,16],"tags":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/175"}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=175"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/175\/revisions"}],"predecessor-version":[{"id":1440,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/175\/revisions\/1440"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}