This project demonstrates a full-scale machine learning pipeline to predict customer churn using Python, scikit-learn, XGBoost, and MLflow. It includes data ingestion, validation, transformation, model training, evaluation, and deployment via FastAPI.
โ
Modularized ML Pipeline using OOP & Configurations
โ
Automated Logging via Python's logging and MLflow
โ
Baseline model comparison (RandomForest, XGBoost, LogisticRegression, etc.)
โ
Advanced metrics: Top-Decile Lift, Overfitting Warning
โ
SHAP-based model explainability
โ
FastAPI for real-time inference API
Churn_Pred/
โโโ components/ # Data ingestion, validation, transformation modules
โโโ entity/ # Artifact data classes
โโโ logger/ # Logging module
โโโ exception/ # Custom exception handling
โโโ utils/ # Utility functions
โโโ artifacts/ # Outputs: models, reports, metrics
โโโ app/ # FastAPI app for deployment
โโโ main.py # Training pipeline entry point
โโโ mlruns/ # MLflow tracking
โโโ README.md
๐ฆ Data Ingestion โ โ
Validation โ ๐ Transformation โ ๐ง Model Training โ ๐ Evaluation โ ๐ FastAPI- Reads raw data and drops irrelevant columns (e.g., IDs, names)
- Splits into training and test sets
- Checks schema consistency, missing values, and data drift
- Ensures all required columns are present
- Applies
ColumnTransformerpipelines for numeric and categorical features - Saves:
.npyarrays (for model training).csvDataFrames (for debugging)preprocessor.pkl(for deployment reuse)
- Trains baseline models (RandomForest, XGBoost, LogisticRegression, etc.)
- Evaluates using:
- Tracks all experiments via MLflow
- Selects and saves the best-performing model
- Exposes real-time inference endpoint using FastAPI
- API UI available at:
http://localhost:8000/ - Can be containerized via Docker for scalable deployment
- Accuracy, F1 Score, Precision, Recall
- ROC AUC
- Cross-validation F1 score (mean & std)
- Top-Decile Lift
- Overfitting/Underfitting Warnings
pip install -r requirements.txtpython main.pyuvicorn app:app --reloadAccess App at: http://localhost:8000
- Metrics, plots, confusion matrices
- Trained models stored in:
artifacts/model_trained - MLflow dashboard:
http://localhost:5000(in terminalmlflow ui)
-
Open a terminal (or command prompt).
-
Navigate to your project folder (e.g.,
Churn_Pred). -
Run the command:
mlflow ui
- Open a browser and go to http://localhost:5000

- This will open the MLflow UI where you can see all of your logged experiments, parameters, metrics, and models.
SMOTETomek is a powerful tool to address class imbalance by both increasing the minority class size and cleaning up the dataset by removing noisy or borderline examples. By doing so, it enables models to perform better in imbalanced settings, leading to improved generalization and more accurate predictions. It is especially useful in tasks like fraud detection, medical diagnosis, and anomaly detection where minority class instances are critical for model performance but are often underrepresented.
The best model after hypertuning was XgBoost is selected based on F1 Score = 0.621, Test Accuracy: 0.85, Train Accuracy: 0.857, ROC AUC: 0.859 , Training time ~40 sec and saved for deployment.
- Arabic language support for UAE telecom market (bilingual churn signals)
- Real-time Kafka stream ingestion replacing batch CSV pipeline
- Survival analysis model (time-to-churn, not just binary churn)
- Customer segmentation clustering + per-segment churn model
- A/B testing framework for retention intervention strategies
Rohit Dusane โ ML Engineer & Healthcare AI Specialist ๐ง hello@rohitdusane.dev ๐ผ LinkedIn ๐ Portfolio




