Clustering
Find groups without labels and evaluate whether the groups mean anything.
What you will be able to do
- Scale features before distance-based clustering.
- Choose k with the elbow method and domain sense.
- Inspect cluster centres in original units.
- Validate clusters with a held-out sample or stakeholder review.
In plain English
Clustering groups similar rows. K-means needs a chosen number of clusters and scaled features. The result is a hypothesis, not a truth; inspect the cluster profiles before naming them.
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
scaled = StandardScaler().fit_transform(X)
model = KMeans(n_clusters=3, random_state=42, n_init='auto').fit(scaled)
print(model.labels_[:10])
print(model.cluster_centers_.shape)Your turn
EasyFit K-means
Cluster scaled data into 3 groups with a fixed random state.
PYTHON · starter
KMeans()Check your understanding before moving on.
Knowledge checkQuestion 1
Why scale features before K-means?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.