SilhouetteScore<T>

Models & Types · AiDotNet.Clustering.Evaluation

Silhouette Score for evaluating cluster quality.

Implements: IClusterMetric<T>

For Beginners

Silhouette Score asks “Is each point in the right cluster?”

For each point, we measure:

  1. How close it is to its cluster-mates (a)
  2. How far it is from the nearest other cluster (b)

If b >> a: Point is clearly in the right place (+1) If b ≈ a: Point is between clusters (0) If b << a: Point might be in wrong cluster (-1)

The overall score is the average of all points. Higher is better!

How It Works

The Silhouette Score measures how similar a point is to its own cluster compared to other clusters. Values range from -1 to 1:

  • Near +1: Points are well-matched to their cluster
  • Near 0: Points are on cluster boundaries
  • Near -1: Points may be assigned to wrong clusters

For each point i:

  • a(i) = mean distance to other points in same cluster
  • b(i) = mean distance to points in nearest other cluster
  • s(i) = (b(i) - a(i)) / max(a(i), b(i))

Constructors

Constructor Summary
SilhouetteScore(IDistanceMetric<T> distanceMetric) Initializes a new SilhouetteScore instance.

Properties

Property Summary
string Name { get; }

Methods

Method Summary
Vector<T> ComputeSampleScores(Matrix<T> data, Vector<T> labels) Computes the silhouette score for every sample.
double Compute(Matrix<T> data, Vector<T> labels)