single
Challenge: Predict At-Risk Customers
Swipe to show menu
Predicting which customers are at risk of churning is a cornerstone of proactive Customer Success management. By identifying these customers early, you can focus your efforts on retention strategies, ultimately reducing revenue loss and improving satisfaction. Using Python and machine learning, you can automate this process and make data-driven decisions that support your team's goals.
123456789101112131415161718import pandas as pd # Hardcoded customer engagement data data = [ {"customer_id": "C001", "login_frequency": 15, "support_tickets": 1, "feature_usage": 7, "churn": 0}, {"customer_id": "C002", "login_frequency": 3, "support_tickets": 4, "feature_usage": 2, "churn": 1}, {"customer_id": "C003", "login_frequency": 10, "support_tickets": 2, "feature_usage": 5, "churn": 0}, {"customer_id": "C004", "login_frequency": 1, "support_tickets": 6, "feature_usage": 1, "churn": 1}, {"customer_id": "C005", "login_frequency": 8, "support_tickets": 0, "feature_usage": 6, "churn": 0}, {"customer_id": "C006", "login_frequency": 2, "support_tickets": 5, "feature_usage": 2, "churn": 1}, {"customer_id": "C007", "login_frequency": 12, "support_tickets": 1, "feature_usage": 8, "churn": 0}, {"customer_id": "C008", "login_frequency": 4, "support_tickets": 3, "feature_usage": 3, "churn": 1}, {"customer_id": "C009", "login_frequency": 9, "support_tickets": 2, "feature_usage": 7, "churn": 0}, {"customer_id": "C010", "login_frequency": 5, "support_tickets": 4, "feature_usage": 2, "churn": 1}, ] df = pd.DataFrame(data) print(df)
To build an effective churn prediction model, you first need to prepare your data by selecting relevant features (such as login frequency, support tickets, and feature usage) and separating them from the churn label. You will use scikit-learn's LogisticRegression to fit the model on your dataset. After training, you can evaluate the model's accuracy by comparing its predictions to the actual churn labels. The model's predicted probabilities will help you interpret which customers are most at risk: higher probabilities indicate greater risk of churn. By listing these customers and their risk scores, you gain actionable insights for targeted intervention.
Swipe to start coding
You are provided with a hardcoded customer dataset containing engagement metrics and a churn label. Your task is to implement a Python function that builds a logistic regression model to predict customer churn. The function should:
- Use the columns
login_frequency,support_tickets, andfeature_usageas input features. - Fit a logistic regression model to predict the
churnlabel. - Calculate and store the accuracy of the model on the dataset.
- Identify customers whose predicted probability of churn is 0.5 or higher, and associate each with their churn probability.
- Print the model's accuracy.
- Print the list of at-risk customers and their predicted churn probabilities.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat