Can you recall from our last lesson how we used Seaborn to make our plots more aesthetically pleasing? We'll continue our journey with Seaborn in this lesson, but this time, we'll explore a different type of visualization - histograms.
Histograms are powerful graphical representations that allow us to inspect the underlying frequency distribution (shape) of a continuous or discrete data set. This is particularly useful when we want to visualize the distribution of a variable over a range of values.
Why is understanding the data distribution important, you might ask? In the field of data analytics and statistics, most statistical tests and models assume certain data distribution patterns. Histograms, therefore, are ways for us to validate these assumptions. In other words, knowing our data well sets the stage for more complex analyses later on.
This lesson will take you further into Seaborn's capabilities. We'll cover how to create and customize histograms, offering a sharper lens to inspect our Titanic dataset.
Let's illustrate a histogram using the passenger ages (age) from titanic_df. As we saw in our previous lessons, there were a variety of ages amongst the passengers that should make for an interesting distribution.
Seaborn provides a function called histplot for creating histograms. Here's the basic syntax:
In the code snippet above, we are telling Seaborn to look at the age column from our titanic_df DataFrame, and the kde=True part is there also to draw a curve of Kernel Density Estimation (KDE) that estimates the probability density function of the variable age (more on this shortly).
This delivers a histogram that shows the distribution of passenger ages. The x-axis represents the ages, and the y-axis represents the number of passengers with ages within the corresponding bin of the histogram.

You may wonder what the smooth, continuous line overlaying our histogram represents. This smooth line, created by turning on the kde parameter in histplot, is a Kernel Density Estimate (KDE) plot that provides a smooth estimate of our distribution.
The KDE is useful when we want to derive a smooth, continuous function from our discrete observations. Often, this can make the output much more interpretable, aiding in the presentation of our data. However, remember that KDEs are just estimates. The true distribution of your data may be different, especially if you have a small number of observations.
Here is one more example of using KDE in action!

As you can see, the KDE gives us a smooth curve that fits our observations, providing a pleasing and easy-to-understand representation of our distribution.



