Silhouette (clustering) explained

Silhouette refers to a method of interpretation and validation of consistency within clusters of data. The technique provides a succinct graphical representation of how well each object has been classified.[1] It was proposed by Belgian statistician Peter Rousseeuw in 1987.

The silhouette value is a measure of how similar an object is to its own cluster (cohesion) compared to other clusters (separation). The silhouette ranges from -1 to +1, where a high value indicates that the object is well matched to its own cluster and poorly matched to neighboring clusters. If most objects have a high value, then the clustering configuration is appropriate. If many points have a low or negative value, then the clustering configuration may have too many or too few clusters. A clustering with an average silhouette width of over 0.7 is considered to be "strong", a value over 0.5 "reasonable" and over 0.25 "weak", but with increasing dimensionality of the data, it becomes difficult to achieve such high values because of the curse of dimensionality, as the distances become more similar. The silhouette score is specialized for measuring cluster quality when the clusters are convex-shaped, and may not perform well if the data clusters have irregular shapes or are of varying sizes.[2] The silhouette can be calculated with any distance metric, such as the Euclidean distance or the Manhattan distance.

Definition

Assume the data have been clustered via any technique, such as k-medoids or k-means, into

k

clusters.

For data point

i\inCI

(data point

i

in the cluster

CI

), let

a(i)=

1
|CI|-1
\sum
j\inCI,ij

d(i,j)

be the mean distance between

i

and all other data points in the same cluster, where

|CI|

is the number of points belonging to cluster

CI

, and

d(i,j)

is the distance between data points

i

and

j

in the cluster

CI

(we divide by

|CI|-1

because we do not include the distance

d(i,i)

in the sum). We can interpret

a(i)

as a measure of how well

i

is assigned to its cluster (the smaller the value, the better the assignment).

We then define the mean dissimilarity of point

i

to some cluster

CJ

as the mean of the distance from

i

to all points in

CJ

(where

CJCI

).

For each data point

i\inCI

, we now define

b(i)=minJ

1
|CJ|
\sum
j\inCJ

d(i,j)

to be the smallest (hence the

min

operator in the formula) mean distance of

i

to all points in any other cluster (i.e., in any cluster of which

i

is not a member). The cluster with this smallest mean dissimilarity is said to be the "neighboring cluster" of

i

because it is the next best fit cluster for point

i

.

We now define a silhouette (value) of one data point

i

s(i)=

b(i)-a(i)
max\{a(i),b(i)\
} , if

|CI|>1

and

s(i)=0

, if

|CI|=1

Which can be also written as:

s(i)=\begin{cases} 1-a(i)/b(i),&ifa(i)<b(i)\\ 0,&ifa(i)=b(i)\\ b(i)/a(i)-1,&ifa(i)>b(i)\\ \end{cases}

From the above definition it is clear that

-1\les(i)\le1

Note that

a(i)

is not clearly defined for clusters with size = 1, in which case we set

s(i)=0

. This choice is arbitrary, but neutral in the sense that it is at the midpoint of the bounds, -1 and 1.[1]

For

s(i)

to be close to 1 we require

a(i)\llb(i)

. As

a(i)

is a measure of how dissimilar

i

is to its own cluster, a small value means it is well matched. Furthermore, a large

b(i)

implies that

i

is badly matched to its neighbouring cluster. Thus an

s(i)

close to 1 means that the data is appropriately clustered. If

s(i)

is close to -1, then by the same logic we see that

i

would be more appropriate if it was clustered in its neighbouring cluster. An

s(i)

near zero means that the datum is on the border of two natural clusters.

The mean

s(i)

over all points of a cluster is a measure of how tightly grouped all the points in the cluster are. Thus the mean

s(i)

over all data of the entire dataset is a measure of how appropriately the data have been clustered. If there are too many or too few clusters, as may occur when a poor choice of

k

is used in the clustering algorithm (e.g., k-means), some of the clusters will typically display much narrower silhouettes than the rest. Thus silhouette plots and means may be used to determine the natural number of clusters within a dataset. One can also increase the likelihood of the silhouette being maximized at the correct number of clusters by re-scaling the data using feature weights that are cluster specific.[3]

Kaufman et al. introduced the term silhouette coefficient for the maximum value of the mean

s(i)

over all data of the entire dataset,[4] i.e.,

SC=maxk\tilde{s}\left(k\right),

where

\tilde{s}\left(k\right)

represents the mean

s(i)

over all data of the entire dataset for a specific number of clusters

k

.

Simplified Silhouette and Medoid Silhouette

Computing the silhouette coefficient needs all

l{O}(N2)

pairwise distances, making this evaluation much more costly than clustering with k-means. For a clustering with centers
\mu
CI
for each cluster

CI

, we can use the following simplified Silhouette for each point

i\inCI

instead, which can be computed using only

l{O}(Nk)

distances:
a'(i)=d(i,\mu
CI

)

and
b'(i)=min
CJCI
d(i,\mu
CJ

)

,which has the additional benefit that

a'(i)

is always defined, then define accordingly the simplified silhouette and simplified silhouette coefficient[5]

s'(i)=

b'(i)-a'(i)
max\{a'(i),b'(i)\
}

