Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Data Science for Marketing Analytics

You're reading from   Data Science for Marketing Analytics Achieve your marketing goals with the data analytics power of Python

Arrow left icon
Product type Paperback
Published in Mar 2019
Publisher
ISBN-13 9781789959413
Length 420 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Tommy Blanchard Tommy Blanchard
Author Profile Icon Tommy Blanchard
Tommy Blanchard
Debasish Behera Debasish Behera
Author Profile Icon Debasish Behera
Debasish Behera
Pranshu Bhatnagar Pranshu Bhatnagar
Author Profile Icon Pranshu Bhatnagar
Pranshu Bhatnagar
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Data Science for Marketing Analytics
Preface
1. Data Preparation and Cleaning FREE CHAPTER 2. Data Exploration and Visualization 3. Unsupervised Learning: Customer Segmentation 4. Choosing the Best Segmentation Approach 5. Predicting Customer Revenue Using Linear Regression 6. Other Regression Techniques and Tools for Evaluation 7. Supervised Learning: Predicting Customer Churn 8. Fine-Tuning Classification Algorithms 9. Modeling Customer Choice Appendix

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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image