UK Online Retail · 2009–2011 · UCI ML Repository
Retail Customer Intelligence Platform

End-to-end ML pipeline: SQL/RFM analysis → K-Means segmentation → churn prediction → product recommendations. Built on 800K+ real transactions.

Monthly revenue — full time series

Monthly Revenue Trend

Dec 2009 → Dec 2011

Revenue by Country

UK = 92% of total · top 8 shown

Top Products by Revenue

Gift-ware dominates · top 8 shown
Layer 2 · K-Means Clustering (K=4) · PCA Visualization
Customer Segmentation

RFM features log-transformed and scaled before clustering. PCA explains 95.1% of variance. Click a segment to see its profile and top products.

Segment explorer

PCA Cluster Scatter

800 sampled customers · PC1+PC2 = 95.1% variance

Revenue Share by Segment

Champions = 20% of customers → 65% of revenue

Churn Risk by Segment

Lost customers: 80% probability
Layer 3 · Random Forest · Time-Based Split · No Data Leakage
Churn Prediction Model

Predicts which customers will not purchase in the next 90 days. Trained on pre-Sep 2011 data; evaluated on the Sep–Dec 2011 holdout window.

ROC Curve

Random Forest AUC = 0.824

Confusion Matrix

Test set: 1,050 customers · holdout window
→ Predicted
↓ Actual
Retained
Churned
Feature importance & risk distribution

Top Churn Drivers

Recency dominates at 27.4% — how recently a customer purchased

Churn Risk Tiers

High (>65%) · Medium (35–65%) · Low (<35%)

Key Finding: Recency + Engagement = Churn Signal

The model identifies recency (27.4%) as the dominant churn predictor. Monetary value (13.2%) and active months (11.6%) are next. Champions churn at only 18.7% vs Lost at 80%. Target Medium-risk customers (35–65% probability) for highest expected return on retention spend — they're still reachable and have proven purchase history.

Layer 4 · Market Basket Analysis · Apriori Algorithm · 89 Rules
Product Recommendations

Association rules from 28K+ UK baskets. Segment-specific recommendations ranked by segment revenue. "Customers who buy X also buy Y."

Segment-based recommendations
Top association rules by lift

Market Basket Rules

Lift = how much more likely than random chance · confidence = % of baskets with antecedent containing consequent · top 12 shown
Retention Targeting · High-Value Customers · Actionable Output
At-Risk Customer List

Top 20 high-value customers with churn probability over 65%, sorted by historical revenue — the highest-priority targets for your retention team.

High-priority targeting list

Top 20 High-Value At-Risk Customers

Churn probability >65% · sorted by total historical revenue · all candidates for personalized retention offer
Customer IDChurn Prob.RevenueRecencyOrdersSegment
Technical Architecture · End-to-End ML Pipeline · 5 Scripts
Pipeline Architecture

Five-stage modular pipeline. Each script produces outputs consumed by the next — fully reproducible from raw Excel to live dashboard.

Data Flow

Raw Excel → Clean CSV → Segment → Predict → Recommend → Dashboard

Dataset Statistics

UCI Online Retail II · real UK gift-ware retailer · 2009–2011

Model Performance

All metrics on held-out test set — no data leakage

What Makes This Project Stand Out

Most analytics projects do one thing. This pipeline does four connected things: SQL-based RFM analysis feeds K-Means clustering; cluster labels enrich the churn model's features; churn scores inform retention priority; association rules produce per-segment recommendations. The time-based train/test split prevents data leakage — the most common mistake in student churn models that inflates accuracy to 99%+. Real performance on this dataset: 75.4% accuracy, 0.824 AUC.

UCI Online Retail II · 805K transactions · 5,878 customers · 4,631 products · 38 countries
Pythonpandasscikit-learnmlxtendK-MeansRandom ForestAprioriPCASQLite