Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Predict At-Risk Customers | Customer Health and Churn Prediction
Python for Customer Success Managers
Seksjon 2. Kapittel 5
single

single

bookChallenge: Predict At-Risk Customers

Sveip for å vise menyen

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.

123456789101112131415161718
import 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)
copy

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.

Oppgave

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, and feature_usage as input features.
  • Fit a logistic regression model to predict the churn label.
  • 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.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 5
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

some-alt