Machine Learning · Classification

Customer Churn Prediction

End-to-end ML case study for predicting telecom customer churn using the Telco Customer Churn dataset. A probability-based classification workflow designed to support retention strategy, threshold tuning, and business intervention.

Telco ChurnBinary ClassificationProbability ScoringRetention StrategyCase Study
0.84ROC-AUC for ranking churn risk
0.78Recall for catching at-risk users
MLFull pipeline from preprocessing to action

On this page

Overview

Why this project matters

Churn prediction helps revenue teams move from reactive reporting to proactive retention. By ranking customers by churn probability, the business can prioritize outreach, design targeted interventions, and improve marketing efficiency.

Targets customers before cancellation rather than after revenue loss.
Uses probability-based scoring to support threshold selection and campaign prioritization.
Connects model performance to concrete business actions instead of stopping at evaluation metrics.
Stack

Implementation profile

The project is framed as a production-ready ML workflow rather than a notebook-only experiment.

PythonData processing, training, evaluation
Scikit-learnBaseline and candidate models
FastAPI-readyBackend serving layer for inference
Business context

Understanding churn as a business signal

Churn is when a customer stops using a company's service. In telecom, that usually means contract cancellation or a switch to a competitor. Retention is often cheaper than acquisition, so identifying at-risk users early has direct business value.

What is churn?

Loss of an active customer relationship, typically visible as cancellation or non-renewal.

Why churn matters

High churn weakens revenue stability and may signal pricing, service, or product issues.

Retention vs acquisition

Retaining an existing user is often lower cost than winning a new one through marketing spend.

Dataset

Telco Customer Churn dataset

A public, portfolio-safe churn dataset containing customer account, service, and billing information.

Target

Churn — binary indicator of whether the customer left during the observation period.

Customer / account

Customer ID, tenure, contract type, and related account-level signals.

Services

Phone, internet, streaming, security, support, and bundled service usage patterns.

Billing

Paperless billing, payment method, monthly charges, and total charges.

Problem framing

Binary classification with probability output

The model predicts churn vs retained, but the more operationally useful output is a churn probability so thresholds can be tuned for cost-sensitive intervention.

Positive class = churn, the event that matters for intervention.
Probability outputs support risk ranking and segment-based action plans.
Thresholds can be adjusted to favor recall when missing a churner is expensive.
Data preprocessing

Preparing the dataset for stable modeling

Preprocessing turns raw account and service data into a reliable supervised learning matrix while controlling for leakage, missing values, scaling issues, and categorical representation.

1

Missing values

Dropped or imputed fields such as total charges for very new customers so no NaNs remained at training time.

2

Categorical encoding

One-hot encoding for contract type, payment method, and other service-related categoricals.

3

Feature cleaning

Invalid rows removed, numeric values checked for range issues, and data integrity validated before training.

4

Train / test split

Separated evaluation data to measure generalization and avoid overestimating model quality.

5

Scaling

Numeric features such as tenure and charges normalized or standardized where appropriate.

Feature engineering

Signals that matter for churn risk

Churn behavior is often shaped by loyalty duration, service bundle complexity, contract commitment, billing friction, and overall engagement. These drivers are translated into usable model features.

Tenure-based

Tenure in months, tenure bands, and tenure-squared to capture non-linear loyalty effects.

Service count

Number of active services to capture bundle stickiness and overall product dependence.

Contract signals

Month-to-month vs one/two-year contract and derived short-term commitment flags.

Billing & payment

Monthly charges, total charges, payment method, and paperless billing as friction indicators.

Modeling strategy

Choosing a model with business trade-offs in mind

A simple baseline establishes the performance floor, then candidate models compete on ranking quality, recall, interpretability, and operational constraints.

Baseline

Logistic regression or a majority-class predictor validates that the problem is learnable.

Candidate models

Logistic Regression, Random Forest, and Gradient Boosting cover the spectrum from interpretability to higher AUC.

Selection logic

Final model chosen based on cross-validated ROC-AUC, recall at business thresholds, and explainability needs.

Trade-offs

Interpretability vs raw predictive power

Logistic regression is fast and easy to explain. Tree-based models often deliver stronger ranking performance, but require additional interpretation layers such as feature importance or SHAP-style analysis.

Use interpretable baselines to validate intuition and feature direction.
Use ensemble models when uplift in ROC-AUC and recall is worth extra complexity.
Probability calibration becomes important when decisions depend on risk thresholds.
Evaluation metrics

How performance is interpreted

Because churn is often imbalanced, one metric is not enough. This case study emphasizes ranking ability, precision-recall balance, and threshold-aware decision support.

ROC-AUC · 0.84Good ranking quality across thresholds
PrecisionHow many predicted churners actually churn
Recall · 0.78How many actual churners are successfully caught
F1 ScoreBalance between precision and recall
Recall is especially important when missing an at-risk customer means lost retention opportunity.
Precision matters when interventions are expensive and false positives create wasted campaign cost.
ROC-AUC helps compare models before the business has locked in one operating threshold.
Visual analysis

Feature importance and performance views

Feature importance surfaces which business drivers contribute most to churn, while ROC and confusion matrix views make model behavior easier to inspect.

Contract (monthly)
24%
Tenure
19%
Total charges
14%
Internet service
12%
Payment method
9%
ROC curve

Threshold-free ranking view

ROC plots true positive rate vs false positive rate across thresholds. AUC summarizes overall separability before a business decision threshold is chosen.

ROC curve placeholderReal chart can be wired later through your frontend chart component
Confusion matrix

Error structure at the chosen threshold

Confusion matrix analysis shows where the model succeeds and where it makes costly mistakes, especially false negatives that hide real churners.

TNCorrectly retained
FPIncorrect churn alert
FNMissed churner
TPCorrectly flagged churn
System architecture

How the prediction workflow is wired

This case study is designed as a real application flow: frontend, API, prediction service, model inference, and structured JSON response.

1

Frontend case study page

The user reads the case study and interacts with the future prediction UI in the same flow.

2

FastAPI backend

REST API exposes health endpoints and a prediction route that accepts customer/account features.

3

Churn service

Service layer loads the trained model, runs inference, and structures the prediction payload.

4

Model inference

Saved model consumes the feature vector and returns churn probability plus optional risk segmentation.

5

Prediction response

JSON response includes predicted label, probability, and supporting output for UI rendering.

Business recommendations

What the business can do with the model

A churn model is most valuable when it changes actions. The output should drive campaign prioritization, offer targeting, and channel optimization rather than remain a passive dashboard number.

Prioritize highest-risk accounts

Focus retention spend on customers with the strongest churn probability instead of broadcasting generic campaigns.

Target month-to-month users

Tailor offers and support outreach to short-term contracts where switching risk is usually higher.

Intervene earlier

Lower-tenure, high-risk users can be reached before dissatisfaction becomes permanent churn behavior.

Use risk segments operationally

Low / medium / high bands help assign channels, offer intensity, and campaign budget rationally.

Live prediction

Interactive churn risk preview

Enter customer/account features and run a portfolio-style prediction. This prototype UI is designed to mirror the future backend integration and help users understand how the model could be consumed in a product setting.

Prediction result

Submit the form to estimate churn probability, assign a simple risk band, and highlight the top contributing signals.

Predicted probability
Predicted labelNo result yet
Top contributing factorsContract, tenure, monthly charge, internet service
Awaiting prediction