{"id":50744601,"url":"https://github.com/ash29032006/customer-churn-predictior","last_synced_at":"2026-06-10T19:32:17.964Z","repository":{"id":338364482,"uuid":"1157619807","full_name":"ash29032006/customer-churn-predictior","owner":"ash29032006","description":"End-to-end Machine Learning pipeline to predict customer churn using XGBoost. Includes data preprocessing, class imbalance handling, and model deployment artifacts.","archived":false,"fork":false,"pushed_at":"2026-02-14T05:10:13.000Z","size":3545,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-14T10:52:33.293Z","etag":null,"topics":["churn-prediction","data-science","machine-learning","machine-learning-algorithms","xgboost"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ash29032006.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-14T03:36:42.000Z","updated_at":"2026-02-14T05:10:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ash29032006/customer-churn-predictior","commit_stats":null,"previous_names":["ash29032006/customer-churn-predictior"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ash29032006/customer-churn-predictior","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ash29032006%2Fcustomer-churn-predictior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ash29032006%2Fcustomer-churn-predictior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ash29032006%2Fcustomer-churn-predictior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ash29032006%2Fcustomer-churn-predictior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ash29032006","download_url":"https://codeload.github.com/ash29032006/customer-churn-predictior/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ash29032006%2Fcustomer-churn-predictior/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34168086,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["churn-prediction","data-science","machine-learning","machine-learning-algorithms","xgboost"],"created_at":"2026-06-10T19:32:14.592Z","updated_at":"2026-06-10T19:32:17.960Z","avatar_url":"https://github.com/ash29032006.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Customer Churn Prediction Model\n\n## Project Overview\nThis project implements a machine learning solution to predict customer churn (customers likely to leave a service). It analyzes customer data (demographics, services used, billing info) to identify at-risk users, enabling proactive retention strategies.\n\n## Key Achievements\n- **High Recall for Churners:** Successfully identifies **~76%** of customers who are actually leaving.\n- **Addressed Overfitting:** Reduced the gap between training and testing accuracy from **~19%** to **~7%**, creating a robust, generalizable model.\n- **Handled Imbalanced Data:** Implemented advanced techniques to ensure the model doesn't just bias towards the majority \"Stay\" class.\n\n## Techniques Implemented \n`This project successfully implements all the advanced strategies required for a robust machine learning pipeline`:\n\n### 1. Model Selection\n- **Implementation:** Switched from `RandomForestClassifier` to `XGBoostClassifier`.\n- **Reason:** XGBoost provided better handling of tabular data and built-in regularization, which was crucial for improving model generalization.\n\n### 2. Addressed Overfitting\n- **Implementation:**\n  - Limited tree depth (`max_depth=5`) to prevent memorization.\n  - Used `subsample=0.8` to train on random subsets of data.\n  - Switched to XGBoost for its superior regularization parameters.\n- **Result:** Drastically reduced the Train-Test accuracy gap from **~19%** (High Overfitting) to **~7%** (Good Generalization).\n\n### 3. Hyperparameter Tuning\n- **Implementation:** Used `GridSearchCV` to exhaustively test 36 different combinations of 6 hyperparameters.\n- **Outcome:** Automatically identified the optimal configuration:\n  - `learning_rate`: 0.1\n  - `n_estimators`: 100\n  - `max_depth`: 5\n\n### 4. Stratified K-Fold CV\n- **Implementation:** Used `StratifiedKFold(n_splits=3)` during the Grid Search.\n- **Reason:** Ensuring that every training fold had the exact same percentage of churners (27%) as the full dataset prevented biased training runs.\n\n### 5. Handling Class Imbalance (Alternative to Downsampling)\n- **Implementation:** Instead of \"Downsampling\" (which deletes data), we implemented **Class Weighting** (`scale_pos_weight`).\n- **Reason:** Downsampling reduced accuracy (74%) by discarding 2,600 valid samples. Weighting (giving Churners a 2.77x importance score) allowed us to use **100% of the data** while still achieving high Recall (75%) and higher Accuracy (76%).\n\n## Files in Repository\n- `churn_prediction_xgboost.py`: The main script. Contains everything.\n- `WA_Fn-UseC_-Telco-Customer-Churn.csv`: The dataset.\n- `customer_churn_model_xgboost.pkl`: The saved, trained model (ready for deployment).\n- `encoders.pkl`: Saved encoding rules (required to process new data).\n- `churn_env/`:  Local Python virtual environment\n\n## How to Run\n\n1. **Activate Environment:**\n   ```bash\n   source churn_env/bin/activate\n   ```\n\n2. **Run Script:**\n   ```bash\n   python churn_prediction_xgboost.py\n   ```\n\n3. **Output:**\n   The script will print accuracy metrics, the confusion matrix, and the classification report to the terminal.\n\n## Metrics Explained\n- **Precision (0.53):** When predicting \"Churn\", correct 53% of the time. (Higher false alarms, but necessary for safety).\n- **Recall (0.75):** Correctly identifies 75% of ALL actual churners. (This is the critical metric for retention).\n- **Accuracy (0.76):** Overall correct predictions across both classes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fash29032006%2Fcustomer-churn-predictior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fash29032006%2Fcustomer-churn-predictior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fash29032006%2Fcustomer-churn-predictior/lists"}