Unsupervised Learning · Study
English translation
Topics covered
Changing the number of clusters and the scale can change how the same data are grouped. Interpret the structure without assigning meaning to cluster numbers themselves.
Grouping without Correct Answers
K-means reduces distances between centers and samples for a specified number of clusters. Cluster numbers are arbitrary names; examine centers, variance, and assignment structure rather than the numbers themselves.
Distance units
A feature with a large range can dominate distances. Compare before and after Standardization and across cluster counts, but do not conclude that clusters are meaningful solely from decreasing inertia.
Example output order: Inertia → mean Silhouette.
- : Mean distance within the same cluster.
- : Mean distance to the nearest other cluster.
- Silhouette: , range .
- Close to 1: Well separated from other clusters.
- Near 0: Close to a cluster boundary.
- Negative: A sample closer to another cluster.
Interpret the mean values and cluster plots together.
Worked example
Use make_blobs(n_samples=180,centers=3,cluster_std=.8,random_state=7) and .
from sklearn.datasets import make_blobs
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score
X,_=make_blobs(n_samples=180,centers=3,cluster_std=.8,random_state=7)
model=KMeans(n_clusters=3,random_state=7,n_init=10).fit(X)
print(model.inertia_,silhouette_score(X,model.labels_))
218.32342403479697 0.8287785157574988
Reference example
View more examples