Back to Labs

Cluster Iris Flowers

Guided clustering project · 20 steps · K-means clustering

About

Learn unsupervised learning by grouping Iris flowers and checking how the discovered clusters compare to known species.

Data

Loaded from scikit-learn via load_iris. Four flower measurements with three species labels for reference.

Task

Complete TODOs in order, run KMeans, pick a good k with elbow and silhouette, then evaluate cluster quality with ARI.


Sign in to run cells and save progress. Log in or sign up.

Cell 1

Step 1: Imports

Cell 2

Step 2: Load dataset

Cell 3

Step 3: Build DataFrame

Cell 4

Step 4: Add species names

Cell 5

Step 5: Shape and class counts

Cell 6

Step 6: Preview rows

Cell 7

Step 7: Quick summary stats

Cell 8

Step 8: 2D scatter by true species

Cell 9

Step 9: Prepare feature matrix

Cell 10

Step 10: Scale features

Cell 11

Step 11: KMeans with k=3

Cell 12

Step 12: Cluster sizes

Cell 13

Step 13: Compare cluster vs species

Cell 14

Step 14: Clusters in petal space

Cell 15

Step 15: Inertia for k=1..8

Cell 16

Step 16: Elbow plot

Cell 17

Step 17: Silhouette for k=2..8

Cell 18

Step 18: Silhouette plot

Cell 19

Step 19: Evaluate clustering quality

Cell 20

Step 20: Inspect cluster centers