Skip to content

Repository files navigation

🛒 Retail Marketplace Logistics & Customer Analytics

📌 Executive Summary

Analyzed 100,000+ e-commerce transactions to quantify delivery risk concentration across a multi-vendor marketplace. Late deliveries affect $1.12M in revenue (6.99% of total) and correlate with a 47.1% reduction in review scores (4.29★ on-time vs 2.27★ late). Applied Empirical Bayes shrinkage to adjust seller late rates for volume bias, identifying that a small subset of sellers accounts for the majority of late-delivery revenue exposure. Supplementary RFM + K-Means analysis (k=4, elbow validated) confirms low repeat-purchase behavior.


🎯 Business Problem

A multi-vendor e-commerce marketplace with thousands of independent sellers exhibits operational challenges around delivery timeliness:

  • Surface-level metrics appear healthy, but late deliveries correlate with lower satisfaction scores
  • 96.96% of customers make only one purchase
  • Review scores decline from 4.29 to 2.27 stars when deliveries exceed promised dates (47.1% reduction)

Key Question: Are late deliveries randomly distributed, or do specific sellers disproportionately damage the platform?


📊 Dataset

E-Commerce dataset with 100,000+ orders containing:

Table Records Key Fields
Orders 99,441 order_status, delivery timestamps, estimated dates
Order Items 112,650 seller_id, price, freight, shipping_limit
Customers 99,441 customer_state, customer_city
Sellers 3,095 seller_state, seller_city
Reviews 99,224 review_score, review_comment
Payments 103,886 payment_type, installments, value
Products 32,951 category, weight, dimensions

🔍 Analytical Framework

Core Analysis: Delivery Risk Investigation

Module 1 — Platform Baseline

  • Total revenue, delivered orders, late delivery count and revenue
  • Late rate and % of revenue exposed

Module 2 — Satisfaction Impact

  • Average review score by delivery status (on-time vs late)
  • Order count and standard deviation per bucket
  • Correlation between delivery timeliness and satisfaction

Module 3 — Delay Severity Curve

  • Review score by days-late bucket
  • Order count per delay group
  • Observable degradation pattern (no cliff assumption)

Module 4 — Seller Concentration

  • Raw late rate and volume per seller
  • Empirical Bayes shrinkage to correct for small-sample bias:
    adjusted_rate = (n / (n + m)) * seller_rate + (m / (n + m)) * platform_avg_rate
    
    Where m = 100 (sellers below 100 orders are pulled toward the platform mean)
  • Sellers ranked by adjusted_rate × total_orders (volume-adjusted impact)
    • adjusted_rate ≈ probability of late delivery (corrected for sample size)
    • total_orders ≈ exposure (how many customers are affected)
    • Product ≈ expected late orders, adjusted for small-sample bias
  • Intervention targets are selected using volume-adjusted impact, not raw late count
  • Top 100 comparison: raw count ranking vs Bayes-adjusted ranking

Module 5 — Revenue Exposure Decomposition

  • Late revenue as % of total
  • Concentration of late revenue among top sellers
  • Effective platform exposure = late_revenue_pct × concentration_pct

Supplementary: Customer Behavioral Analysis

  • RFM scoring (Recency, Frequency, Monetary)
  • K-Means clustering (k=4, elbow method validated)
  • 4 behavioral segments identified from feature distribution
  • Confirms low repeat-purchase behavior (96.96% single-order)

📈 Key Findings

Customer Insights

Metric Value Implication
One-time purchase rate 96.96% Transactional marketplace
Repeat customer rate 3.04% Low repeat behavior
Revenue from repeat customers 5.66% Repeats high-value
Avg Customer Lifetime Value $137.75 Single-order dominance

Delivery Performance

Metric Value Implication
Late delivery cost $1.12M 6.99% of total revenue
On-time review score 4.29 stars Baseline satisfaction
Late delivery score 2.27 stars 47.1% satisfaction reduction
Delivery degradation Gradual Ratings decline with delay

Seller Risk Concentration

Finding Value Method
Raw top 100 concentration 53.18% of late deliveries Ranked by raw late count
Bayes-adjusted top 100 Computed via EB shrinkage adjusted_rate × volume
Revenue exposed to late-delivery risk $1.12M 6.99% of total platform revenue
Total late orders 6,381 Delivered orders past estimate
Prior strength (m) 100 Shrinks small-sample rates

Geographic Insights

