SciPy – Cluster
Clustering is nothing but it is the procedure of dividing the datasets into groups consisting of similar data points. In this procedure, the data points in the same group must be identical as possible and should be different from the other groups.
Types of SciPy – Cluster:
There are two types of Cluster:
- K-Means Clustering
- Hierarchical Clustering
To solve clustering problems in machine learning or data science an unsupervised algorithm is used that is the K-Means Clustering algorithm. This algorithm groups the unlabeled dataset into different clusters. Here K is the number of pre-defined clusters which is needed to be created in the process. In this algorithm, each cluster is associated with a centroid that’s why? It is also known as a centroid-based algorithm.
Working of K-Means Clustering:
Step 1: To decide the number of clusters first choose the number K.
Step 2: Consider random K points( also known as centroids).
Step 3: To form the predefined K clusters assign each data point to its closest centroid.
Step 4: Now find the mean and put a new centroid of each cluster.
Step 5: Reassign each datapoint to the new closest centroid of each cluster.
Step 6: If there comes any reassignment, then repeat step 4.
Now we will see this algorithm in action by using the SciPy module implementation for the k-means clustering algorithm.
Now, we will make an object of KMeans along with providing a number of clusters after that we can plot and visualize the cluster’s centers picked by k-means.
It is another unsupervised Clustering algorithm that is used to group the unlabeled datasets into a cluster. The hierarchical Clustering algorithm develops the hierarchy of clusters in the form of a tree. This hierarchy of clusters which is in the form of a tree-shaped structure is known as the dendrogram.
Now let’s look at the code to implement the hierarchical clustering using the SciPy module.
Hierarchical clustering has two types:
- Agglomerative Hierarchical clustering
- Divisive Hierarchical clustering
Agglomerative Hierarchical clustering:
In the hierarchical clustering algorithm, we don’t have required a predefined number of clusters, it follows the bottom-up approach to group the datasets into clusters. This algorithm considers each dataset as a single cluster at the beginning and then starts combining the closest pair of clusters together. This process is continued until all the clusters are merged into a single cluster.
Working of the Agglomerative Hierarchical clustering:
Step 1: Consider each data point as a single cluster. For example, suppose the number of data points is N so the number of clusters will also be N.
Step 2: Choose the two closest data points or clusters and merge them to make one cluster. Hence, now there will be N-1 clusters.
Step 3: Repeat Step 2, until only one cluster is left.
Step 4: When all the clusters will be converted into one big cluster, then develop the dendrogram to divide the clusters as per the problem.
Divisive hierarchical clustering:
The working of Divisive hierarchical clustering is the same as Agglomerative Hierarchical clustering only difference is that it follows the Top-down approach To group the datasets into clusters.
Please Login to comment...