This machine learning project predicts customer churn using a Random Forest Classifier.
The goal is to identify customers who are likely to leave based on behavioral and demographic data.
churn_prediction/
│
├── data/ # Dataset files (ignored in repo)
│ └── generate_data.py # Script to generate sample data
│
├── models/ # Trained model files (ignored in repo)
│
├── notebooks/ # Jupyter notebooks for analysis
│ └── churn_analysis.ipynb
│
├── src/ # Source code modules
│ ├── data_preprocessing.py
│ ├── model_training.py
│ ├── utils.py
│ └── __init__.py
│
├── main.py # Main execution script
├── predictions.csv # Sample predictions output
├── requirements.txt # Python dependencies
└── README.md
Make sure you have Python 3.8+ installed.
Then install all dependencies:
pip install -r requirements.txtTo run the full prediction pipeline:
python main.pyOr train and test the model manually:
python src/model_training.py
python main.py # Generates predictions.csv| File | Description |
|---|---|
data_preprocessing.py |
Handles data cleaning and encoding |
model_training.py |
Trains and evaluates the Random Forest model |
utils.py |
Utility functions for predictions |
main.py |
Runs the full churn prediction pipeline |
Model: RandomForestClassifier (n_estimators=100, max_depth=15)
Evaluation on Test Set:
- Accuracy: 0.912
- Precision: 0.89
- Recall: 0.87
- F1-score: 0.88
- ROC-AUC: 0.94
You can reproduce these results using:
python src/model_training.pyThe predictions are saved to:
predictions.csvThe output file predictions.csv contains churn probabilities for each customer.
Example:
| Customer_ID | Churn_Probability |
|---|---|
| 1001 | 0.12 |
| 1002 | 0.84 |
| 1003 | 0.45 |
The dataset (customer_churn.csv) and trained model (churn_model.pkl) are not included in this repository to keep it lightweight.
You can generate them yourself by following these steps:
-
Generate synthetic data
python data/generate_data.py
This creates
data/customer_churn.csv. -
Train the model
python src/model_training.py
This saves the trained model as
models/churn_model.pkl. -
Run predictions
python main.py
This creates a
predictions.csvfile with churn probabilities.
This project is open-source and available under the MIT License.
Sarim Shah — GitHub: @ssarimm