Python Tutorial: Exploring your data using visualizations

Learn to visualize a telecom dataset with Seaborn to explore customer churn. The tutorial covers histograms to check if account length is normally distributed, box plots to compare churners and non-churners, and how to add a third variable like International Plan to see if it affects churn.
Chapters
One of the most important parts of the EDA workflow is data visualization. It helps you better understand your data and allows you to effectively communicate insights to technical and non technical stakeholders alike. In Python, the Seaborn library allows you to easily create informative and attractive plots. It builds on top of matplotlib, which you may have seen in other courses. Here we'll use Seaborn let's say you wanted to visualize the distribution of the account lengths of your customers. Many machine learning algorithms make assumptions about how the data is distributed, so it's important to understand how the variables in your own data set are distributed before you apply those algorithms. A histogram is an effective way to visualize the distribution of a variable, and you can create one using Seaborn's diskplot function, which is short for distribution plot. First import Seaborn, then pass in the account length feature of the Telco dataframe to the diskplot function. Remember to call Plot show to display the plot. You can see here that it resembles a bell curve, also known as the normal distribution. It turns out that many things we measure in the real world are well approximated by the normal distribution, and many models actually make the assumption that your data is normally distributed. Let's now visualize the differences in account length between Churners and non churners. An effective way to do this is using a box plot, which you can create using Seaborn's boxplot function by specifying the x, y and data parameters as shown here. As you can see, there doesn't appear to be any noticeable difference in account length. The line in the middle of each box represents the median. The colored boxes represent the middle 50% of the account lengths for each group. The values here range from the 25th to the 75th percentile and give a sense of the spread of the distribution. The floating points represent outliers which you can remove using the sym parameter as shown here. Seaborn allows you to easily add a third variable to your plot. For example, we might be interested in visualizing whether the International Plan feature has an impact on account length or Churn. You can add this information to the plot by specifying the hue parameter from the plot. It looks like as far as Predict and Churn goes, it does not matter whether or not a customer had an international plan. In the exercises you will visualize the distributions of other features and investigate their influence on Churn Happy.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







