Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Challenge: Predict At-Risk Customers | Customer Health and Churn Prediction
Practice
Projects
Quizzes & Challenges
Quiz
Challenges
/
Python for Customer Success Managers
Sezione 2. Capitolo 5
single

single

bookChallenge: Predict At-Risk Customers

Scorri per mostrare il 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.

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.

Compito

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.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 5
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

some-alt