{"id":136305,"date":"2024-09-20T10:59:17","date_gmt":"2024-09-20T05:29:17","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?page_id=136305"},"modified":"2024-09-20T10:59:18","modified_gmt":"2024-09-20T05:29:18","slug":"step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/","title":{"rendered":"Step-by-step walkthrough of the K-Means clustering algorithm (Legacy)"},"content":{"rendered":"\n<p>The K-means clustering algorithm is a popular unsupervised learning technique used to partition a dataset into K distinct clusters. This guide will provide a step-by-step walkthrough of the K-means algorithm, focusing on its traditional implementation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Initialization<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Choose the value of K:<\/strong> Determine the number of clusters you want to create. This is a crucial step as the choice of K can significantly impact the clustering results.<\/li>\n\n\n\n<li><strong>Randomly initialize centroids:<\/strong> Select K data points from the dataset at random to serve as the initial centroids for each cluster.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Assignment<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Calculate distances:<\/strong> For each data point, compute its Euclidean distance to each centroid.<\/li>\n\n\n\n<li><strong>Assign to nearest centroid:<\/strong> Assign each data point to the cluster whose centroid is closest to it.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Update<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Recalculate centroids:<\/strong> For each cluster, calculate the new centroid as the mean of all data points assigned to that cluster.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Repeat<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Iterate:<\/strong> Repeat steps 2 and 3 until the centroids converge or a maximum number of iterations is reached. Convergence occurs when the centroids no longer change significantly between iterations.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<p>Consider a dataset of two-dimensional points:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Data points: (2, 3), (4, 5), (6, 7), (8, 9), (1, 2)\nK = 2\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Initialization:<\/strong> Randomly select two data points as initial centroids: (2, 3) and (8, 9).<\/li>\n\n\n\n<li><strong>Assignment:<\/strong>\n<ul class=\"wp-block-list\">\n<li>(2, 3) is closer to (2, 3) than (8, 9), so it is assigned to cluster 1.<\/li>\n\n\n\n<li>(4, 5) is closer to (2, 3) than (8, 9), so it is assigned to cluster 1.<\/li>\n\n\n\n<li>(6, 7) is closer to (8, 9) than (2, 3), so it is assigned to cluster 2.<\/li>\n\n\n\n<li>(8, 9) is closer to (8, 9) than (2, 3), so it is assigned to cluster 2.<\/li>\n\n\n\n<li>(1, 2) is closer to (2, 3) than (8, 9), so it is assigned to cluster 1.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Update:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Centroid of cluster 1: (2 + 4 + 1) \/ 3 = 2.33, (3 + 5 + 2) \/ 3 = 3.33<\/li>\n\n\n\n<li>Centroid of cluster 2: (6 + 8) \/ 2 = 7, (7 + 9) \/ 2 = 8<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Repeat:<\/strong> Continue iterating steps 2 and 3 until convergence or a maximum number of iterations is reached.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Limitations and Considerations<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Sensitivity to initialization:<\/strong> The initial centroids can significantly affect the final clustering results.<\/li>\n\n\n\n<li><strong>Assumption of spherical clusters:<\/strong> K-means assumes that clusters are spherical and of similar size.<\/li>\n\n\n\n<li><strong>Scalability:<\/strong> K-means can be computationally expensive for large datasets.<\/li>\n<\/ul>\n\n\n\n<p>To address these limitations, various modifications and extensions of the K-means algorithm have been proposed, such as K-means++, hierarchical K-means, and fuzzy c-means.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The K-means clustering algorithm is a popular unsupervised learning technique used to partition a dataset into K distinct clusters. This guide will provide a step-by-step walkthrough of the K-means algorithm, focusing on its traditional implementation. Initialization Assignment Update Repeat Example Consider a dataset of two-dimensional points: Limitations and Considerations To address these limitations, various modifications&#8230;<\/p>\n","protected":false},"author":16,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-136305","page","type-page","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Step-by-step walkthrough of the K-Means clustering algorithm (Legacy) - Tutorial<\/title>\n<meta name=\"description\" content=\"Follow this step-by-step walkthrough of the legacy K-Means clustering algorithm. Understand how this classic method groups data points.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Step-by-step walkthrough of the K-Means clustering algorithm (Legacy) - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Follow this step-by-step walkthrough of the legacy K-Means clustering algorithm. Understand how this classic method groups data points.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-20T05:29:18+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/\",\"name\":\"Step-by-step walkthrough of the K-Means clustering algorithm (Legacy) - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2024-09-20T05:29:17+00:00\",\"dateModified\":\"2024-09-20T05:29:18+00:00\",\"description\":\"Follow this step-by-step walkthrough of the legacy K-Means clustering algorithm. Understand how this classic method groups data points.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Step-by-step walkthrough of the K-Means clustering algorithm (Legacy)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Step-by-step walkthrough of the K-Means clustering algorithm (Legacy) - Tutorial","description":"Follow this step-by-step walkthrough of the legacy K-Means clustering algorithm. Understand how this classic method groups data points.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/","og_locale":"en_US","og_type":"article","og_title":"Step-by-step walkthrough of the K-Means clustering algorithm (Legacy) - Tutorial","og_description":"Follow this step-by-step walkthrough of the legacy K-Means clustering algorithm. Understand how this classic method groups data points.","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-09-20T05:29:18+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/","name":"Step-by-step walkthrough of the K-Means clustering algorithm (Legacy) - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2024-09-20T05:29:17+00:00","dateModified":"2024-09-20T05:29:18+00:00","description":"Follow this step-by-step walkthrough of the legacy K-Means clustering algorithm. Understand how this classic method groups data points.","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/step-by-step-walkthrough-of-the-k-means-clustering-algorithm-legacy\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Step-by-step walkthrough of the K-Means clustering algorithm (Legacy)"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=136305"}],"version-history":[{"count":1,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136305\/revisions"}],"predecessor-version":[{"id":136308,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136305\/revisions\/136308"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=136305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=136305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=136305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}