Business Analytics: Data Science for Business Problems Walter R. Paczkowski - Read the ebook now with the complete version and no limits
Business Analytics: Data Science for Business Problems Walter R. Paczkowski - Read the ebook now with the complete version and no limits
com
https://ebookmeta.com/product/business-analytics-data-
science-for-business-problems-walter-r-paczkowski/
OR CLICK HERE
DOWLOAD EBOOK
https://ebookmeta.com/product/data-science-for-business-with-r-1st-
edition-jeffrey-s-saltz/
ebookmeta.com
https://ebookmeta.com/product/business-analytics-a-data-driven-
decision-making-approach-for-business-volume-i-1st-edition-amar-sahay/
ebookmeta.com
https://ebookmeta.com/product/oxford-textbook-of-endocrinology-and-
diabetes-3rd-edition-john-wass/
ebookmeta.com
https://ebookmeta.com/product/a-rumor-of-kings-kingdom-of-
ghosts-1-1st-edition-victor-gischler/
ebookmeta.com
https://ebookmeta.com/product/the-hunger-habit-1st-edition-judson-
brewer/
ebookmeta.com
https://ebookmeta.com/product/axel-1st-edition-milly-taiden/
ebookmeta.com
https://ebookmeta.com/product/extremophiles-diversity-adaptation-and-
applications-1st-edition-masrure-alam/
ebookmeta.com
Walter R. Paczkowski
Business
Analytics
Data Science for Business Problems
Business Analytics
Walter R. Paczkowski
Business Analytics
Data Science for Business Problems
Walter R. Paczkowski
Data Analytics Corp.
Plainsboro, NJ, USA
This Springer imprint is published by the registered company Springer Nature Switzerland AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
Preface
I analyze business data—and I have been doing this for a long time. I was an analyst
and department head, a consultant and trainer, worked on countless problems,
written many books and reports, and delivered numerous presentations to all levels
of management. I learned a lot. This book reflects insights I gained from this
experience about Business Data Analytics that I want to share.
There are three questions you should quickly ask about this sharing. The first
is obvious: “Share what?” The second logically follows: “Share with whom?” The
third is more subtle: “How does this book differ from other data analytic books?”
The first is about focus, the second is about target, and the third is about competitive
comparison. So, let me address each question.
v
vi Preface
These three components form a synergistic whole, a unifying approach if you wish,
for doing business data analytics, and, in fact, any type of data analysis. This synergy
implies that one part does not dominate any of the other two. They work together,
feeding each other with the goal of solving only one overarching problem: how to
provide decision makers with rich information extracted from data. Recognizing this
problem was the most valuable lesson of all. All the analytical tools and know how
must have a purpose and solving this problem is that purpose—there is no other.
I show this problem and the synergy of the three components for solving it as a
triangle in Fig. 1. This triangle represents the almost philosophical approach I take
for any form of business data analysis and is the one I advocate for all data analyses.
Theoretical
Framework
ent
stm
Pr o
ze
dju
gra
aly
Ver
A
mm
An
nt/
yF if
me
to
ing
ram
fine
at
Problem:
Ins
Wh
ewo
Re
tru
rk
rk
ctio
Ho
ewo
ns
m
Fra
Fig. 1 The synergistic connection of the three components of effective data analysis for the
overarching problem is illustrated in this triangular flow diagram. Every component is dependent
on the others and none dominates the others. Regardless of the orientation of the triangle, the same
relationships will hold
The overarching problem at the center of the triangle is not obvious. It is subtle.
But because of its preeminence in the pantheon of problems any decision maker
faces, I decided to allocate the entire first chapter to it. Spending so much space
talking about information in a data analytics book may seem odd, but it is very
important to understand why we do what we do, which is to analyze data to extract
that rich information from data.
The theoretical understanding should be obvious. You need to know not just the
methodologies but also their limitations so you can effectively apply them to solve
a problem. The limitations may hinder you or just give you the wrong answers.
Assume you were hired or commissioned by a business decision maker (e.g., a
Preface vii
CEO) to provide actionable, insightful, and useful rich information relevant for their
problem. If the limitations of a methodology prevent you from accomplishing your
charge, then your life as an analyst will be short-lived, to say the least. This will
hold if you either do not know these limitations or simply choose to ignore them.
Another methodological approach might be better, one that has fewer problems, or
is just more applicable.
There is a dichotomy in methodology training. Most graduate-level statistics and
econometric programs, and the newer Data Science programs, do an excellent job
instructing students in the theory behind the methodologies. The focus of these
academic programs is largely to train the next generation of academic professionals,
not the next generation of business analytical professionals. Data Science programs,
of which there are now many available online and “in person,” often skim the surface
of the theoretical underpinnings since their focus is to prepare the next generation
of business analysts, those who will tackle the business decision makers’ tough
problems, and not the academic researchers. Something in between the academic
and data science training is needed for successful business data analysts.
Data handling is not as obvious since it is infrequently taught and talked about
in academic programs. In those programs, beginner students work with clean data
with few problems and that are in nice, neat, and tidy data sets. They are frequently
just given the data. More advanced students may be required to collect data, most
often at the last phase of training for their thesis or dissertation, but these are small
efforts, especially when compared to what they will have to deal with post training.
The post-training work involves:
• Identifying the required data from diverse, disparate, and frequently disconnected
data sources with possibly multiple definitions of the same quantitative concept
• Dealing with data dictionaries
• Dealing with samples of a very large database—how to draw the sample and
determine the sample size
• Merging data from disparate sources
• Organizing data into a coherent framework appropriate for the statisti-
cal/econometric/machine learning methodology chosen
• Visualizing complex multivariate data to understand relationships, trends, pat-
terns, and anomalies inside the data sets
This is all beyond what is provided by most training programs.
Finally, there is the programming. First, let me say that there is programming
and then there is programming. The difference is scale and focus. Most people,
when they hear about programming and programming languages, immediately
think about large systems, especially ones needing a considerable amount of
time (years?) to fully specify, develop, test, and deploy. They would be correct
regarding large-scale, complex systems that handle a multitude of interconnected
operations. Online ordering systems easily come to mind. Customer interfaces,
inventory management, production coordination, supply chain management, price
maintenance and dynamic pricing platforms, shipping and tracking, billing, and
viii Preface
collections are just a few components of these systems. The programming for these
is complex to say the least.
As a business data analyst, you would not be involved in this type of program-
ming although you might have to know about and access the subsystems of one or
more of these larger systems. And major businesses are composed of many larger
systems! You might have to write code to access the data, manipulate the retrieved
data, and so forth, basically write programming code to do all the data handling I
described above. And for this you need to know programming and languages.
There are many programming languages available. Only a few are needed for
most business data analysis problems. In my experience, these are:
• SQL
• Python
• R
Julia should be included because it is growing in popularity due to its performance
and ease of use. For this book, I will use Python because its ecosystem is
strongly oriented toward machine learning with strong modeling, statistics, data
visualization, and programming functionalities. In fact, its programming paradigm
is clear to use, which is a definite advantage over other languages.
The target audience for this book consists of business data analysts, data scientists,
and market research professionals, or those aspiring to be any of these, in the private
sector. You would be involved in or responsible for a myriad of quantitative analyses
for business problems such as, but not limited to:
• Demand measurement and forecasting
• Predictive modeling
• Pricing analytics including elasticity estimation
• Customer satisfaction assessment
• Market and advertisement research
• New product development and research
To meet these tasks, you will have a need to know basic data analytical methods and
some advanced methods, including data handling and management. This book will
provide you with this needed background by:
• Explaining the intuition underlying analytic concepts
• Developing the mathematical and statistical analytic concepts
• Demonstrating analytical concepts using Python
• Illustrating analytical concepts with case studies
Preface ix
This book is also suitable for use in colleges and universities offering courses and
certifications in business data analytics, data sciences, and market research. It could
be used as a major or supplemental textbook.
Since the target audience consists of either current or aspiring business data
analysts, it is assumed that you have or are developing a basic understanding of fun-
damental statistics at the “Stat 101” level: descriptive statistics, hypothesis testing,
and regression analysis. Knowledge of econometric and market research principles,
while not required, would be beneficial. In addition, a level of comfort with calculus
and some matrix algebra is recommended, but not required. Appendices will provide
you with some background as needed.
There are many books on the market that discuss the three themes of this book:
analytic methods, data handling, and programming languages. But they do them
separately as opposed to a synergistic, analytic whole. They are given separate
treatment so that you must cover a wide literature just to find what is needed for
a specific business problem. Also, once found, you must translate the material into
business terms. This book will present the three themes so you can more easily
master what is needed for your work.
I divided this book into three parts. In Part I, I cover the basics of business
data analytics including data handling, preprocessing, and visualization. In some
instances, the basic analytic toolset is all you need to address problems raised by
business executives. Part II is devoted to a richer set of analytic tools you should
know at a minimum. These include regression modeling, time series analysis,
and statistical table analysis. Part III extends the tools from Part II with more
advanced methods: advanced regression modeling, classification methods, and
grouping methods (a.k.a., clustering).
The three parts lead naturally from basic principles and methods to complex
methods. I illustrate this logical order in Fig. 2.
Embedded in the three parts are case study examples of business problems
using (albeit, fictitious, fake, or simulated) business transactions data designed to
be indicative of what business data analysts use every day. Using simulated data
x Preface
Part III
Analytics Progression
Advanced Analytics:
Going Further
Business Data
Part II
Intermediate Analytics:
Gaining Insight
Part I
Beginning Analytics:
Getting Started
Fig. 2 This is a flow chart of the three parts of this book. The parts move progressively from basics
to advanced. At the end of Part I, you should be able to do basic analyses of business data. At the
end of Part II, you should be able to do regression and times series analysis. At the end of Part III,
you should be able to do advanced machine learning work
for instructional purposes is certainly not without precedence. See, for example,
Gelman et al. (2021). Data handling, visualization, and modeling are all illustrated
using Python. All examples are in Jupyter notebooks available on Github.
xi
Contents
xiii
xiv Contents
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
List of Figures
Fig. 1.1 This cost curve illustrates what happens to the cost of
decisions as the amount of information increases. The
Base Approximation Cost is the lowest possible cost you
can achieve due to the uncertainty of all decisions. This
is an amount above zero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Fig. 1.2 Data is the base for information which is used for
decision making. The Extractor consists of the
methodologies I will develop in this book to take you
from data to information. So, behind this one block in
the figure is a wealth of methods and complexities . . . . . . . . . . . . . . . 11
Fig. 1.3 This is an example of a Data Cube illustrating the three
dimensions of data for a manufacturer. As I noted in the
text, more than three dimensions are possible, but only
three can be visualized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
xix
xx List of Figures
Fig. 1.4 This is a DataFrame version of the Data Cube for the
product return example. There are 288 rows. This
example has a multilevel index representing the Data
Cube. Each combination of the levels of three indexes is
unique because each combination is a row identifier, and
there can only be one identifier for each row . . . . . . . . . . . . . . . . . . . . . . 13
Fig. 1.5 This is a stylized Data Cube illustrating the three
dimensions of data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Fig. 1.6 This illustrates three possible aggregations of the
DataFrame in Fig. 1.4. Panel (a) is an aggregation over
months; (b) is an aggregation over plants; and (c) is an
aggregation over plants and products. There are six ways
to aggregate over the three indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Fig. 1.7 This illustrates information about the structure of a
DataFrame. The variable “supplier” is an object or text,
“averagePrice” is a float, “ontime” is an integer, and
“dateDelivered” is a datetime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Fig. 1.8 Not only does information have a quantity dimension
that addresses the question “How much information
do you have?’, but it also has a quality dimension that
addresses the question “How good is the information?”
This latter dimension is illustrated in this figure as
varying degrees from Poor to Rich . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Fig. 1.9 Cost curves for Rich Information extraction from data . . . . . . . . . . . 25
Fig. 1.10 The synergistic connection of the three components
of effective data analysis for business problems is
illustrated in this triangular flow diagram. Every
component is dependent on the others and none
dominates the others. Regardless of the orientation of
the triangle, the same relationships will hold . . . . . . . . . . . . . . . . . . . . . . 26
Fig. 1.11 Programming roles throughout the Deep Data Analytic
process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Fig. 3.1 Importing a CSV file. The path for the data would have
been previously defined as a character string, perhaps
as path = ‘../Data/’. The file name is also a character
string as shown here. The path and file name are string
concatenated using the plus sign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Fig. 3.2 Reading a chunk of data. The chunk size is 5 records.
The columns in each row in each chunk are summed . . . . . . . . . . . . . 65
Fig. 3.3 Processing a chunk of data and summing the columns,
but then deleting the first two columns after the
summation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Fig. 3.4 Chunks of data are processed as in Fig. 3.3 but then
concatenated into one DataFrame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Fig. 3.5 Display the head( ) of a DataFrame. The default is n = 5
records. If you want to display six records, use df.head(
6 ) or df.head( n = 6 ). Display the tail with a comparable
method. Note the “dot” between the ‘df” and “head().
This means that the head( ) method is chained or linked
to the DataFrame “df” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Fig. 3.6 This is a style definition for setting the font size for a
DataFrame caption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Fig. 3.7 This is an example of using a style for a DataFrame . . . . . . . . . . . . . . 69
Fig. 3.8 Display the shape of a DataFrame. Notice that the shape
does not take any arguments and parentheses are not
needed. The shape is an attribute, not a method. This
DataFrame has 730,000 records and six columns . . . . . . . . . . . . . . . . . 69
Fig. 3.9 Display the column names of a DataFrame using the
columns attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Fig. 3.10 These are some examples where an NaN value is ignored
in the calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Fig. 3.11 These are some examples where an NaN value is not
ignored in the calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Fig. 3.12 Two symbols are assigned an NaN value using Numpy’s
nan function. The id( ) function returns the memory
location of the symbol. Both are stored in the same
memory location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
xxii List of Figures
Fig. 6.7 ANOVA table for the unit sales multiple regression
model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Fig. 6.8 Correlation matrix showing very little correlation . . . . . . . . . . . . . . . . 183
Fig. 6.9 F-test showing no region effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Fig. 6.10 You define the statistics to display in a portfolio using a
setup like this . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Fig. 6.11 This is the portfolio summary of the two regression
models from this chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Fig. 6.12 This illustrates a framework for making predictions with
a simulation tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Fig. 7.1 The relationships among the four concepts are shown
here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Fig. 7.2 The Data Cube can be collapsed by aggregating the
measures for periods that were extracted from a datetime
value using the accessor dt. Aggregation is the done
using the groupby and aggregate functions . . . . . . . . . . . . . . . . . . . . . . . . 193
Fig. 7.3 This function in this example, returns date as a datetime
integer. This integer is the number of seconds since the
Pandas epoch which is January 1, 1970. The Unix epoch
is January 1, 1960 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Fig. 7.4 These are consecutive dates, each written in a different
format. Each format is a typical way to express a
date. Pandas interprets each format the same way and
produces the datetime value, which is the number of
seconds since the epoch. The column labeled “Time
Delta” is the day-to-day change. Notice that it is always
86,400 which is the number of seconds in a day . . . . . . . . . . . . . . . . . . 195
Fig. 7.5 The groupby method and the resampling method can
be combined in this order: the rows of the DataFrame
are first grouped by the groupby method and then each
group’s time frequency is converted by the resample
method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Fig. 7.6 The groupby method is called with an additional
argument to the variable to group on. The additional
argument is Grouper which groups by a datetime
variable. This method takes two arguments: a key
identifying the datetime variable and a frequency to
convert to. The Grouper can be placed in a separate
variable for convenience as I show here . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Fig. 7.7 The groupby method is called with the Grouper
specification only . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
List of Figures xxvii
Fig. 7.21 The AR(1) model is used to forecast the pocket price
times series. In this case, I forecast 4-steps ahead, or
four periods into the future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Fig. 7.22 These are the 4-steps ahead forecasts for the pocket
prices. (a) Forecast values. (b) Forecast plot . . . . . . . . . . . . . . . . . . . . . . . 223
Fig. 8.1 This illustrates the code to remap values in a DataFrame . . . . . . . . 228
Fig. 8.2 A Categorical data type is created using the
CategoricalDtype method. In this example, a list
of ordered levels for the paymentStatus variable is
provided. The categorical specification is applied using
the astype( ) method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Fig. 8.3 The variable with a declared categorical data type is used
to create a simple frequency distribution of the recoded
payment status. Notice how the levels are in a correct
order so that the cumulative data make logical sense . . . . . . . . . . . . . 231
Fig. 8.4 The variable with a declared categorical data type is
used to create a simple frequency distribution, but this
time subsetted on another variable, region . . . . . . . . . . . . . . . . . . . . . . . . 231
Fig. 8.5 This is the frequency table for drug stores in California.
Notice that 81.2% of the drug stores in California are
past due . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Fig. 8.6 This illustrates a chi-square test comparing an observed
frequency distribution and an industry standard
distribution. The industry distribution is in Table 8.3.
The Null Hypothesis is no difference in the two
distributions. The Null is rejected at the α = 0.05 level
of significance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Fig. 8.7 This illustrates a basic cross-tab of two categorical
variables. The payment status is the row index of the
resulting tab. The argument, margins = True instructs
the method to include the row and column margins. The
sum of the row margins equals the sum of the column
margins equals the sum of the cells. These sums are all
equal to the sample size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Fig. 8.8 This illustrates a basic tab but with a third variable,
“daysLate”, averaged for each combination of the levels
of the index and column variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Fig. 8.9 This is the Python code for interweaving a frequency
table and a proportions table. There are two important
steps: (1) index each table to be concatenated to identify
the respective rows and (2) concatenate based on axis 0 . . . . . . . . . 236
Fig. 8.10 This is the result of interweaving a frequency table and
a proportions table using the code in Fig. 8.9. This is
sometimes more compact than having two separate tables . . . . . . . 236
List of Figures xxix
Fig. 8.11 This illustrates the Pearson Chi-Square Test using the
tab in Fig. 8.7. The p-value indicates that the Null
Hypothesis of independence should not be rejected.
The Cramer’s V statistic is 0.0069 and supports this
conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Fig. 8.12 This illustrates a heatmap using the tab in Fig. 8.7. It is
clear that the majority of Grocery stores is current in
their payments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Fig. 8.13 This is the main function for the correspondence
analysis of the cross-tab developed in Fig. 8.7. The
function is instantiated with the number of dimensions
and a random seed or state (i.e., 42) so that results can
always be reproduced. The instantiated function is then
used to fit the cross-tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Fig. 8.14 The functions to assemble the pieces for the final
correspondence analysis display are shown here.
Having separate function makes programming more
manageable. This is modular programming . . . . . . . . . . . . . . . . . . . . . . . 242
Fig. 8.15 The complete final results of the correspondence
analysis are shown here. Panel (a) shows the set-up
function for the results and the two summary tables.
Panel (b) shows the biplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Fig. 8.16 This is the map for the entire nation for the bakery
company . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Fig. 8.17 The cross-tab in Fig. 8.7 is enhanced with the mean of a
third variable, days-late . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Fig. 8.18 The cross-tab in Fig. 8.17 can be replicated using the
Pandas groupby function and the mean function. The
values in the two approaches are the same; just the
arrangement differs. This is a partial display since the
final table is long . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Fig. 8.19 The cross-tab in Fig. 8.17 is aggregated using multiple
variables and aggregation methods. The agg method
is used in this case. An aggregation dictionary has the
aggregation rules and this dictionary is passed to the agg
method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Fig. 8.20 The DataFrame created by a groupby in Fig. 8.18, which
is a long-form arrangement, is pivoted to a wide-form
arrangement using the Pandas pivot function. The
DataFrame is first reindexed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Fig. 8.21 The pivot_table function is a more convenient way to
pivot a DataFrame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Fig. 8.22 The pivot_table function is quite flexible for pivoting a
table. This is a partial listing of an alternative pivoting of
our data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
xxx List of Figures
Fig. 9.1 There are several options for identifying duplicate index
values shown here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Fig. 9.2 This illustrate how to convert a DatetimeIndex to a
PeriodIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Fig. 9.3 Changing a MultiIndex to a new MultiIndex . . . . . . . . . . . . . . . . . . . . . . 260
Fig. 9.4 This is one way to query a PeriodIndex in a MultiIndex.
Notice the @. this is used then the variable is in the
environment, not in the DataFrame. This is the case with
“x” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Fig. 9.5 This illustrates how to draw a stratified random sample
from a DataFrame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Fig. 9.6 This illustrates how to draw a cluster random sample
from a DataFrame. Notice that the Numpy unique
function is used in case duplicate cluster labels are
selected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Fig. 9.7 This schematic illustrates how to split a master data set . . . . . . . . . . 267
Fig. 9.8 This illustrates a general correct scheme for developing a
model. A master data set is split into training and testing
data sets for basic model development but the training
data set is split again for validation. If the training data
set itself is not split, perhaps because it is too small, then
the trained model is directly tested with the testing data
set. This accounts for the dashed arrows . . . . . . . . . . . . . . . . . . . . . . . . . . 267
Fig. 9.9 This illustrates a general incorrect scheme for developing
a model. The test data are used with the trained model
and if the model fails the test, it is retrained and tested
again. The test data are used as part of the training
process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Fig. 9.10 There is a linear trade-off between allocating data to the
training data set and the testing data set. The more you
allocate to the testing, the less is available for training . . . . . . . . . . . 270
Fig. 9.11 As a rule-of-thumb, split your data into three-fourths
training and one-fourth testing. Another is two-thirds
training and one-third testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Fig. 9.12 This is an example of a train-test split on simulated
cross-sectional data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Fig. 9.13 This is an example of a train-test split on simulated time
series data. Sixty monthly observations were randomly
generated and then divided into one-fourth testing and
three-fourths training. A time series plot shows the split
and a table summarizes the split sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
List of Figures xxxi
Fig. 10.1 This is the code to aggregate the orders data. I had
previously created a DataFrame with all the orders,
customer-specific data, and marketing data . . . . . . . . . . . . . . . . . . . . . . . 285
Fig. 10.2 This is the code to split the aggregate orders data into
training and testing data sets. I used three-fourths testing
and a random see of 42. Only the head of the training
data are shown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Fig. 10.3 This is the code to set up the regression for the
aggregated orders data. Notice the form for the formula
statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Fig. 10.4 This is the results for the regression for the aggregated
orders data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Fig. 10.5 These are the regression results for simulated data. The
two lines for the R 2 are the R 2 itself and the adjusted
version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Fig. 10.6 Panel (a) is the unrestricted ANOVA table for simulated
data and Panel (b) is the restricted version . . . . . . . . . . . . . . . . . . . . . . . . 290
Fig. 10.7 This is the manual calculation of the F-Statistic using
the data in Fig. 10.6. The F-statistic here agrees with the
one in Fig. 10.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Fig. 10.8 This is the F-test of the two regressions I summarized in
Fig. 10.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Fig. 10.9 These are the signature patterns for heteroskedasticity.
The residuals are randomly distributed around their
mean in Panel (a); this indicates homoskedasticity. They
fan out in Panel (b) as the X-axis variable increases; this
indicates heteroskedasticity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Fig. 10.10 This is the residual plot for the residuals in Fig. 10.4 . . . . . . . . . . . . . 293
Fig. 10.11 These are the White Test results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
xxxii List of Figures
Fig. 11.29 This illustrates data points for a SVM problem. Two
decision support lines (DS1 and DS2 ) are shown . . . . . . . . . . . . . . . . . 352
Fig. 11.30 This illustrates DataFrame setup for a SVM problem . . . . . . . . . . . . . 354
Fig. 11.31 This illustrates the fit and accuracy measures for a SVM
problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Fig. 11.32 This illustrates how to do a scenario analysis using a SVM . . . . . . 355
Fig. 11.33 This illustrates the fit and accuracy measure for a SVM
problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Fig. 12.1 This is a sample of the aggregated data for the furniture
Case Study hierarchical clustering of customers . . . . . . . . . . . . . . . . . . 363
Fig. 12.2 This shows the standardization of the aggregated data
for the furniture Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Fig. 12.3 This shows the label encoding of the Region variable for
the furniture Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Fig. 12.4 This shows the code for the hierarchical clustering for
the furniture Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Fig. 12.5 This shows the dendrogram for the hierarchical
clustering for the furniture Case Study. The horizontal
line at distance 23 is a cut-off line: clusters formed
below this line are the clusters we will study . . . . . . . . . . . . . . . . . . . . . . 366
Fig. 12.6 This is the flattened hierarchical clustering solution.
Notice the cluster numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Fig. 12.7 This is a frequency distribution for the size of the
clusters for the hierarchical clustering solution . . . . . . . . . . . . . . . . . . . 367
Fig. 12.8 This are the boxplots for the size of the clusters for the
hierarchical clustering solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Fig. 12.9 This is a summary of the cluster means for the
hierarchical clustering solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Fig. 12.10 This is a sample of the aggregated data for the furniture
Case Study for K-Means clustering of customers . . . . . . . . . . . . . . . . . 369
Fig. 12.11 This are the setup for a K-Means clustering. Notice that
the random seed is set at 42 for reproducibility . . . . . . . . . . . . . . . . . . . 370
Fig. 12.12 This is an example frequency table of the K-Means
cluster assignments from Fig. 12.11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Fig. 12.13 This is a summary of the cluster means for the K-Means
cluster assignments from Fig. 12.11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Fig. 12.14 This are the setup for a Gaussian mixture clustering . . . . . . . . . . . . . . 372
Fig. 12.15 This is an example frequency table of the Gaussian
Mixture cluster assignments from Fig. 12.14 . . . . . . . . . . . . . . . . . . . . . . 372
Fig. 12.16 This is a summary of the cluster means for the Gaussian
Mixture cluster assignments from Fig. 12.14 . . . . . . . . . . . . . . . . . . . . . . 373
List of Tables
Table 1.1 For the three SOWs shown here, the expected ROI is
3
i=1 ROIi × pi = 0.0215 or 2.15% . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 1.2 Information extraction methods and chapters where I
discuss them . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Table 1.3 These are some major package categories available in Python . . . 29
xxxv
xxxvi List of Tables
Table 5.1 When the probability of an event is 0.5, then the odds of
the event happening is 1.0. This is usually expressed as
“odds of 1:1” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Table 5.2 These are some categorical variables that might be
encountered in Business Analytic Problems . . . . . . . . . . . . . . . . . . . . . . . 143
Table 6.1 This is the general ANOVA table structure. The mean
squares are just the average or scaled sum of squares.
The statistic, FC , is the calculated F-statistic used
to test the fitted model against a subset model. The
simplest subset model has only an intercept. I refer
to this as the restricted model. Note the sum of the
degrees-of-freedom. Their sum is equivalent to the sum
of squares summation by (6.2.4) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Table 6.2 This is the modified ANOVA table structure when there
are p > 1 independent variables. Notice the change in
the degrees-of-freedom, but that the degrees-of-freedom
for the dependent variable is unchanged. The p
degrees-of-freedom for the Regression source accounts
for the p independent variables which are also reflected
in the Error source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
List of Tables xxxvii
Table 6.3 The F-test for the multiple regression case is compared
for the simple and multiple regression cases. . . . . . . . . . . . . . . . . . . . . . . 177
Table 6.4 Density vs log-density values for the normal density
with mean 0 and standard deviation 1 vs standard
deviation 1/100. Note that the values of the log-Density
are negative around the mean 0 in the left panel but
positive in the right panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Table 10.1 This is a list of the most commonly used link functions . . . . . . . . . 280
Table 10.2 This table illustrates the dummy variable trap. The
constant term is 1.0 be definition. So, no matter which
Region an observation is in, the constant has the same
value: 1.0. The dummy variables’ values, however, vary
by region as shown. The sum of the dummy values for
each observation is 1.0. This sum and the Constant Term
are equal. This is perfect multicollinearity. The trap is
not recognizing this equality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Table 10.3 These are the four White and MacKinnon correction
methods available in statsmodels. The test command
notation is the statsmodels notation. The descriptions
are based on Hausman and Palmery (2012) . . . . . . . . . . . . . . . . . . . . . . . 295
Table 10.4 These are the available cross-validation functions. See
https://scikit-learn.org/stable/modules/classes.html for
complete descriptions. Web site last accessed November
27, 2020 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
This first part of the book introduces basic principles for analyzing business data.
The material is at a Statistics 101 level and is applicable if you are interested in basic
tools that you can quickly apply to a business problem. After reading this part of the
book, you will be able to conduct basic business data analysis.
Chapter 1
Introduction to Business Data Analytics:
Setting the Stage
Spoiler-alert: Business Data Analytics (BDA), the focus of this book, is solely
concerned with one task, and one task only: to provide the richest information
possible to decision makers.
I have two objectives for this introductory chapter regarding my spoiler alert. I
will first discuss the types of problems business decision makers confront and who
the decision makers are. I will then discuss the role and importance of information
to set the foundations for succeeding chapters. This will include a definition of
information. People frequently use the words data and information interchangeably
as if they have the same meaning. I will draw a distinction between them. First, they
are not the same despite the fact that they are used interchangeably. Second, as I will
argue, information is latent, hidden inside data and must be extracted and revealed
which makes it a deeper, more complex topic. As a data analyst, you need to have a
handle on the significance of information because extracting it from data is the sole
reason for the existence of BDA.
My discussion of the difference between data and information will follow with a
comparison of two dimensions of information rarely discussed: the quantity and
quality of the information decision makers rely on. There is a cost to decision
making often overlooked at best or ignored at worst. The cost is due to both
dimensions. The objective of BDA is not only to provide information (i.e., a quantity
issue), but also to provide good information (i.e., a quality issue) to reduce the cost
of decision making. Providing good information, however, is itself not without cost.
You need the appropriate skill sets and resources to effectively extract information
from data. This is a cost of doing data analytics. These two costs—cost of decision
making and cost of data analytics—determine what information can be given to
decision makers. These have implications for the type and depth of your BDA.
What types of business problems warrant BDA? The types are too numerous to
mention, but to give a sense of them consider a few examples:
• Anomaly Detection: production surveillance, predictive maintenance, manufac-
turing yield optimization;
• Fraud detection;
• Identity theft;
• Account and transaction anomalies;
• Customer analytics:
– Customer Relationship Management (CRM);
– Churn analysis and prevention;
– Customer Satisfaction;
– Marketing cross-sell and up-sell;
– Pricing: leakage monitoring, promotional effects tracking, competitive price
responses;
– Fulfillment: management and pipeline tracking;
• Competitive monitoring;
• Competitive Environment Analysis (CEA); and
• New Product Development.
And the list goes on, and on.
A decision of some type is required for all these problems. New product
development best exemplifies a complex decision process. Decisions are made
throughout a product development pipeline. This is a series of stages from ideation
or conceptualization to product launch and post-launch tracking. Paczkowski (2020)
identifies five stages for a pipeline: ideation, design, testing, launch, and post-launch
tracking. Decisions are made between each stage whether to proceed to the next
one or abort development or even production. Each decision point is marked by
a business case analysis that examines the expected revenue and market share
for the product. Expected sales, anticipated price points (which are refined as the
product moves through the pipeline), production and marketing cost estimates, and
competitive analyses that include current products, sales, pricing, and promotions
plus competitive responses to the proposed new product, are all needed for each
business case assessment. If any of these has a negative implication for the concept,
then it will be canceled and removed from the pipeline. Information is needed for
each business case check point.
The expected revenue and market share are refined for each business case
analysis as new and better information –not data– become available for the items I
listed above. More data do become available, of course, as the product is developed,
but it is the analysis of that data based on methods described in this book, that
provide the information needed to approve or not approve the advancement of the
concept to the next stage in the pipeline. The first decision, for example, is simply to
Other documents randomly have
different content
This eBook is for the use of anyone anywhere in the
United States and most other parts of the world at no
cost and with almost no restrictions whatsoever. You
may copy it, give it away or re-use it under the terms
of the Project Gutenberg License included with this
eBook or online at www.gutenberg.org. If you are not
located in the United States, you will have to check the
laws of the country where you are located before using
this eBook.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.