 Open in App
Not now

# Silhouette Algorithm to determine the optimal value of k

• Last Updated : 06 Jun, 2019

One of the fundamental steps of an unsupervised learning algorithm is to determine the number of clusters into which the data may be divided. The silhouette algorithm is one of the many algorithms to determine the optimal number of clusters for an unsupervised learning technique.

In the Silhouette algorithm, we assume that the data has already been clustered into k clusters by a clustering technique(Typically K-Means Clustering technique). Then for each data point, we define the following:-

C(i) -The cluster assigned to the ith data point

|C(i)| – The number of data points in the cluster assigned to the ith data point

a(i) – It gives a measure of how well assigned the ith data point is to it’s cluster b(i) – It is defined as the average dissimilarity to the closest cluster which is not it’s cluster The silhouette coefficient s(i) is given by:- We determine the average silhouette for each value of k and for the value of k which has the maximum value of s(i) is considered the optimal number of clusters for the unsupervised learning algorithm.

Let us consider the following data:-

S.NoX1X2
1.-7.366.37
2.3.08-6.78
3.5.03-8.31
4.-1.93-0.92
5.-8.866.60

We now iterate the values of k from 2 to 5. We assume that no practical data exists for which all the data points can be optimally clustered into 1 cluster.

We construct the following tables for each value of k:-

k = 2

S.Noa(i)b(i)s(i)
1.5.3114.10.62
2.2.4713.150.81
3.2.4714.970.84
4.9.668.93-0.076
5.5.8819.160.69

Average value of s(i) = 0.58

k = 3

S.Noa(i)b(i)s(i)
1.1.529.090.83
2.2.477.710.68
3.2.4710.150.76
4.07.711
5.1.5217.930.92

Average value of s(i) = 0.84

k = 4

S.Noa(i)b(i)s(i)
1.1.529.090.83
2.infinite2.470
3.infinite2.470
4.infinite7.710
5.1.5210.230.85

Average value of s(i) = 0.37

k = 5

S.Noa(i)b(i)s(i)
1.infinite1.520
2.infinite2.470
3.infinite2.470
4.infinite7.710
5.infinite1.520

Average value of s(i) = 0 We see that the highest value of s(i) exists for k = 3. Therefore we conclude that the optimal number of clusters for the given data is 3.

My Personal Notes arrow_drop_up