# k-means Clustering

The k-means algorithm, a straightforward and widely used clustering algorithm. Given a set of objects (records), the goal of clustering or segmentation is to divide these objects into groups or “clusters” such that objects within a group tend to be more similar to one another as compared to objects belonging to different groups. In other words, clustering algorithms place similar points in the same cluster while placing dissimilar points in different clusters.Note that,in contrast to supervised tasks such as regression or classiﬁcation where there is a notion of a target value or class label, the objects that form the inputs to a clustering procedure do not come with an associated target. Therefore, clustering is often referred to as unsupervised learning. Because there is no need for labeled data, unsupervised algorithms are suitable for many applications where labeled data is difﬁcult to obtain. Unsupervised tasks such as clustering are also often used to explore and characterize the dataset before running a supervised learning task. Since clustering makes no use of class labels, some notion of similarity must be deﬁned based on the attributes of the objects. The deﬁnition of similarity and the method in which points are clustered differ based on the clustering algorithm being applied. Thus, different clustering algorithms are suited to different types of datasets and different purposes. The “best” clustering algorithm to use therefore depends on the application. It is not uncommon to try several different algorithms and choose depending on which is the most useful.

`   1: Input: Dataset D, number clusters k`

`   2: Output: Set of cluster representatives C, cluster membership vector m`

`   3:     /* Initialize cluster representatives C */`

`   4:     Randomly choose k data points from D`

`   5: 5: Use these k points as initial set of cluster representatives C`

`   6:     repeat`

`   7:         /* Data Assignment */`

`   8:         Reassign points in D to closest cluster mean`

`   9:         Update m such that mi is cluster ID of ith point in D`

`  10: 10: /* Relocation of means */`

`  11:         Update C such that cj is mean of points in jth cluster`

`  12: until convergence of objective function summation(i=1 to N)(argminj||xi −cj||2 2)`
{"ft_lang_label":"__label__en","ft_lang_prob":0.91601753,"math_prob":0.80279994,"size":2180,"snap":"2020-34-2020-40","text_gpt3_token_len":451,"char_repetition_ratio":0.15487133,"word_repetition_ratio":0.0,"special_character_ratio":0.20321101,"punctuation_ratio":0.09848485,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9506932,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-08-05T10:08:56Z\",\"WARC-Record-ID\":\"<urn:uuid:444cb542-7b9d-4ed4-908c-fd15b40b49b5>\",\"Content-Length\":\"96125\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e2da7cd6-1b96-40ea-8b3d-c7d07467504a>\",\"WARC-Concurrent-To\":\"<urn:uuid:9f10c52a-36be-44f8-bd90-f6e9fe1ef361>\",\"WARC-IP-Address\":\"192.0.78.13\",\"WARC-Target-URI\":\"https://speedestchandu.wordpress.com/2014/02/22/k-means-clustering/\",\"WARC-Payload-Digest\":\"sha1:BM56NG6KPITTHVP7AMI6SF47S6TJSPYU\",\"WARC-Block-Digest\":\"sha1:ETI3SQUBZ5JLYMN5JVQFNHDKXCFLTWY5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-34/CC-MAIN-2020-34_segments_1596439735939.26_warc_CC-MAIN-20200805094821-20200805124821-00509.warc.gz\"}"}