
Customer Churn Prediction
Overview
This project demonstrates an end-to-end machine learning pipeline for predicting customer churn. It utilizes a Streamlit web application to showcase each phase, from data loading and exploratory data analysis to model training, evaluation, and interpretation. The primary goal is to identify customers at high risk of leaving, enabling businesses to implement targeted retention strategies. By understanding the factors that drive churn, companies can reduce revenue loss and enhance customer satisfaction.
The application uses the "Telco Customer Churn" dataset, which includes customer demographics, account information, subscribed services, and charges. The workflow presented in the application includes:
Introduction: Overview of the project, its importance, and the dataset used.
Data Loading & Initial Inspection: Loading the raw data and performing initial checks on its structure, data types, and missing values. This involved handling issues like the 'TotalCharges' column being initially read as an object type and converting it to numeric, revealing missing values for new customers (tenure = 0).
Exploratory Data Analysis (EDA): Visualizing data to uncover patterns, such as the bimodal distribution of tenure and the right-skewed nature of 'TotalCharges'. Key insights included that customers on month-to-month contracts with high monthly charges and fewer additional services were more prone to churn. The EDA also confirmed the dataset was imbalanced, with significantly fewer churners than non-churners.
Feature Engineering & Processing: Cleaning data (e.g., imputing missing 'TotalCharges' with 0, dropping 'customerID') and creating new informative features. Examples include 'TenureGroup', 'NumOptionalServices', and interaction features like 'Tenure_x_Monthly'. The target variable 'Churn' was also numerically encoded.
Data Splitting: Dividing the data into training (80%) and testing (20%) sets, using stratification to maintain the churn proportion in both.
Preprocessing: Applying
StandardScalerto numerical features andOneHotEncoderto categorical features using a Scikit-learnPipelineandColumnTransformer.Model Selection & Training: Training various classification algorithms (Logistic Regression, Random Forest, XGBoost, LightGBM). This included addressing class imbalance using SMOTE and class weights, and tuning hyperparameters with
RandomizedSearchCV.Model Evaluation: Assessing model performance on the unseen test set using metrics like accuracy, ROC AUC, classification reports, and confusion matrices.
Ensemble Model (Optional): Exploring a Voting Classifier combining predictions from top individual models.
Interpretation (SHAP): Using SHAP (SHapley Additive exPlanations) to understand the predictions of the best-performing individual model, identifying key drivers for churn.
Conclusion: Summarizing the project, key results, business value, and perspectives from Solutions Architect and Machine Learning Engineer standpoints.
Challenges & Solutions
Handling Missing Data: The 'TotalCharges' column had missing values for customers with zero tenure, which required careful imputation (filled with 0).
Class Imbalance: The dataset was imbalanced, with a smaller proportion of customers churning. This necessitated strategies like SMOTE and class weighting during model training to ensure the model could effectively learn patterns from the minority class.
Feature Engineering: Creating meaningful features that capture complex customer behaviors and interactions to improve model performance.
Model Interpretation: While SHAP provides powerful insights, its calculation (especially KernelExplainer for some models) can be time-consuming and computationally intensive, requiring strategies like data subsampling for the Streamlit application. Ensuring correct preprocessing for SHAP explainers and handling different SHAP value output structures was also a consideration.
Artifact Management: Ensuring all necessary model artifacts (preprocessor, models, evaluation results, column names) were correctly saved and loaded within the Streamlit application for each step. The application includes caching mechanisms (
st.cache_resource,st.cache_data) to optimize loading.
Outcomes
Predictive Model: A validated machine learning model capable of predicting customer churn with quantifiable accuracy. The project selected a final model (e.g., 'LightGBM with SMOTE' or another based on evaluation) that demonstrated strong predictive capability on unseen test data. For example, results mentioned an accuracy of around 80.4% and an ROC AUC of approximately 0.84 for a selected model.
Actionable Insights: The project provides insights into key drivers of churn through EDA and SHAP analysis. For instance, month-to-month contracts, higher monthly charges, and lack of services like online security or tech support were identified as significant factors influencing churn.
Interactive Showcase: A Streamlit application that clearly demonstrates each step of the machine learning workflow, making the process transparent and understandable.
Business Value Demonstration: The project highlights the strategic impact of churn prediction, including reduced revenue loss, improved Customer Lifetime Value (CLTV), enhanced customer experience through understanding pain points, and optimized resource allocation for retention efforts.
Operationalization Framework: The conclusion outlines perspectives for integrating such a model into a business environment, considering deployment strategies (API, batch scoring), system integration, scalability, monitoring, and the overall MLOps lifecycle (model retraining, drift detection, CI/CD).