Book Image

Data Science for Marketing Analytics

By : Tommy Blanchard, Debasish Behera, Pranshu Bhatnagar
Book Image

Data Science for Marketing Analytics

By: Tommy Blanchard, Debasish Behera, Pranshu Bhatnagar

Overview of this book

Data Science for Marketing Analytics covers every stage of data analytics, from working with a raw dataset to segmenting a population and modeling different parts of the population based on the segments. The book starts by teaching you how to use Python libraries, such as pandas and Matplotlib, to read data from Python, manipulate it, and create plots, using both categorical and continuous variables. Then, you'll learn how to segment a population into groups and use different clustering techniques to evaluate customer segmentation. As you make your way through the chapters, you'll explore ways to evaluate and select the best segmentation approach, and go on to create a linear regression model on customer value data to predict lifetime value. In the concluding chapters, you'll gain an understanding of regression techniques and tools for evaluating regression models, and explore ways to predict customer choice using classification algorithms. Finally, you'll apply these techniques to create a churn model for modeling customer product choices. By the end of this book, you will be able to build your own marketing reporting and interactive dashboard solutions.
Table of Contents (12 chapters)
Data Science for Marketing Analytics
Preface

Chapter 2: Data Exploration and Visualization


Activity 2: Analyzing Advertisements

  1. Import pandas and seaborn using the following code:

    import pandas as pd
    import seaborn as sns
    sns.set()
  2. Read the Advertising.csv file and look at the first few rows:

    ads = pd.read_csv("Advertising.csv", index_col = 'Date')
    ads.head()
  3. Look at the memory and other internal information about the DataFrame:

    ads.info

    This gives the following output:

    Figure 2.63: The result of ads.info()

  4. As all the attributes are numeric, it is enough to understand the distribution of the data with describe():

    ads.describe()

    This gives the following output:

    Figure 2.64: The result of ads.describe()

  5. See how the values in the column are spread:

    ads.quantile([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])

    As all values are within a reasonable range, we don't need to filter out any data and can directly proceed.

  6. Look at the histograms of individual features and understand the values better:

    sns.distplot(ads['TV'], kde = False)
    sns.distplot(ads['newspaper'], kde = False)
    sns.distplot(ads['radio'], kde = False)
    sns.distplot(ads['sales'], kde = False)

    Looking at the data, it is clear that we are interested in analyzing behaviors that drive an increase in sales. Therefore, sales is the KPI we need to look at.

  7. Understand the relationships between columns with this command:

    sns.pairplot(ads)

    This should give the following output:

    Figure 2.65: Output of pairplot of the ads feature

    You can derive the following insights from the data: Both TV and radio have a clear positive correlation with sales. The correlation with newspaper is not that direct, but as the distribution of newspapers is low, we can't make a claim about no or negative correlation.

  8. You can also try to find unknown or hidden relationships in the data. Let's analyze the relationship between newspaper and sales:

    ads[['newspaper', 'sales']].plot()

    Figure 2.66: pandas plot of the relationship between newpaper and sales

There seems to be a trend in the sales values preceding the newspaper value. We can look at this relationship in detail in further analysis. Anyway, the data seems to be fully explored now. The data from 1st Jan 2018 to 19th July 2018 has TV and radio in direct correlation with sales, but the relationship between sales and newspaper can be explored further using different techniques.