100 beginner machine learning projects with runnable Python code, tests and honest case studies. By Networkers Home, Bangalore.
This teaching project demonstrates a simple, unsupervised image segmentation pipeline that clusters pixel colour features using K-means. It builds small synthetic colour images (so no external image files are required), fits K-means on a held-out subset of pixels, and predicts cluster assignments for the remainder. The project reports a held-out silhouette score (a clustering quality metric) and K-means inertia. It also returns the chosen cluster count so students can experiment with how the number of clusters affects the segmentation.
The data are synthetic, small RGB images generated in code using NumPy (no external image files or downloads). Each image contains simple coloured regions (rectangles and circles) arranged to mimic natural regions with clear colour differences. Images are resized by construction to 64×64 pixels and represented in RGB colour space (three channels). This keeps the task lightweight while giving realistic pixel-colour clustering behaviour.
Run the project module as a script. It prints a JSON object of results. Example (from shell):
python project.py
Or import and call the run(seed) function from Python.
Use pytest. The provided tests import run() and verify the output structure, value ranges, determinism, and a conservative metric floor on the held-out silhouette score.
Measured by running python project.py (seed 42) on 2026-10-23; the tests in test_project.py assert the floor.
| Metric | Value |
|---|---|
| silhouette | 0.7358 |
| inertia | 214.4296 |
| n_clusters | 4 |
Full case study, build steps and evaluation checks: Image segmentation using clustering on networkershome.com
Built by Networkers Home · Learn the skills in the AI Engineer Course · Part of 100 AI projects with code