Skip to content
Sangam Gupta
All work

Customer Intelligence

Turns raw transactions into customer segments a business can act on, served to a web app and an Android app from one API.

Status
Demo offline right now
Stack
Python, scikit-learn, K-Means, FastAPI, AWS EC2, Streamlit, Kotlin
Links
Open the web appAndroid app (closed testing)Code

Try the model

Enter a customer's recency, frequency and spend to see their segment.

Loading the model…

How it fits together

  1. Transactions
  2. Cleaning and EDA
  3. RFM features
  4. StandardScaler
  5. K-Means
  6. FastAPI on AWS EC2
    • Streamlit web app
    • Android app

Model card

Intended use
Group customers by purchasing behaviour so a business can tailor retention, cross-selling and reactivation campaigns.
Data
Transaction records aggregated into one row per customer (2,394 customers) with recency, frequency and monetary value.
Model
StandardScaler followed by K-Means with 3 clusters, chosen with the elbow method (KneeLocator); clusters labelled High-Value / Loyal, Regular / Mid-Value and Inactive / Low-Value.
How it was evaluated
  • K-Means silhouette score 0.498 with 3 clusters
  • Hierarchical clustering: 0.473 with 3 clusters
  • DBSCAN reached 0.576 but found only 2 clusters and left points as noise, so K-Means was kept
Limitations
  • RFM only: it ignores what people buy, channel and demographics.
  • Segment boundaries reflect this dataset's customers and need refitting for another business.
  • Three segments is a modelling choice; finer segments may suit larger customer bases.
Read the full analysis notebook

End-to-end unsupervised ML system: RFM features and K-Means clustering behind a FastAPI service on AWS EC2, used by a Streamlit web app and a native Android app.

The problem

Most businesses have years of transaction logs and still treat every customer the same. I wanted to see how far an unsupervised model could go, from raw transactions to segments someone could check on a phone.

How I built it

  1. Clean the transaction data and aggregate it per customer into recency, frequency and monetary (RFM) features.
  2. Scale the features and pick the number of clusters with the elbow method, checking quality with silhouette scores.
  3. Compare K-Means against hierarchical clustering and DBSCAN, and visualise the clusters with PCA.
  4. Give each cluster a business-friendly segment label and serialise the model.
  5. Serve predictions from a FastAPI service on AWS EC2, kept running with systemd. I designed the API with AI assistance.
  6. Build two clients on the same API: a Streamlit web app, and a native Android app in Kotlin with Jetpack Compose, built with AI assistance.

Where it is now

The web app is live on Streamlit Cloud and the Android app is in closed testing on Google Play. HTTPS, authentication and a custom domain for the API are next.

Ask about Customer Intelligence

Answers come from this case study and its code on GitHub.