Skip to main content
Module 9 · Lesson 1 of 541/56 in the course~22 min
Module lessons (1/5)

k-means clustering

Lesson preview5 hands-on exercises readyMachine Learning: from first principles to practice · Module 9 — Unsupervised learning

Centroids, Lloyd’s algorithm, inertia and partitioning data without labels.

What you'll learn in this lesson

  • Explain how k-means partitions unlabeled data into k clusters using centroids.
  • Compute distances to centroids and calculate inertia.
  • Fit and predict clusters with scikit-learn's KMeans.

Overview

In supervised learning, every training sample arrives with a known answer: price, spam, category. But most data in the world arrives raw and unlabelled: customer purchase histories, sensor logs, genome sequences.

Unsupervised learning uncovers hidden patterns, groups and structures without target labels. The most widely used clustering technique is k-means.

Sections covered in this lesson

  1. 1The hook: discovering structure without labels
  2. 2How Lloyd's algorithm works
  3. 3Try it: step through Lloyd's algorithm
  4. 4Comparing k-means settings & regimes
  5. 5Progressive examples: distance assignment and clustering
  6. 6Practice
Pro Lesson · Module 9 — Unsupervised learning

Unlock "k-means clustering" and the full Machine Learning: from first principles to practice curriculum

Centroids, Lloyd’s algorithm, inertia and partitioning data without labels.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Machine Learning: from first principles to practice plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.