1

Silhouette Coefficient

Unsolved
Unsupervised

Difficulty: 1 | Problem written by Junaid Ahmed
Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

The silhouette coefficient, also known as the silhouette score, is a metric for determining how effective a clustering technique is. Its value is between -1 and 1.

The equation for the Silhouette Coefficient is:

\(s = \frac{a-b}{max(a,b)}\)

where a is the average distance between each cluster point and b is the average distance between all clusters. It is useful for determining the validity of a cluster.

Given a and b, return the Silhouette Coefficient.

Sample Input:
<class 'list'>
a: 4
b: 2

Expected Output:
<class 'float'>
3.5

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Itaque totam eius facere voluptate ullam voluptates eveniet ratione at, quas magni suscipit consequuntur explicabo assumenda placeat praesentium vitae, perspiciatis facilis veniam sed, magni assumenda sint ad amet? Exercitationem quo porro iure nulla neque odit ab iusto, veritatis dolorum ad veniam dicta, eius illo quibusdam eligendi temporibus quisquam fugiat.

Error iusto cumque vel, fugiat laborum unde, maiores pariatur hic earum harum perferendis ratione reprehenderit quam quibusdam illum, totam veritatis accusamus repudiandae, sunt quas quis magni ut quasi ab est doloribus rem hic?

Id cumque quam veritatis quibusdam odio sit dolorum quae dolore mollitia.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)