Course materials · Introduction to Machine Learning

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.

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 K∈{2,3,4}K\in\{2,3,4\}.

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

Reference materials