# Understanding Clustering

## Importance of Clustering :

Clustering is the process of grouping data items that are “similar” between them, and “dissimilar” to data items in other clusters.

Clustering separates datasets into many clusters of similar ones and finding out grouping in data automatically.

So, the main purpose of clustering is to separate groups with similar behaviors and combine them together into diverse clusters.

It is very challenging for a machine to recognize from an orange or an apple unless as it should be trained on a huge amount of relevant dataset. This training is done by using unsupervised machine learning algorithms, such as clustering.

For example, all the data points gathered together can be observed as one cluster or a group.

## Clustering Techniques :

In order to understand and analyze the patterns or characteristics of a huge dataset, we first split the data into reasonable groups.

Using this method, you can take out values from a big set of unstructured data. It assists you to look from end to end at the data to understand patterns before moving into data exploration.

We arrange data into clusters, which helps in recognizing the underlying patterns or structure in the data and discovers applications across trades.

Clustering can be used to categorize disease in the medical science domain, and can also be implemented for customer segmentation in retail.

Types of techniques :

1. K-means clustering

2. Hierarchical Clustering

3. Density-Based Clustering

4. Mean-shift clustering

## K-Means Clustering Algorithm:

Clustering algorithms learn from the characteristics of the data, an optimal division, or discrete labeling of groups of points. There are many clustering algorithms available in the scikit-learn library and elsewhere online, but perhaps the simplest algorithm to understand is an algorithm known as the k-means clustering algorithm, which is implemented in sklearn.cluster.KMeans.

The k-means algorithm finds a pre-determined (k) number of clusters within an unlabeled multidimensional dataset. It completes this using a simple conception of what the optimal clustering looks like:

In k-means, the cluster center is the mean of all the data points belonging to a particular cluster.

Each data point is closer to its own cluster center than to other cluster centers and there should be more inter-cluster distance between two clusters.

The expectation-maximization approach here consists of the following procedure:

• Guess some cluster centers
• Repeat until converged
• E-Step: assign points to the nearest cluster center
• M-Step: set the cluster centers to the mean

Here the “E-step” or “Expectation step” is so named because it involves updating our expectation of which cluster each point belongs to.

The “M-step” or “Maximization step” is so named because it involves maximizing some fitness function that defines the location of the cluster centers — in this case, that maximization is accomplished by taking a simple mean of the data in each cluster.

## Centroid-based Clustering — (Centers are Centroids)

The intuition behind centroid-based clustering is that a cluster is characterized and represented by a central vector which is called a centroid of all data points in that cluster and data points that are in close proximity to these vectors are assigned to the respective clusters.

These clustering methods iteratively measure the distance between the clusters and the centroids using various distance metrics such as Euclidian distance, Manhattan Distance or Minkowski Distance.

The major disadvantage here is that we should either heuristically or practically (Elbow Method) define the number of clusters, “k”, to begin the iteration of any clustering machine learning algorithm to start assigning the data points to the cluster.

## Hierarchical-based Clustering

Normally, hierarchical-based clustering is used on hierarchical data, like you will be provided a database from a company. It builds up a tree of clusters, so everything is structured from the top to down. Hierarchical-based clustering is more preventive than the other clustering categories, but it is quite good for particular types of datasets.

Hierarchical clustering combines or collects similar data points into a cluster or group based on distance metric where each following cluster is shaped centered on the earlier cluster. The outcome is a set of clusters, where each cluster is different from the other, also the patterns inside each cluster are mostly similar to each other.

## i) Agglomerative

Agglomerative is a bottom-up methodology. In this method, We assign each point to an individual cluster in this technique. Suppose there are 4 data points. We will assign each of these points to a cluster and hence will have 4 clusters in the beginning and couples of clusters are combined as one moves up the hierarchy.

At each iteration, we combine the closest pair of clusters and repeat this step until only a single cluster is left which encompasses all the data points from all clusters.

This kind of clustering is known as additive hierarchical clustering.

## ii) Divisive

Top-Down Approach is also known as DIANA (Divisive Analysis) is the opposite of agglomerative clustering.

Divisive hierarchical clustering works in the opposite way to the agglomerative way. Instead of starting with n clusters, we start with a single cluster and assign all the points to that cluster. So, it doesn’t matter if we have few or many data points. All these points will belong to the same cluster at the start of the process.

## Density-Based Spatial Clustering of Applications with Noise (DBSCAN) :

Density-based clustering methods consider density instead of distances. Clusters are considered as the highly dense region in a data space, which is separated by regions of lower object density and it is defined as a maximal set of connected points.

It is used to connect areas that have high density into clusters.

In the density-based clustering method, data is grouped by zones of high dense data points enclosed by zones of low dense data points. The algorithm finds the areas that are highly dense with data points and states them clusters.

The algorithm selects a random starting position and, using a distance epsilon, the neighborhood to this position is extracted.

All the positions that are inside the distance epsilon are the neighborhood positions. If these positions are enough in number, then the clustering procedure begins and we gain the first cluster. If there are not sufficient neighboring data positions, then the first position is tagged as noise.

For each position in this first cluster, the neighboring data positions are also included in a similar cluster. This practice is recurrent for each position in the cluster till there are no more data positions that can be included.

As soon as we are completed with the present cluster, an unvisited position is picked as the first data position of the next cluster and all neighboring positions are categorized into that cluster. This method is repeated up until all positions are expressed as visited.

## Distribution-based Clustering

With a distribution-based clustering method, all of the data points are measured shares of a cluster built on the possibility that they fit into an assumed cluster. There is a mid-point, and as the range of a data point grows from the center, the chance of it being a part lessens of that cluster.

Distribution-based clustering algorithms make use of different metrics considerations such as probability. Distribution-based clustering creates and groups data points based on their likely hood of belonging to the same probability distribution in the data.

Data science trainee at Almabetter

## More from Sriram Chunduri

Data science trainee at Almabetter