How prabham205/telecom-customer-churn-prediction-and-retention-recommendation works
Purpose and entry points
This repository implements telecom customer churn prediction and retention recommendations, with analytical dashboards, an API surface, and an AI retention assistant. Primary runtime entry points are api/main.py for the service layer and app/streamlit_app.py plus app/pages/ for the Streamlit interface. Model training is initiated through scripts/train.py.
Data and feature pipeline
Raw customer data originates at data/raw/Telco_customer_churn.xlsx. The data path is organized as load, clean, engineer features, and preprocess:
• src/data/loader.py
• src/data/cleaner.py
• src/data/feature_engineering.py
• src/preprocessing/pipeline.py
The fitted preprocessing artifact is persisted at artifacts/preprocessor.joblib, creating a boundary between training-time transformations and inference-time inputs.
Model training, evaluation, and inference
The training layer supports several model implementations under src/models/, including lightgbm_model.py, xgboost_model.py, random_forest.py, logistic_regression.py, and dnn_model.py. Evaluation is centralized in src/models/evaluate.py, with recorded metrics at models/model_metrics.json.
Online or application-facing scoring is separated into src/prediction/predictor.py. This boundary should consume the persisted preprocessing/model artifacts rather than reproduce training logic.
Risk, value, and retention decisioning
Prediction outputs are converted into business actions through distinct domain modules:
• Churn-risk interpretation: src/risk/risk_engine.py
• Revenue-at-risk calculation: src/business/revenue_at_risk.py
• Customer prioritization: src/recommendation/priority_engine.py
• Rule-based retention and offer selection: src/recommendation/retention_rules.py and src/recommendation/offer_engine.py
This establishes a control flow of customer data → churn prediction → risk/value assessment → prioritized retention recommendation.
Generative AI and agent workflow
The AI retention assistant is structured as an agent graph rather than being embedded directly in the dashboard. Its workflow/state boundary is represented by:
• agent/graph.py
• agent/nodes.py
• agent/state.py
Prompt content is isolated in agent/prompts.py; LLM access and offer generation are isolated in genai/llm_client.py and genai/offer_generator.py. This separates deterministic recommendation logic from external LLM-driven assistance.
Delivery surfaces and operational concerns
The Streamlit UI exposes executive KPIs, customer-risk views, retention recommendations, AI assistance, and model performance through app/pages/01_Executive_Dashboard.py through app/pages/05_Model_Performance.py. Reusable visualization and presentation components reside in app/components/.
The API request/response boundary is represented by api/main.py and api/schemas.py. Monitoring is explicitly separated in src/monitoring/drift_monitor.py. Deployment infrastructure includes Dockerfile; dependencies and environment configuration are defined by requirements.txt, .env.example, and config.yaml.
Main entry points: predictor.py Churn predictor · main.py API service · pipeline.py Preprocessing pipeline · offer_engine.py Offer selection
Components 22
Data & ML
- Telco churn data
data/raw/Telco_customer_churn.xlsx - Data loader
src/data/loader.py - Data cleaner
src/data/cleaner.py - Feature engineering
src/data/feature_engineering.py - Preprocessing pipeline
src/preprocessing/pipeline.py - Fitted preprocessor · Shared training and inference transformation contract.
artifacts/preprocessor.joblib - Model training · Trains supported LightGBM, XGBoost, random forest, logistic, and DNN models.
scripts/train.py - Model evaluation
src/models/evaluate.py - Model metrics
models/model_metrics.json - Churn predictor · Scores customers using persisted preprocessing and model artifacts.
src/prediction/predictor.py
Retention Decisioning
- Risk interpretation
src/risk/risk_engine.py - Revenue at risk
src/business/revenue_at_risk.py - Customer prioritization
src/recommendation/priority_engine.py - Retention rules
src/recommendation/retention_rules.py - Offer selection
src/recommendation/offer_engine.py
AI Assistant
- Retention agent workflow · Stateful orchestration for AI retention assistance.
agent/graph.py - Agent nodes & state
agent/nodes.py - Agent prompts
agent/prompts.py - LLM offer generation
genai/offer_generator.py
Delivery Surfaces
- API service · Request and response contracts are defined in api/schemas.py.
api/main.py - Streamlit dashboards · Executive, risk, recommendation, AI, and model-performance views.
app/streamlit_app.py - Drift monitoring
src/monitoring/drift_monitor.py
Connections 24
- Telco churn data → Data loader: load
- Data loader → Data cleaner: clean
- Data cleaner → Feature engineering: engineer
- Feature engineering → Preprocessing pipeline: transform
- Preprocessing pipeline → Fitted preprocessor: persist
- Preprocessing pipeline → Model training: training features
- Model training → Model evaluation: evaluate
- Model evaluation → Model metrics: record
- Fitted preprocessor → Churn predictor: load
- Churn predictor → Risk interpretation: churn scores
- Risk interpretation → Revenue at risk: risk assessment
- Revenue at risk → Customer prioritization: value at risk
- Customer prioritization → Retention rules: ranked customers
- Retention rules → Offer selection: eligible actions
- Offer selection → Retention agent workflow: deterministic context
- Retention agent workflow → Agent nodes & state: orchestrate
- Agent prompts → Agent nodes & state: instructions
- Agent nodes & state → LLM offer generation: generate assistance
- Churn predictor → API service: serve scoring
- Offer selection → API service: serve recommendations
- Retention agent workflow → API service: serve assistant
- API service → Streamlit dashboards: application data
- Model metrics → Streamlit dashboards: performance views
- Churn predictor → Drift monitoring: inference signals