Customer Intelligence Platform
Built by Yuvraj · 99,441 Real Orders · XGBoost AUC 0.777

Where do you want
to begin?

The Dashboard
Live data · Revenue · Segments · Churn Predictor
→
The Story
How it was built · The mistake · SHAP findings
→
The Process
SQL · ML pipeline · Leakage fix · Architecture
→
Skip — take me straight to the dashboard
Loading data...
Total Revenue
—
delivered orders
Orders
—
successfully delivered
Customers
—
unique buyers
Avg Order Value
—
per order (BRL)
Avg Rating
—
out of 5.0
Late Deliveries
—
after promised date

93% of customers never return after their first order.

That single number defines the retention challenge. This platform was built to understand why — and predict who's at risk before they leave.

0.777
ROC-AUC
XGBoost · 77K customers
CV stable 0.760±0.009
🚚
Delivery is the #1 churn driver. Even a single day of late delivery drops average rating from 4.3 to 2.6. The first order experience determines everything.
💸
Freight cost is the top ML predictor. SHAP analysis shows hidden shipping costs create "surprise shock" — the strongest signal that a customer won't come back.
👑
Champions have 10× the LTV of Lost customers. RFM segmentation identifies 15,526 high-value customers who deserve a fundamentally different retention strategy.
💄
health_beauty leads revenue at R$1.26M. It's the star category — high volume, high satisfaction. The template for what other categories should aspire to.
Gross Revenue by Month delivered orders · BRL
Monthly Revenue
Peak Month
Month-over-Month Growth
Orders vs Unique Customers
Orders
Customers
Avg Order Value vs Customer Rating dual axis
Avg Order Value (BRL)
Avg Rating
Segment Map
Size reflects customer count · Hover for details
Loading segments...
Segment Breakdown
What each segment means — and what to do
Rating Drop by Delivery Delay
On-time delivery = 4.3 avg rating. One day late = 2.6.
Loading...
Order Volume by Delivery Status
Top 15 Product Categories by Revenue
⚡
The 1-day rule. Even a single day beyond the promised date collapses average rating by 1.7 points. Customers notice immediately.
📦
Bulky categories carry more risk. bed_bath_table and furniture_decor show higher late-delivery rates — logistics complexity maps directly to churn.
🔮
Fill in order details and click
Predict to see the risk assessment.
Built by Yuvraj · 2024

One question
drove everything.

Why do 93% of e-commerce customers never come back after their first order? I spent weeks inside 100,000 real transactions to find out — and built this platform to prove it with data.

PostgreSQL XGBoost FastAPI SHAP Python SQL
0
real orders analysed
0.777
ROC-AUC
9
DB tables joined
62
ML features
93%
of customers never placed a second order.
That number started this entire project.
🏗️
Data Engineer
  • 9-table PostgreSQL schema
  • Automated ingestion pipeline
  • 3 analytics views · medallion arch
  • FastAPI — 9 REST endpoints
📊
Data Analyst
  • 5 production SQL queries
  • RFM — 96,478 customers
  • Delivery vs satisfaction analysis
  • Product health scoring
🤖
Data Scientist
  • Detected + fixed target leakage
  • XGBoost · AUC 0.777
  • RandomizedSearchCV · 30 iters
  • SHAP explainability
01
Data Engineer
The Foundation
Schema design · ingestion pipeline · medallion architecture

Most students dump CSVs into pandas and call it a project. I started by designing a 9-table relational schema in PostgreSQL — because that's what production looks like.

Two schemas: raw for data exactly as it arrived, analytics for business-ready views. This is the medallion architecture pattern used in real data lakes.

Engineering decision Used if_exists='replace' with proper indexes — not just CSV load. Batch inserts with method='multi' cut load time by 60%.
raw.orders
99,441 rows
customers
order_items
reviews
payments
sellers
products
9 tables · proper FK constraints · 7 indexes
02
Data Analyst
The Insights
5 SQL queries · window functions · RFM framework

Five production-grade SQL queries, each answering a real business question that an e-commerce company would actually pay to know.

The finding that changed everything came from Query 03 — delivery performance vs customer satisfaction.

The insight that drove the ML model 1 day of late delivery drops avg rating from 4.29 → 2.6. Not a trend — a cliff edge. Every late order is a lost customer.
Delivery delay → Rating impact
On Time
4.29
0-1 day
2.60
1-3 days
2.10
3-7 days
1.73
Source: 99,441 real delivered orders · PostgreSQL query
03
Data Scientist · The Mistake
99.9% Precision.
Something was wrong.
Target leakage · wrong frame · rebuild

The first model returned 99.9% precision. Any data scientist should immediately suspect something is wrong — and it was.

I had made a classic mistake: target leakage. recency_days was both defining the label (recency > 180 = churned) AND used as a model feature. The model wasn't learning — it was memorising a rule.

The bug CV AUC was 0.56 — barely above random guessing. That's the real tell. High train accuracy + low CV = leakage, not learning.
What leakage looks like
❌ Version 1 — Leaked
Train AUC 0.99
CV AUC 0.56
Precision 99.9%
Feature: recency_days ← Label source ⚠️
↓ rebuilt
✅ Version 2 — Clean
Train AUC 0.869
CV AUC 0.760 ± 0.009
Test AUC 0.777
recency_days removed · first-order frame only
04
Data Scientist · Fixed
The Real Model
Leakage-free frame · SHAP · freight as #1 predictor

New frame: given only a customer's first-order signals, predict whether they'll ever place a second order. Recency and frequency completely excluded.

RandomizedSearchCV with 30 iterations. 5-fold stratified CV. SHAP explainability on 2,000 test samples.

What SHAP revealed freight_value is the #1 churn predictor — not delivery speed, not review score. Customers who pay high freight relative to order value never come back. Surprise cost = silent churn.
Top churn predictors (SHAP — your model)
freight_value
0.196
installments
0.171
avg_item_price
0.150
promised_days
0.134
actual_days
0.108
review_score
0.094
From your ml/models/churn_model.pkl · XGBoost · 62 features · 77K customers
📦
Raw CSV
9 files · Kaggle Olist
→
🐍
Ingestion
Python · SQLAlchemy · batch inserts
→
🗄️
PostgreSQL
raw + analytics schemas
→
📐
SQL Layer
5 queries · CTEs · window fns
→
🧮
Feature Eng.
Pandas · 62 leakage-free features
→
🤖
XGBoost
AUC 0.777 · SHAP explainability
→
⚡
FastAPI
9 endpoints · live DB + model
→
🖥️
Dashboard
Pure HTML · zero framework
01
4.29 → 1.73
Delivery SLA is the retention lever
Late 7+ day delivery destroys avg rating. Tighten SLA on bulky categories. No discount required.
02
SHAP #1
Freight cost predicts churn better than satisfaction score
Surprise shipping cost = silent churn. Free shipping above R$150 threshold would directly address this.
03
10× LTV
Champions are worth protecting at any cost
R$318 avg LTV vs R$32 for Lost segment. A referral programme targeting Champions compounds growth.
04
R$1.24M
health_beauty is the benchmark category
Highest revenue, high satisfaction, manageable logistics. Every other category should study it.