Data analysis and preparation

As you may notice by looking at the data, there are a few things we need to do before we can start building machine learning models. In this section, we are going to transform continuous variables that have monetary values and encode the target variable, Churn, as well as other categorical variables. To do so, perform the following steps:

  1. Target variable encoding: As you may have noticed from the data, the target variable, Churn, has two values: Yes and No. We are going to encode these values as 1 for Yes and 0 for No. The code to encode the target variable looks like the following:
        df['Churn'] = df['Churn'].apply(lambda x: 1 if x == 'Yes' else 0)

To get the overall churn rate, you can simply run the following ...

Get Hands-On Data Science for Marketing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.