Skip to content

Dethered/retail-churn-analysis

Repository files navigation

Customer Churn Forecasting & $3.38M At-Risk Revenue Optimization via Survival Analysis

Jupyter Python Power BI SQL

Executive Summary

Traditional churn models treat customer attrition as a binary classification problem (Will they quit? Yes/No). This project implements a Time-to-Event Survival Analysis framework to solve a more critical business challenge: When will they leave, and what financial revenue is at risk over time? By leveraging a Random Survival Forest model on historical account behavioral data sourced from the UCI Machine Learning Repository (Online Retail II Dataset), this pipeline successfully handles right-censored data and maps out exact customer survival trajectories over a 700+ day horizon.

Data Architecture & Pipeline

This project involves data processing from raw records to automated business intelligence dashboards.

  1. Data Cleaning/Preparation(queries.sql): Using SQL, processed and cleaned an initial dataset composed of 1,067,371 raw records down to 5,852 unique customer profiles in the analytical base table. Executed SQL transformations on the cleaned records to focus on recency, frequency, and monetary (RFM) behavioral metrics in addition to high-performing C-index features.
  2. Modeling & Diagnostics (churn_analysis_dt.ipynb):
    • Conducted exploratory data analysis (EDA) using Kaplan-Meier Curves, correlation heatmaps, and boxplots as well as determined feature importance ranking through permutation drops in C-index scores.
    • Fitted survival models (Cox Proportional Hazards, Random Survival Forest).
    • Validated major statistical assumptions/violations using Schoenfeld, Martingale, and Deviance residuals.
    • Assessed Integrated Brier Scores and Temporal Risk Profiling to quantify how accurately the model estimates the probability of customer churn.
  3. Production Pipeline (predict_churn_analysis_pipeline.py): An automated Python script handling database connections, defensive data seeding, and discrete integration over survival curves to output actionable predictions, while enabling seamless logging and dataset expansion.
  4. Business Intelligence (dashboard_churn_analysis_dt.pbix): A Power BI dashboard providing stakeholder-facing visualizations of at-risk cohorts, behavioral drivers, and high-risk periods.

Key Methodologies

  • Survival Analysis & Statistical Modeling: Survival Analysis (Kaplan-Meier, Cox PH, Random Survival Forest), Integrated Brier Scores, residual-based diagnostics (Schoenfeld, Martingale, Deviance), and C-index performance evaluation.
  • Quantitative Modeling: Quantified at-risk revenue and temporal risk profiles by performing numerical integration over generated survival probability curves.
  • Data Engineering: SQL aggregation/transformation, RFM feature engineering, and automated ETL/defensive data pipelines via Python.

Business Intelligence Dashboard (Power BI)

Translates complex survival probabilities into interactive Power BI visualizations, mapping out key behavioral drivers that will help prevent churn amongst defined high-risk customer cohorts.

Page 1: Churn Analysis Overview

A summary quantifying baseline metrics such as tracking $17.43M in total revenue against a $3.38M at-risk segment, alongside volumes comparing active versus churned accounts. Churn Analysis Overview


Page 2: Customer Retention & Behavioral Drivers

A mapping of behavioral patterns using transaction frequencies and monetary spending thresholds. Includes a clear tenure breakdown proving that churn rates drop aggressively from 71.17% in the first quarter down to 23.18% after a customer hits the 1+ year legacy mark. Customer Retention & Behavioral Drivers


Page 3: Predictive Risk Insights

Provides a cohort analysis of active users across segmented risk tiers (Low, Medium, High) computed by the Random Survival Forest and Cox Proportional Hazards models, mapping high-risk accounts to specific customer profiles for immediate outreach. Predictive Risk Insights

Repository Structure

  • images/: Stores dashboard pages as images for an easy overview.
  • queries.sql: The SQL aggregation and transformation queries used to clean raw data from the UCI Online Retail II dataset and to construct the analytical base table.
  • churn_analysis_dt.ipynb: The primary research notebook containing all the statistical theory, model fitting, and diagnostics for the project.
  • predict_churn_analysis_pipeline.py: The Python pipeline for generating timeline predictions as well as the script needed for automation of logging and dataset expansion.
  • dashboard_churn_analysis_dt.pbix: The compiled Power BI dashboard for business stakeholders.

Author - Daniel Therattil

Contributors

Languages