100 beginner machine learning projects with runnable Python code, tests and honest case studies. By Networkers Home, Bangalore.
This small teaching project demonstrates a repeatable pipeline for customer segmentation using RFM-style numeric summaries (recency, frequency, monetary). It is deliberately simple and deterministic so students can experiment with preprocessing, clustering settings and stability checks. The pipeline scales numeric features, fits an interpretable clustering model (KMeans), compares a small grid of cluster counts, and evaluates cluster stability across two synthetic time periods.
The dataset is synthetic and built inside the code to emulate anonymised RFM summaries. Each customer row contains: recency (days since last visit), frequency (visits in period), and spend (monetary aggregated). The data is generated with clear consent-style assumptions for teaching only: no real personal data is used. This is not a replacement for real operational data and is intentionally small for clarity.
Run the project module directly. It prints a JSON dictionary with key metrics and cluster summaries.
python project.py
(The module also exposes run(seed: int = 42) for programmatic use.)
Install the requirements and run pytest in the project folder:
Tests check the returned structure, ranges and deterministic behaviour for a fixed seed.
Measured by running python project.py (seed 42) on 2026-10-23; the tests in test_project.py assert the floor.
| Metric | Value |
|---|---|
| best_k | 3 |
| n_segments | 450 |
| silhouette | 0.8408 |
| stability_ari | 1 |
Also returned (see python project.py output): segment_summary (3 items).
This teaching project uses synthetic RFM summaries, not real customer records. The clustering model is KMeans which assumes spherical clusters and numeric scaling; it may not capture complex behaviour in real commercial datasets. The pipeline and metrics are intended for exploration and planning only — segments should be reviewed by humans and validated on real business outcomes before any operational use. Also: the original starter that used handwritten digits was not appropriate for customer segmentation; this project replaces that with numeric RFM-style data.
Possible next steps include: adding categorical attributes and using mixed-type clustering; exploring hierarchical or density-based clustering; validating segments against business outcomes; and adding simple visual reports (outside this restricted environment).
Full case study, build steps and evaluation checks: Customer segmentation tool on networkershome.com
Built by Networkers Home · Learn the skills in the AI Engineer Course · Part of 100 AI projects with code