State Revenue Share Avg Transit Days
SP (São Paulo) 42% 8.2 days
RJ (Rio) 13% 10.1 days
MG (Minas Gerais) 12% 11.8 days
Remote states 8% 18+ days ("Black Holes")

💡 Strategic Recommendations

Immediate Actions (Week 1-2)

  1. Address top 100 sellers - Focus on sellers contributing 53% of late deliveries
  2. Analyze delivery thresholds - Identify delivery day ranges with satisfaction degradation
  3. Segment customer base - Identify repeat-purchaser characteristics for targeted retention

Short-term (Month 1-3)

  1. Operational review for sellers with high Bayes-adjusted impact scores
  2. Regional logistics analysis for high-transit states (RR, AP, AM)
  3. Delivery estimate calibration using seller + region performance data

Long-term (Quarter 2+)

  1. Seller performance monitoring with volume-adjusted risk scoring
  2. Dynamic delivery estimates based on historical seller + carrier data
  3. Retention analysis targeting repeat-purchase behavior patterns

🛠️ Tech Stack

Category Technologies
Database PostgreSQL 15
SQL Techniques CTEs, Window Functions (LAG, LEAD, NTILE, RANK), Complex Aggregations
Python Pandas, NumPy, Matplotlib, Seaborn, Plotly, Scikit-learn
ML/Statistics Empirical Bayes Shrinkage, K-Means Clustering, RFM Analysis
Visualization Power BI Dashboard, Interactive Plotly Charts
Version Control Git & GitHub

📁 Project Structure

retail-sql-analytics/
│
├── sql/
│   ├── business_overview.sql      # Revenue trends, KPIs
│   ├── customer_analytics.sql     # CLV, Cohort, RFM analysis
│   ├── product_revenue.sql        # Category & regional performance
│   └── advance_analysis.sql       # Window functions, complex patterns
│
├── python/
│   ├── setup.py                   # Shared imports & DB connection
│   ├── analysis.ipynb             # EDA & customer segmentation
│   ├── analysis2.ipynb            # Delivery forensics & seller risk
│   └── analysis3.ipynb            # Seller risk bucketing & visualization
│
├── dashboard/
│   ├── retail_dashboard.pbix      # Power BI interactive dashboard
│   └── *.png                      # Exported visualizations
│
├── requirements.txt               # Python dependencies
└── README.md

🚀 How to Run

# 1. Clone repository
git clone https://github.com/yourusername/retail-sql-analytics.git

# 2. Install dependencies
pip install -r requirements.txt

# 3. Set up database connection
# Update python/setup.py with your PostgreSQL credentials

# 4. Run Jupyter notebooks
jupyter notebook python/

📊 Core Analysis: Delivery Risk Investigation

The following modules build a structured case from baseline measurement through seller-level risk decomposition.


Stage 1: Delivery Status & Satisfaction Correlation

Question: Does delivery timeliness impact review scores?

Sentiment Analysis

Finding: On-time deliveries average 4.29★. Late deliveries average 2.27★, representing a 47.1% reduction in satisfaction scores.

Implication: Delivery timeliness is a significant driver of customer satisfaction.


Stage 2: Root Cause Attribution

Question: Are late deliveries driven by seller processing time or carrier transit time?

Root Cause Mapping

Finding: The scatter plot reveals two distinct delay sources:

  • Carrier-driven delays: Sellers ship within 0-2 days, but carriers take 8-15 days in transit
  • Seller-driven delays: Sellers take 5-8+ days to hand off to carrier

Implication: Different delay sources require different interventions — seller process improvement vs carrier/regional logistics optimization.


Stage 3: Delivery Delay Impact Analysis

Question: How do satisfaction scores vary with delivery delays?

Delivery Impact Curve

Finding: Customer satisfaction shows gradual degradation as delivery days increase. Days 5-10 (early delays): 5,734 orders. Days 15+ (extended delays): 589 orders. The drop reflects both satisfaction decline and reduced repeat ordering.

Implication: Customers become progressively less likely to engage as delivery extends beyond promise date.


Stage 4: Seller Performance Concentration

Question: How are late deliveries distributed across sellers?

Seller Performance Distribution

Finding:

  • Top 100 sellers (7.85% of 1,274 sellers with late orders): 53.18% of all late deliveries
  • Top 3 sellers: ~1,000 late orders combined (15% of total late orders)
  • Top 20 sellers: ~3,500 late orders (35% of platform late deliveries)

