๐ฎ Customer Churn Prediction
This project predicts customer churn (likelihood of a customer leaving a bank) using machine learning. It combines data analysis, feature engineering, classification models, and deployment through both Flask API and Streamlit UI.
๐ Features
๐ Exploratory Data Analysis (EDA): heatmaps, distributions, churn insights
๐ Feature Engineering: log transformations, interaction terms, binning
๐ค Machine Learning Models: Logistic Regression, Decision Tree, KNN
โก Model Pipelines: preprocessing + training with scikit-learn
๐พ Model Persistence: trained model saved as churn_model.pkl
๐ Flask API: REST endpoint for churn prediction (/predict)
๐ Streamlit UI: user-friendly interface to input customer details and predict churn
โ๏ธ Imbalance Handling: SMOTE + class weighting for better recall
๐ ๏ธ Tech Stack
Python 3.9+
Pandas โ data handling
Matplotlib , Seaborn โ visualization
Scikit-learn โ ML models & pipelines
Imbalanced-learn โ SMOTE for imbalance
Joblib โ model saving
Flask โ API deployment
Streamlit โ interactive dashboard
๐ Installation & Setup
Clone the repository
git clone https://github.com/your-username/churn-prediction.git cd churn-prediction
Install dependencies
pip install -r requirements.txt
Run EDA / Training script
python project.py
Run Flask API
python app.py
Visit โ http://127.0.0.1:5000
Example API request:
curl -X POST http://127.0.0.1:5000/predict -H "Content-Type: application/json"
-d '{"CreditScore":600,"Geography":"France","Gender":"Male","Age":40,"Tenure":5,
"Balance":60000,"NumOfProducts":2,"HasCrCard":1,"IsActiveMember":1,"EstimatedSalary":50000}'
Run Streamlit App
streamlit run app_streamlit.py
Visit โ http://localhost:8501
๐ Model Evaluation
Metrics used: Accuracy, AUC, Confusion Matrix, Precision-Recall
Threshold tuning for better balance between precision & recall
Visual outputs: ROC & Precision-Recall curves