How dhavaldalvi/customer-churn-prediction works
Project type and purpose
• This is a full-stack web application (Flask) whose primary purpose is to predict customer churn using machine learning.
• The README confirms it provides a web UI for users to input customer features, runs a ML model pipeline, and returns a churn probability.
File structure
• Top level:
• app.py – Flask application entry point with routes for “home” and “result.”
• setup.py, requirements.txt – packaging and dependencies.
• artifacts/, data/ – local file-system stores for raw, train, test CSVs and model outputs.
• notebook/ – exploratory analysis and training notebooks (offline).
• src/customer_churn_prediction:
• components/
– data_ingestion.py
– data_transformation.py
– model_trainer.py
• pipelines/
– training_pipeline.py
– prediction_pipeline.py
• config.py, exception.py, logger.py, utils.py
• templates/ + static/ – HTML/CSS UI layers.
README for additional insights
• Confirms use of Flask, Scikit-learn, Pandas, NumPy.
• Explains that on startup the app runs model training to select the best model, then serves the web UI.
a. Main components:
1. User & Browser (Frontend)
2. Flask Web Server (app.py/routes)
3. Templates & Static assets (UI layer)
4. Prediction Pipeline (src/.../prediction_pipeline.py)
5. Training Pipeline (src/.../training_pipeline.py) – runs at startup
6. Components Layer:
– Data Ingestion
– Data Transformation
– Model Trainer
7. File-System Data Store:
– artifacts/raw_data.csv
– artifacts/train_data.csv
– artifacts/test_data.csv
– model artifact (.pkl)
b. Relationships & interactions:
• User → Browser → HTTP request to Flask route (GET home.html / POST form data)
• Flask route invokes Prediction Pipeline
• Prediction Pipeline calls Data Ingestion (loads CSV or form payload), Data Transformation (feature engineering), loads persisted model from artifacts, returns prediction
• Flask returns result.html populated with churn probability
• On startup, Flask app invokes Training Pipeline which:
• Ingests raw data from data/Churn_Modelling.csv or artifacts/raw_data.csv
• Transforms data
• Trains multiple models via Model Trainer
• Selects best model and writes .pkl to artifacts
c. Architectural patterns & principles
• Layered architecture:
• Presentation (Flask + Jinja templates + static CSS)
• Application (Flask controllers + pipelines)
• Domain/Service (components: ingestion, transformation, training)
• Infrastructure (file-system storage of CSVs and model artifacts)
• Single-responsibility per component, separation of concerns.
d. Technologies/frameworks:
• Flask (web layer)
• Scikit-learn (model training & inference)
• Pandas & NumPy (data handling)
• Jinja2 (templating)
• Plain CSV files as storage
Elements
• From User to Browser to Flask (GET/POST)
• From Flask to Prediction Pipeline to Components to Artifacts to Flask to Browser
• From Flask on startup to Training Pipeline to Components to Artifacts
• Blue for “Frontend/UI”
• Green for “Backend/Application”
• Yellow for “Service/Domain Components”
• Gray for “Storage/Artifacts”
Final advice
• Be very detailed: capture both the one‐time training flow and the recurring prediction flow.
• Avoid over-abstraction: instead of a single “ML Service,” expose Data Ingestion, Transformation, Trainer modules to show the responsibilities clearly.