SC'=maxk

1N
\sum

is'\left(i\right)

.

If the cluster centers are medoids (as in k-medoids clustering) instead of arithmetic means (as in k-means clustering), this is also called the medoid-based silhouette[6] or medoid silhouette.[7]

If every object is assigned to the nearest medoid (as in k-medoids clustering), we know that

a'(i)\leqb'(i)

, and hence

s'(i)=

b'(i)-a'(i)
b'(i)

=1-

a'(i)
b'(i)

.

Silhouette Clustering

Instead of using the average silhouette to evaluate a clustering obtained from, e.g., k-medoids or k-means, we can try to directly find a solution that maximizes the Silhouette. We do not have a closed form solution to maximize this, but it will usually be best to assign points to the nearest cluster as done by these methods. Van der Laan et al. proposed to adapt the standard algorithm for k-medoids, PAM, for this purpose and call this algorithm PAMSIL:

  1. Choose initial medoids by using PAM
  2. Compute the average silhouette of this initial solution
  3. For each pair of a medoid and a non-medoid
    1. swap and
    2. compute the average silhouette of the resulting solution
    3. remember the best swap
    4. un-swap and for the next iteration
  4. Perform the best swap and return to 3, otherwise stop if no improvement was found.

The loop in step 3 is executed for

l{O}(Nk)

pairs, and involves computing the silhouette in

l{O}(N2)

, hence this algorithm needs

l{O}(N3ki)

time, where is the number of iterations.

Because this is a fairly expensive operation, the authors propose to also use the medoid-based silhouette, and call the resulting algorithm PAMMEDSIL. It needs

l{O}(N2k2i)

time.

Batool et al. propose a similar algorithm under the name OSil, and propose a CLARA-like sampling strategy for larger data sets, that solves the problem only for a sub-sample.[8]

By adopting recent improvements to the PAM algorithm, FastMSC reduces the runtime using the medoid silhouette to just

l{O}(N2i)

.

By starting with a maximum number of clusters and iteratively removing the worst center (in terms of a change in silhouette) and re-optimizing, the best (highest medoid silhouette) clustering can be automatically determined. As data structures can be reused, this reduces the computation cost substantially over repeatedly running the algorithm for different numbers of clusters.[9] This algorithm needs pairwise distances and is typically implemented with a pairwise distance matrix. The

l{O}(N2)

memory requirement is the main limiting factor for applying this to very large data sets.

See also

Notes and References

  1. 10.1016/0377-0427(87)90125-7 . Peter J. Rousseeuw . Peter J. Rousseeuw . Silhouettes: a Graphical Aid to the Interpretation and Validation of Cluster Analysis . Computational and Applied Mathematics . 20 . 53 - 65 . 1987. free .
  2. Monshizadeh . Mehrnoosh . Khatri . Vikramajeet . Kantola . Raimo . Yan . Zheng . 2022-11-01 . A deep density based and self-determining clustering approach to label unknown traffic . Journal of Network and Computer Applications . 207 . 103513 . 10.1016/j.jnca.2022.103513 . 1084-8045 . However, both measures [silhouette coefficient and edge correlation] prefer convex-shaped clusters and cannot adapt to all cluster shapes produced by DBSCAN.. free .
  3. 10.1016/j.ins.2015.06.039 . R.C. de Amorim, C. Hennig . Recovering the number of clusters in data sets with noise features using feature rescaling factors . Information Sciences . 324 . 126 - 145 . 2015. 1602.06989 . 315803 .
  4. Book: Leonard Kaufman . Peter J. Rousseeuw . Peter J. Rousseeuw . Finding groups in data : An introduction to cluster analysis . 1990 . Wiley-Interscience . Hoboken, NJ . 9780471878766 . 10.1002/9780470316801 . 87 .
  5. Hruschka . E.R. . de Castro . L.N. . Campello . R.J.G.B. . 2004 . Evolutionary Algorithms for Clustering Gene-Expression Data . Fourth IEEE International Conference on Data Mining (ICDM'04) . IEEE . 403–406 . 10.1109/ICDM.2004.10073.
  6. Van der Laan . Mark . Pollard . Katherine . Bryan . Jennifer . 2003 . A new partitioning around medoids algorithm . Journal of Statistical Computation and Simulation . en . 73 . 8 . 575–584 . 10.1080/0094965031000136012 . 17437463 . 0094-9655.
  7. Lenssen . Lars . Schubert . Erich . 2022 . Clustering by Direct Optimization of the Medoid Silhouette . International Conference on Similarity Search and Applications . en . 190–204 . 10.1007/978-3-031-17849-8_15 . 2022-10-20. 2209.12553 .
  8. Batool . Fatima . Hennig . Christian . 2021 . Clustering with the Average Silhouette Width . Computational Statistics & Data Analysis . en . 158 . 107190 . 10.1016/j.csda.2021.107190. 1910.11339 . 219260336 .
  9. Lenssen . Lars . Schubert . Erich . 2024-02-01 . Medoid Silhouette clustering with automatic cluster number selection . Information Systems . 120 . 102290 . 10.1016/j.is.2023.102290 . 0306-4379. 2309.03751 .