# Cluster Analysis Using K-means Explained

DevFeed: [Cluster Analysis Using K-means Explained](<https://devfeed.tech/articles/cluster-analysis-using-k-means-explained-24974.md>)

Original publisher: [Read original article](<https://codeahoy.com/2017/02/19/cluster-analysis-using-k-means-explained/>)

Author: umer

Published: 2017-02-19T00:00:00Z

Content type: tutorial

Language: en

Sources: [Code Ahoy - Articles](<https://devfeed.tech/sources/code-ahoy-articles.md>)

Topics: [data](<https://devfeed.tech/topics/data.md>), [Machine learning](<https://devfeed.tech/topics/machine-learning.md>), [Algorithm](<https://devfeed.tech/topics/algorithm.md>), [datasets](<https://devfeed.tech/topics/datasets.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [blog-post](<https://devfeed.tech/tags/blog-post.md>), [clustering](<https://devfeed.tech/tags/clustering.md>), [data](<https://devfeed.tech/tags/data.md>), [dataset](<https://devfeed.tech/tags/dataset.md>), [machine-learning](<https://devfeed.tech/tags/machine-learning.md>)

## AI overview

This tutorial explains clustering and k-means, including how k-means assigns data points to clusters, updates cluster centroids, and repeats the process to minimize the total distance within clusters. It also discusses applications and the importance of choosing a clustering method based on requirements and the dataset.

## Source excerpt

Clustering or cluster analysis is the process of dividing data into groups (clusters) in such a way that objects in the same cluster are more similar to each other than those in other clusters. It is used in data mining, machine learning, pattern recognition, data compression and in many other fields. In machine learning, it is often a starting point. In a machine learning application I built couple of years ago, we used clustering to divide six million prepaid subscribers into five clusters and then built a model for each cluster using linear regression. The goal of the application was to predict future recharges by subscribers so operators can make intelligent decisions like whether to grant or deny emergency credit. Another (trivial) application of clustering is for dividing customers into groups based on spending habits or brand loyalty for further analysis or to determine the best promotional strategy. There are various models and techniques for cluster analysis. When I first started, I was mistakenly searching for 'the best clustering model or technique.' I wasn't aware that there is no universal best algorithm and the choice depends on your requirements and the dataset. There are density-based, graph based or centroid based clustering models. We finally settled on a clustering technique called k-means. This blog post is a brain-dump of everything I've learned about clustering and k-means so far. K-means K-means is a very simple and widely used clustering technique. It divides a dataset into 'k' clusters. The 'k' must be supplied by the users, hence the name k-means. It is general purpose and the algorithm is straight-forward: We call the process k-means clustering because we assume that there are k clusters, and each cluster is defined by its center point -- its mean. To find these clusters, we use Lloyd's Algorithm: we start out with k random centroids. A centroid is simply a datapoint around which we form a cluster. For each centroid, we find the datapoints