Visualizing Health Scores and Risk Levels
Swipe to show menu
Visualizing customer health scores and risk levels is essential for understanding which customers are thriving and which may require extra attention. Using Python's matplotlib library, you can create clear, insightful plots that display each customer's health score and highlight those who are at risk. Visualization techniques such as scatter plots allow you to quickly spot patterns, clusters, and outliers within your customer base. By assigning different colors to various risk categories, you make it much easier to identify trends and take action where needed.
1234567891011121314151617import matplotlib.pyplot as plt # Sample customer data customer_ids = ["C001", "C002", "C003", "C004", "C005", "C006", "C007", "C008"] health_scores = [85, 40, 78, 65, 30, 92, 55, 47] risk_levels = ["Healthy", "At Risk", "Healthy", "Healthy", "At Risk", "Healthy", "At Risk", "At Risk"] # Assign colors based on risk level colors = ["red" if r == "At Risk" else "green" for r in risk_levels] plt.figure(figsize=(8, 5)) plt.scatter(customer_ids, health_scores, c=colors, s=100) plt.xlabel("Customer ID") plt.ylabel("Health Score") plt.title("Customer Health Scores with Risk Highlighted") plt.ylim(0, 100) plt.show()
When interpreting the scatter plot above, you can quickly see which customers fall into the At Risk category by their red color. Clusters of red points indicate groups of customers with low health scores who may require immediate attention. Outliers, such as a single customer with a very low or very high score, can also be identified easily. This visual approach helps you spot trends, focus on problem areas, and prioritize engagement strategies.
12345678910111213141516171819202122232425262728import matplotlib.pyplot as plt customer_ids = ["C001", "C002", "C003", "C004", "C005", "C006", "C007", "C008"] health_scores = [85, 40, 78, 65, 30, 92, 55, 47] risk_levels = ["Healthy", "At Risk", "Healthy", "Healthy", "At Risk", "Healthy", "At Risk", "At Risk"] colors = ["red" if r == "At Risk" else "green" for r in risk_levels] plt.figure(figsize=(8, 5)) scatter = plt.scatter(customer_ids, health_scores, c=colors, s=100, label=risk_levels) # Add labels for each point for i, txt in enumerate(customer_ids): plt.annotate(txt, (customer_ids[i], health_scores[i]), textcoords="offset points", xytext=(0,10), ha='center') # Add custom legend from matplotlib.lines import Line2D legend_elements = [Line2D([0], [0], marker='o', color='w', label='At Risk', markerfacecolor='red', markersize=10), Line2D([0], [0], marker='o', color='w', label='Healthy', markerfacecolor='green', markersize=10)] plt.legend(handles=legend_elements, title="Risk Level") plt.xlabel("Customer ID") plt.ylabel("Health Score") plt.title("Customer Health Scores with Labels and Legend") plt.ylim(0, 100) plt.show()
1. What does a cluster of low health scores indicate?
2. How can color-coding help in visualizing risk levels?
3. Which matplotlib function is used to add a legend to a plot?
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat