measuring the clustering performance the real world data is not naturally organized into number of distinctive clusters due to this reasonit is not easy to visualize and draw inferences that is why we need to measure the clustering performance as well as its quality it can be done with the help of silhouette analysis silhouette analysis this method can be used to check the quality of clustering by measuring the distance between the clusters basicallyit provides way to assess the parameters like number of clusters by giving silhouette score this score is metric that measures how close each point in one cluster is to the points in the neighboring clusters analysis of silhouette score the score has range of [- following is the analysis of this scorescore of + score near + indicates that the sample is far away from the neighboring cluster score of score indicates that the sample is on or very close to the decision boundary between two neighboring clusters score of - negative score indicates that the samples have been assigned to the wrong clusters calculating silhouette score in this sectionwe will learn how to calculate the silhouette score silhouette score can be calculated by using the following formulasilhouette score ( )/max(pqherep is the mean distance to the points in the nearest cluster that the data point is not part of andq is the mean intra-cluster distance to all the points in its own cluster for finding the optimal number of clusterswe need to run the clustering algorithm again by importing the metrics module from the sklearn package in the following examplewe will run the -means clustering algorithm to find the optimal number of clustersimport the necessary packages as shownimport matplotlib pyplot as plt import seaborn as snssns set(import numpy as np from sklearn cluster import kmeans with the help of the following codewe will generate the two-dimensional datasetcontaining four blobsby using make_blob from the sklearn dataset package