which cluster evaluation metric measures the similarity inside each cluster?
- User
which cluster evaluation metric measures the similarity inside each cluster?
- Assistant
The metric you’re looking for is intra-cluster similarity (or cohesion). A few common ways it’s measured in clustering evaluation:
Silhouette coefficient (per cluster or per point): Measures how close each sample is to points in its own cluster (compactness) compared to other clusters. The “a(i)” part of silhouette is specifically the average intra-cluster distance.
Dunn index (numerator): Uses the maximum intra-cluster distance to quantify cluster tightness.
Davies–Bouldin index (denominator): Computes the average similarity within each cluster relative to the distance between clusters.
Within-cluster sum of squares (WCSS): The most direct measure of how similar points are inside the same cluster, used in k-means (a.k.a. inertia). Lower WCSS means higher intra-cluster similarity.
👉 In short:
WCSS / intra-cluster distance = raw measure of similarity inside each cluster.
Silhouette (a(i)) = per-point version of the same.
Do you want me to focus only on internal metrics (like WCSS, Silhouette, DBI), or also mention external metrics (like homogeneity, if you have ground truth)?
- User
Does PYthon have an implementatino for Within-cluster sum of squares?
- Assistant
Yes 👍 In Python you usually don’t see "WCSS" as a separate function — but it’s built into clustering implementations. For k-means in scikit-learn, it’s called inertia_, which is exactly the within-cluster sum of squared distances to the cluster centroids. Example: pythonCopy codefrom sklearn.cluster import KMeans import numpy as np
toy data
X = np.array([[1,2], [1,4], [1,0], [10,2], [10,4], [10,0]])
run k-means
kmeans = KMeans(n_clusters=2, random_state=42).fit(X)
WCSS (within-cluster sum of squares)
print("WCSS:", kmeans.inertia_)
This inertia_ value is the WCSS. If you’re using another clustering algorithm (like DBSCAN, Agglomerative, Spectral, etc.), scikit-learn doesn’t provide inertia_, but you can compute WCSS manually: pythonCopy codefrom sklearn.metrics import pairwise_distances_argmin_min
def wcss(X, labels, centers): # squared distances of each point to its assigned cluster center _, dists = pairwise_distances_argmin_min(X, centers) return np.sum(dists**2)
Example with kmeans result:
print("WCSS manual:", wcss(X, kmeans.labels_, kmeans.cluster_centers_))