02 · See it in action
Follow the steps
- Choose numeric features for a synthetic collection.
- Scale features when their units differ substantially.
- Try a small range of cluster counts.
- Inspect representative examples and ambiguous boundary cases.
Worked example
from sklearn.cluster import KMeans
x = [[0, 0], [0, 1], [9, 9], [9, 8]]
m = KMeans(n_clusters=2, random_state=7, n_init=10).fit(x)
print(m.labels_)
# Group IDs are arbitrary; nearby points should share a group.
Read the example once, then explain each part aloud in your own words. If it includes Python, you can understand the idea first and run the code later in a local Python environment. Code is shown as text; this page does not execute it.
Sign in to save your reading progress.
Sign in