An end-to-end cohort retention analysis pipeline for a B2B SaaS subscription product. Analyzes 10,000 users over 2 years using both weekly and monthly cohorts, measuring user retention and Net Revenue Retention (NRR) — the two most critical metrics for SaaS product health and investor reporting.
- What percentage of users are still active after 1, 3, and 6 months?
- Is cohort quality improving over time (is the product getting better)?
- What is our Net Revenue Retention — are existing customers growing or shrinking in value?
- When is monthly vs weekly cohort analysis the right tool?
cohort_retention_analysis/
├── outputs/ # Charts, cohort tables (CSV), executive summary
├── src/
│ ├── data_prep.py # 2 years of synthetic SaaS subscription events
│ ├── cohorts.py # Monthly + weekly cohort table construction
│ ├── retention.py # Retention curves, churn rates, NRR
│ └── visualizations.py # Heatmaps, curves, dashboard
├── main.py # Run the full pipeline
├── requirements.txt
└── README.md
Synthetic SaaS subscription data simulating realistic behavior:
| Parameter | Value |
|---|---|
| Users | 10,000 |
| Period | Jan 2023 – Dec 2024 |
| Plans | Starter ($29), Professional ($49), Enterprise ($149) |
| Month 1 churn | ~25% (industry benchmark) |
| Steady-state churn | ~3%/month |
| Expansion probability | 15% of retained users upgrade |
| Cohort quality | Improves 0.5%/month (product improving) |
| Frequency | Best For |
|---|---|
| Weekly | Evaluating product releases, short-term A/B tests, operational decisions |
| Monthly | Strategic planning, investor reporting, long-term trend analysis |
User Retention Rate
Retention(cohort, period) = Active users in period N / Users at signup
Net Revenue Retention (NRR)
NRR = (Starting MRR - Churned MRR + Expansion MRR) / Starting MRR
- NRR > 110%: World-class (Snowflake, Twilio tier)
- NRR > 100%: Healthy — revenue grows even without new customers
- NRR < 100%: Revenue leaking — must be addressed
- Monthly churn rate with 3-month rolling average
- Annualized churn = 1 - (1 - monthly_churn)^12
- Cohort quality comparison at Month 1, 3, 6, and 12
| File | Description |
|---|---|
01_monthly_retention_heatmap.png |
Classic cohort heatmap (monthly) |
02_weekly_retention_heatmap.png |
Weekly granularity heatmap |
03_retention_curves.png |
Avg retention curve + individual cohorts |
04_nrr_over_time.png |
Net Revenue Retention trend |
05_churn_rate.png |
Monthly and annualized churn over time |
06_cohort_quality.png |
Retention improvement across cohorts |
07_summary_dashboard.png |
Full summary dashboard |
monthly_user_retention.csv |
Monthly cohort table (exportable) |
monthly_mrr_retention.csv |
Monthly MRR retention table |
weekly_user_retention.csv |
Weekly cohort table |
retention_executive_summary.txt |
Business-ready summary |
git clone https://github.com/yourusername/cohort_retention_analysis.git
cd cohort_retention_analysis
pip install -r requirements.txt
python main.pyNo data download required — data is generated synthetically with realistic SaaS benchmarks.
- Python 3.14+
pandas— cohort table construction and time-series manipulationnumpy— simulation and statistical computationmatplotlib— heatmaps, curves, and dashboardsscipy— statistical analysis
- Weekly vs monthly cohort construction from event data
- User retention and revenue retention (NRR) analysis
- Cohort heatmap visualization (most-recognized product analytics chart)
- Churn rate calculation (monthly and annualized)
- Cohort quality trend analysis
- Net Revenue Retention with expansion modeling
- SaaS subscription event simulation
Built as part of a data science / product analytics portfolio project.
Background: 15+ years in Marketing Analytics | SQL | Python | Statistical Modeling