Topics / 🤖 AI & Machine Learning / 📏 Level 22: Evaluate & Engineer

Python exercise · about 5 minutes · free

K-Means: Find Customer Segments

No labels, just behaviour. Clustering finds natural groups, like casual players, regulars and whales.

K-means places k centres and assigns each point to the nearest one, repeating until stable. KMeans(n_clusters=3, n_init=10, random_state=0).fit(X); the groups are in .labels_. You still have to name and judge the clusters yourself.

Diagram. casual (~1.5 h, ₹50); regulars (~11 h, ₹320); whales (~30 h, ₹5,000). k-means finds 3 groups; you decide what they meancasual~1.5 h, ₹50regulars~11 h, ₹320whales~30 h, ₹5,000k-means finds 3 groups; you decide what they mean
Your quest: Cluster the players into 3 groups. Set labels to the cluster label of each row.
Try it now Runs in your browser. No sign-in needed. Ctrl+Enter to run.
Hintlabels = KMeans(n_clusters=3, n_init=10, random_state=0).fit(X).labels_
Output appears here.

Open it in the full course → Free with Google: saves your progress and unlocks 627 lessons.

In this level you'll learn:
More in Level 22: Evaluate & Engineer

Share on LinkedIn