Implication: Late delivery risk is concentrated in a small fraction of sellers, creating targeted improvement opportunities.


Stage 5: Empirical Bayes Adjusted Risk Ranking

Raw late counts overweight high-volume sellers. Raw late rates overweight low-volume sellers. Empirical Bayes shrinkage corrects for both.

Sellers are then ranked by adjusted_rate × total_orders — treating adjusted rate as probability of failure and order volume as exposure, so the product approximates expected late orders corrected for bias:

adjusted_rate = (n / (n + m)) * seller_rate + (m / (n + m)) * platform_avg_rate

Pareto Curve (Bayes-Adjusted) Cumulative late-delivery revenue by Bayes-adjusted seller rank. Shows concentration of risk after volume correction.

Volume vs Adjusted Late Rate Scatter plot: seller order volume against Empirical Bayes adjusted late rate. Color intensity = adjusted impact score. High-volume + high-adjusted-rate = primary intervention targets.


📊 Seller Risk Bucketing

Overall Delivery Performance

On-Time vs Late Orders Platform delivery status: 93% on-time, 7% late.

Seller Late Rate Distribution

Seller Late Rate Distribution Late-rate distribution across sellers with 50+ orders.

Risk Bucket Classification

Seller Risk Segmentation Sellers classified into SUSPEND / CRITICAL / HIGH_RISK / MONITOR based on late rate and volume thresholds.

Revenue Exposure

Revenue Exposure Scatter Revenue vs late order count per seller. Top-right quadrant = highest financial exposure.


📊 Supplementary: Customer Behavioral Analysis (RFM + K-Means)

Additional analysis to demonstrate ML capability and confirm marketplace purchase patterns.

K-Means Clustering

Customer Segments 4-cluster segmentation using Recency, Frequency, Monetary features. Segments identified from feature distribution, not pre-labeled.

Elbow Method Validation

Elbow Curve k=4 selected at elbow inflection point. Inertia: k=3→4 showed significant drop, k=4→5 showed diminishing returns.

Customer Base Distribution

EDA Distributions Distribution analysis: payment methods, price ranges, review scores across 99,441 customers.


✅ Methodology & Data Verification

Every claim in this project is backed by executed queries and actual data. Run python verify_claims.py to regenerate the verification report.

Claim Verification Summary

All claims verified via verify_claims.py. Source queries use INNER JOINs on production tables.

Claim Verified Value Method
Late delivery revenue cost $1,118,391.48 (6.99% of total) SUM(payment_value) WHERE delivered > estimated
One-time purchase rate 96.96% of customers COUNT(DISTINCT orders) per customer
Satisfaction drop 2.27★ late vs 4.29★ on-time (47.1% difference) AVG(review_score) grouped by delivery status
Delay severity 5,734 orders (days 5-10) vs 589 orders (days 15+) COUNT(order_id) grouped by days_late
Seller concentration (raw) 7.85% of sellers with late orders (100/1,274) → 53.18% of late deliveries ROW_NUMBER() by late_order count
Seller concentration (EB) Top 100 by Bayes-adjusted impact score EB shrinkage (m=100) × volume
K-Means segmentation k=4 selected via elbow method (inertia=3070.30) KMeans k=2-8, supplementary analysis

📄 Verification & Reproducibility

  • verify_claims.py - Automated script executing all claim verification queries
  • verification_results.json - Machine-readable output with exact metrics
  • RESUME_VERIFIED.md - Extended analysis summary

All SQL queries use INNER JOINs on production tables (customers, orders, order_items, payments, reviews). Run python verify_claims.py to regenerate results.


🎓 Key Skills Demonstrated

  • SQL: Complex CTEs, window functions (ROW_NUMBER, LAG), FILTER aggregations, subqueries
  • Statistical Methods: Empirical Bayes shrinkage, correlation analysis, bias correction
  • Machine Learning: K-Means clustering, elbow method validation, RFM feature engineering
  • Python: Pandas, scikit-learn, automated verification pipelines
  • Visualization: Pareto curves, scatter diagnostics, Power BI dashboards
  • Business Analysis: Revenue exposure decomposition, risk concentration quantification

👤 Author

Manikanta DM
Data Analyst | SQL & Python Specialist


📜 License

This project is for portfolio and educational purposes.

About

Retail marketplace analytics using PostgreSQL, Python (Jupyter), and Power BI — revenue, delivery SLAs, customer segmentation, seller performance

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages