Visualizing PredictHealth's Customer Profiles
Introduction And Lesson Objectives
Welcome back! In the previous lesson, you learned how to load, inspect, and filter the PredictHealth insurance dataset using Python. These foundational skills are essential for any data analysis project. Now, we will take the next step by exploring how to visualize this data. Visualizing customer profiles is a powerful way to uncover patterns, spot trends, and communicate insights that might be hidden in raw numbers. In the context of health insurance, visualizations can help us understand how different factors — such as age, gender, region, and smoking status — affect insurance charges.
In this lesson, you will learn how to create several types of visualizations using real data from PredictHealth. We will build histograms, bar charts, scatter plots, and boxplots to explore the distribution of insurance charges and compare different customer groups. By the end of this lesson, you will be able to use these visual tools to gain a deeper understanding of customer behavior and prepare for more advanced analysis.
Setting Up The Visualization Environment
To make our plots look clean and professional, we will set an aesthetic style using Seaborn's set_style function. We will also define the size of our figures using Matplotlib's figure function. This helps ensure that our charts are easy to read and visually appealing.
Here is how you can set up your visualization environment:
Let's break down the visualization setup:
sns.set_style('whitegrid'): This sets a clean white background with subtle grid lines, making our plots easier to read. Other options include 'darkgrid', 'white', 'dark', and 'ticks'plt.figure(figsize=(15, 10)): This creates a new figure with a width of 15 inches and height of 10 inches, ensuring our plots are large enough to see clearly
By running this code, you prepare your canvas for all the visualizations we will create in this lesson.
Visualizing The Distribution Of Insurance Charges
Let's start by exploring how insurance charges are distributed across all customers. A histogram is a great tool for this because it shows how many customers fall into different charge ranges. This helps you see if most people pay similar amounts or if there are a few who pay much more or less.
Here is how you can create a histogram of insurance charges:
Let's examine each part of this histogram code:
plt.hist(): This is the main function that creates a histograminsurance_data['charges']: This selects the 'charges' column from our dataset as the data to plotbins=30: This divides the range of charge values into 30 equal-width intervals. More bins give finer detail, fewer bins show broader patternscolor='skyblue': This sets the fill color of the histogram bars to a light blueedgecolor='black': This adds black borders around each bar, making them easier to distinguishplt.title(): This adds a descriptive title at the top of the plotplt.xlabel()andplt.ylabel(): These label the x and y axes so viewers understand what the plot representsplt.show(): This displays the completed plot

The result is a bar-like plot that shows the frequency of different charge amounts. For example, you might see that most customers have charges below $20,000, but there are some with much higher charges. This kind of visualization helps you quickly understand the spread and shape of the data, such as whether it is skewed or has outliers.




