SwiftTel is a prepaid mobile operator. When a customer stops recharging (churns), the revenue is gone, and winning a new customer costs much more than keeping an old one.
The retention team can call only a limited number of customers each week with an offer. They have 500 subscribers from last quarter and know who churned. They want a model that ranks customers by churn risk, so the calls go to the right people.
Goal: Predict churned (Yes / No) and rank customers by the chance of churning. Random Forest, many decision trees voting together, is a strong choice for this kind of table data.
500 subscribers, one row each.
| customer_id | tenure_months | monthly_recharge | data_gb | support_calls | dropped_call_pct | family_plan | churned |
|---|---|---|---|---|---|---|---|
| 9001 | 11 | 239 | 11 | 0 | 4.6 | No | No |
| 9002 | 24 | 499 | 16 | 0 | 2.4 | No | No |
| 9003 | 9 | 299 | 14 | 2 | 2.4 | No | No |
| 9004 | 39 | 399 | 3 | 2 | 5.9 | Yes | No |
| 9005 | 3 | 149 | 8 | 0 | 6.6 | No | Yes |
| 9006 | 68 | 299 | 11 | 4 | 8.6 | No | No |
First 6 of 500 rows · realistic practice data
Press Run on each step in order, or run them all at once. You can change any code and run it again.
Starting Python…
Look at the data and the share of customers who churned.
Turn Yes / No into 1 / 0. Trees and forests do not need scaling, so the numbers can stay as they are.
A single deep decision tree is the baseline. Note its train and test scores: one tree usually memorises the training customers.
A Random Forest trains many trees. Each tree sees a random sample of customers (bootstrap) and a random few columns at each split. Their mistakes are different, so when they vote, the mistakes cancel out. That is why a forest usually beats one tree on new data.
More trees make the vote steadier, but after some point the score stops improving and the model just gets slower. Look for where the line goes flat.
The classification report shows precision and recall for each class. ROC-AUC checks the ranking itself: the chance that a random churner gets a higher risk score than a random loyal customer. 0.5 is guessing, 1.0 is perfect. For a call list, the ranking is what matters.
The forest adds up how much each column helped all its trees. This tells the business where to act, for example fixing the network in areas with many dropped calls.
Score every test customer and sort by risk. The top of this list is who the retention team should call first. Then check: how many of the top 20 really churned?
20 questions on new data. You write the code; hints point the way without giving it.