Module 11 · Machine Learning: How Models Learn · Lesson 38 of 51
Clustering and the model zoo
K-means step by step, choosing k with the elbow, and a tour of the main model families (linear, trees, forests, boosting, nearest neighbours) and when to use each.
In this lesson · about 40 minutes
- Explain the two steps of k-means and why scaling matters
- Choose k with an elbow chart and name the clusters in business terms
- Match common model families to problems
Try it · data lab
K-means, step by step
Group members by visits and spend. Step through assign and move, try different k, and read the elbow chart.
Cluster 1: 19 members, about 16 visits, $4.73 average spend
Cluster 2: 62 members, about 8 visits, $6.27 average spend
Cluster 3: 19 members, about 21 visits, $6.16 average spend
K-means in two steps
- Assign: each point joins the nearest centre.
- Move: each centre moves to the average of its points.
Repeat until assignments stop changing. Inertia is the total squared distance from points to their centres; it always falls as k grows, so look for the elbow where adding a cluster stops helping much. Scale features first, or the one with the biggest numbers decides everything. Run several random starts (scikit-learn does this) because a bad start can give a poor answer.
The model zoo
| Family | Idea | Strengths | Watch for |
|---|---|---|---|
| Linear / logistic regression | Weighted sum of features | Fast, explainable, a strong baseline | Misses curves and interactions unless you engineer them |
| Decision tree | A flowchart of yes/no questions | Easy to explain, handles mixed data | Overfits when deep |
| Random forest | Many trees on random samples, averaged | Accurate, robust, little tuning | Bigger, less explainable |
| Gradient boosting | Trees added one by one to fix the last ones' errors | Often the best on tables of data | Needs tuning; can overfit |
| k-nearest neighbours | Copy the answer of similar past rows | Simple, no training | Slow on big data, needs scaling |
| Neural networks | Layers of weighted sums with bends | Images, text, sound | Usually overkill for business tables |
Exercise
One round of k-means by hand
Given six points and two starting centres, do one assign step and one move step. Set labels to a list of 0/1 (nearest centre for each point, by straight-line distance) and new_centres to a list of two [x, y] lists, rounded to 2 decimals.
Code that runs before yours
import numpy as np points = np.array([[1, 2], [2, 1], [1.5, 1.8], [8, 8], [9, 7.5], [7.5, 9]]) centres = np.array([[2.0, 2.0], [6.0, 6.0]])
Flashcards
Module 11 flashcards
0 of 11 known
Say the answer out loud, flip the card, then be honest: cards you miss come back at the end.
Practice exam
Module 11 checkpoint
12 questions, 15 minutes.
- 12 questions · 15 minutes
- No feedback until you submit. Flag questions to come back to them.
- Aim for 85% or better before you move on. The real exam's 750 out of 900 is roughly 80–83%.
Exercises solved: 0 of 1
Written by Noviq Academy in its own words. Kettle & Crumb and all its data are made up for teaching; any resemblance to a real business is a coincidence. Python runs in your browser with Pyodide, so results can differ slightly from your own computer. Power BI, Tableau and other product names belong to their owners. Read-aloud uses your device's built-in voices.