Previous lesson. Module 08: Unsupervised Learning · Next lesson. Unsupervised Learning
Module 08 Exercise Pack
KMeans clustering and silhouette on a tiny blob set.
How to run
From this exercises/ folder:
python solutions.py
That loads your implementations (in solutions.py) and runs the asserts in tasks.py.
Work pattern:
- Read each
exercise_N_...docstring intasks.py. - Implement the same function names in
solutions.py(starter solutions are already filled). - Re-run
python solutions.pyuntil you see the module OK line.
Deps: numpy, pandas, and scikit-learn where noted. No dataset downloads.
Tasks
- Fit KMeans(k=3) and return labels.
- Count unique clusters.
- Compute silhouette score.
- Pick best k in {2,3,4} by silhouette.
- Report inertia for k=3.
- Confirm label vector length equals n_samples (120).
Hub smoke (do not edit)
CI runs the fence below from the hub repo root.
import runpy
import sys
from pathlib import Path
p = Path("road-to-machine-learning/08-unsupervised-learning/exercises/solutions.py").resolve()
sys.path.insert(0, str(p.parent))
runpy.run_path(str(p), run_name="__main__")
print("mod08-exercises-smoke OK")
Previous lesson. Module 08: Unsupervised Learning · Next lesson. Unsupervised Learning