Generate a Churn Risk Report
Advanced · Write the code · from Predict Customer Churn: End-to-End Data Analysis (with sklearn)
From the lesson: Step 7: Identify At-Risk Customers
The real business value isn't just knowing that churn happens - it's knowing who is most likely to churn and why. We can use the model's predicted probabilities to rank customers by risk and generate actionable insights for the retention team.
Read this part of the lessonUsing model.predict_proba(), get the churn probability for each customer. Add it as a churn_risk column to the original DataFrame. Then:
1. Sort by churn_risk descending.
2. Print "=== CHURN RISK REPORT ===" as a header.
3. Print the top 5 at-risk customers showing customer_id, tenure_months, monthly_charges, contract, and churn_risk (formatted to 2 decimal places).
4. Print a summary: "High risk customers (>70%): N" with the count.
More Churn Prediction exercises
- Build the Customer DataFrameAdvanced
- Exploratory Data AnalysisAdvanced
- Engineer New FeaturesAdvanced
- Encode and Scale FeaturesAdvanced
- Train a Logistic Regression ModelAdvanced
- Build a Confusion MatrixAdvanced
All Python exercises · 50 practice problems · Practical Projects quiz