Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-147

Silhouette Score Single Point

Problem

Compute the silhouette score of point i: a = mean distance to the other points in its own cluster, b = smallest mean distance to any other cluster, score = (b - a) / max(a, b).

Return 0.0 if the point's cluster is a singleton, there is no other cluster, or max(a, b) is 0.

Hint

a measures cohesion, b measures separation; values near 1 mean the point fits its own cluster well.

Test cases

case 1
in: [[[0,0],[1,0],[10,0],[11,0]],[0,0,1,1],0]
expected: 0.9047619047619048
case 2
in: [[[0,0],[1,0],[10,0],[11,0]],[0,0,1,1],2]
expected: 0.8947368421052632
case 3
in: [[[0],[5]],[0,1],0]
expected: 0
case 4
in: [[[0,0],[5,5]],[0,0],0]
expected: 0
Starter codePython
def silhouette_point(points, labels, i):
    # Your code here
    pass

4 test cases · run your code against them in the editor