Clustering Metrics
Measures how similar each point is to its own cluster vs. other clusters. Range: [−1, 1]. Higher is better. 1 = well-clustered, 0 = overlapping, −1 = misassigned.
Per-sample silhouette values. Useful for identifying poorly assigned samples.
Average similarity between each cluster and its most similar cluster. Lower is better. 0 = perfect separation.
Ratio of between-cluster dispersion to within-cluster dispersion. Higher is better. Also known as Variance Ratio Criterion.
Similarity between two clusterings, adjusted for chance. Range: [−1, 1]. 1 = perfect match, 0 = random. Requires ground truth labels.
Adjusted mutual information between two label assignments. Adjusted for chance. Range: [0, 1].
Normalized mutual information between two label assignments. Range: [0, 1]. 1 = perfect correlation.
Geometric mean of pairwise precision and recall. Range: [0, 1]. Higher is better.
Whether each cluster contains only members of a single class. Range: [0, 1].
Whether all members of a given class are assigned to the same cluster. Range: [0, 1].
Harmonic mean of homogeneity and completeness. Range: [0, 1].
Silhouette Coefficient
Where:
- a(i) = Mean distance to points in same cluster
- b(i) = Mean distance to nearest other cluster
Davies-Bouldin Index
Where:
- σᵢ = Average distance of cluster i members to centroid
- d(cᵢ,cⱼ) = Distance between centroids
Calinski-Harabasz Index
Where:
- B = Between-cluster dispersion
- W = Within-cluster dispersion
V-Measure
Where:
- h = Homogeneity
- c = Completeness
import { silhouetteScore, daviesBouldinScore, adjustedRandScore } from "deepbox/metrics";import { tensor } from "deepbox/ndarray";const X = tensor([[1, 2], [1.5, 1.8], [5, 8], [8, 8], [1, 0.6], [9, 11]]);const labels = tensor([0, 0, 1, 1, 0, 1]);silhouetteScore(X, labels); // Higher = better separationdaviesBouldinScore(X, labels); // Lower = better separation// With ground truthconst trueLabels = tensor([0, 0, 1, 1, 0, 1]);const predLabels = tensor([0, 0, 1, 1, 0, 2]);adjustedRandScore(trueLabels, predLabels);