Because learning changes everything.
Data-driven Decision
Making
Day 3 | Predictive Analytics
Avijit Mallik,
Assistant Professor,
Institute of Business Administration, University of Dhaka
Email: [email protected]
1
What is predictive analytics
• Predict the future by examining historical data, detecting patterns or
relationships in these data, and then extrapolating these
relationships forward in time.
• “What might happen in the future?”
• Which product the customer is likely to buy next?
• Which customer is likely to default?
• How much are we likely to sell in the next quarter?
• What is the impact of increase in HR staff in our freelancing revenue?
Tools used: Correlation analysis, regression analysis 2
© McGraw Hill
What is Correlation Analysis? 1
Correlation Analysis A group of techniques to measure the
relationship between two variables.
Study the relationship between two interval- or ratio- scale
variables.
Start with a scatter diagram.
• Graphic tool used to show the relationship between two
variables.
• X-axis: The independent variable, used as the predictor.
• Y-axis: The dependent variable, variable that is predicted.
© McGraw Hill 3
What is Correlation Analysis? 2
• Example: North American Copier Sales sells copiers to
businesses of all sizes throughout the United States and
Canada.
• The new national sales manager is preparing for an
upcoming sales meeting and would like to impress upon
the sales representatives the importance of making an
extra sales call each day.
• She takes a random sample of 15 sales representatives
and gathers information on the number of sales calls
made last month and the number of copiers sold.
© McGraw Hill 4
What is Correlation Analysis? 3
• Example continued.
Sales Representative Sales Calls Copiers Sold
Brian Virost 96 41
Carlos Ramirez 40 41
Carol Saia 104 51
Greg Fish 128 60
Jeff Hall 164 61
Mark Reynolds 76 29
Meryl Rumsey 72 39
Mike Kiel 80 50
Ray Snarky 36 28
Rich Niles 84 43
Ron Broderick 180 70
Sal Spina 132 56
Soni Jones 120 45
Susan Welch 44 31
Tom Keller 84 30
Access the text alternative for these images.
© McGraw Hill 5
The Correlation Coefficient 1
Correlation Coefficient A measure of the strength of the
linear relationship between two variables.
r=
( x − x )( y − y )
(n − 1) s y sx
• Identified as r.
• It ranges from −1 to 1.
• Near 0 indicates little linear association.
• Near 1 indicates a direct/positive linear association.
• Near −1 indicates an inverse/negative linear association.
© McGraw Hill 6
The Correlation Coefficient 2
Access the text alternative for these images.
© McGraw Hill 7
The Correlation Coefficient 3
Access the text alternative for these images.
© McGraw Hill 8
The Correlation Coefficient 4
• Examples.
Access the text alternative for these images.
© McGraw Hill 9
The Correlation Coefficient 6
• Example continued.
Sales Representative Sales Calls (x) Copiers Sold (y) x− x y− y (x − x ) (y − y )
Brian Virost 96 41 0 −4 0
Carlos Ramirez 40 41 −56 −4 224
Carol Saia 104 51 8 6 48
Greg Fish 128 60 32 15 480
Jeff Hall 164 61 68 16 1088
Mark Reynolds 76 29 −20 −16 320
Meryl Rumsey 72 39 −24 −6 144
Mike Kiel 80 50 −16 5 −80
Ray Snarky 36 28 −60 −17 1020
Rich Niles 84 43 −12 −2 24
Ron Broderick 180 70 84 25 2100
SalSpina 132 56 36 11 396
Soni Jones 120 45 24 0 0
Susan Welch 44 31 −52 −14 728
Tom Keller 84 30 −12 −15 180
Totals 1440 675 0 0 6672
© McGraw Hill 10
The Correlation Coefficient 7
• Example continued.
• r=
( x − x )( y − y )
=
6672
= .865.
(n − 1) s y sx (15 − 1)(12.89)(42.76)
Access the text alternative for these images.
© McGraw Hill 11
The Correlation Coefficient 8
If there is a strong association, we might be tempted assume a
change in one variable causes a change in another variable.
Spurious correlation: Strong relationships between variables that
are not related to each other but are related to other variables.
Correlation does not imply causation!
© McGraw Hill 12
What is happening here?
© McGraw Hill
Now Tell Us What is happening here?
© McGraw Hill
There's A Shocking Connection Between Eating More Chocolate And Winning The
Nobel Prize
© McGraw Hill
Regression Analysis 1
• Regression analysis is another method to examine a linear
relationship between two variables.
• Provides more information than correlation.
• Estimate the value of the dependent variable (Y) for a
value of the independent variable (X).
Regression Equation An equation that expresses the linear
relationship between two variables.
• How do we get the equation?
© McGraw Hill 16
Regression Analysis 2
• Use the data to position a line that best represents the
relationship between X and Y.
• We could use a scatter diagram.
Access the text alternative for these images.
© McGraw Hill 17
Regression Analysis 3
• But this can be hard to do without criteria and may not be
the best line.
Access the text alternative for these images.
© McGraw Hill 18
Regression Analysis
• The ”best fitting” line is obtained by the least squares
principle.
Least Squares Principle A mathematical procedure that
uses the data to position a line with the objective of
minimizing the sum of the squares of the vertical distances
between the actual y values and the predicted values of y.
Access the text alternative for these images.
© McGraw Hill 19
Regression Analysis 5
General form of the linear regression equation:
ŷ = a + bx
• ŷ is the estimated value of y for a selected value of x.
• a is the constant or intercept.
• b is the slope of the fitted line.
• x is the value of the independent variable.
The values of a and b are given by:
sy
• b = r .
sx
• a = y − bx .
© McGraw Hill 20
Regression Analysis 6
• Example: Sales Calls v s Copiers Sold.
ersu
• We previously determined the correlation to be r = .865.
• sx = 42.76, s y = 42.76, x = 96, y = 45.
• What is the least squares equation?
• If a salesperson makes 100 calls, how many copiers do they
expect to sale?
Access the text alternative for these images.
© McGraw Hill 21
Regression Analysis 7
Example continued.
r = .865, sx = 42.76, s y = 12.89, x = 96, y = 45.
sy 12.89
• b = r = .865 = .2608.
sx 42.76
• a = y − bx = 45 − .2608(96) = 19.96.
Least squares line: yˆ = 19.69 + .2068 x.
b = .2608: for each additional sales call, the salesperson can expect to
increase the number of copiers sold by about .2608.
If a salesperson makes 100 calls.
• yˆ = 19.69 + .2068(100) = 46.0432.
• They can expect to sale 46.0432 copiers.
© McGraw Hill 22
Regression Analysis 8
• Example continued. yˆ = 19.69 + .2068(100) = 46.0432.
• To draw the line, put in the x values.
Sales Representative Sales Calls (x) Copiers Sold (y) Estimated Sales ( yˆ )
Brian Virost 96 41 45.0000
Carlos Ramirez 40 41 30.3952
Carol Saia 104 51 47.0864
Greg Fish 128 60 53.3456
Jeff Hall 164 61 62.7344
Mark Reynolds 76 29 39.7840
Meryl Rumsey 72 39 39.7840
Mike Kiel 80 50 38.7408
Ray Snarky 36 28 40.8272
Rich Niles 84 43 29.3520
Ron Broderick 180 70 41.8704
Sal Spina 132 56 66.9072
Soni Jones 120 45 54.3888
Susan Welch 44 31 51.2592
Tom Keller 84 30 31.4384
Totals 1440 675
© McGraw Hill 23
Evaluating a Regression Equation’s Ability to
Predict 3
• Example continued.
• This lived in the previous output.
Access the text alternative for these images.
© McGraw Hill 24
Evaluating a Regression Equation’s Ability to
Predict 4
We need a measure that is easy to interpret.
Coefficient Of Determination The proportion of the total
variation in the dependent variable Y that is explained, or
accounted for, by the variation in the independent variable X.
The correlation squared, hence r 2 .
Between 0 and 1 (or 0% and 100%).
Based on an ANOVA framework.
• Variation explained by the model.
• Variation explained by the errors or residuals.
© McGraw Hill 25
Evaluating a Regression Equation’s Ability to
Predict 6
• Example: Sales Calls v s Copiers Sold.
ersu
Access the text alternative for these images.
© McGraw Hill 26
Practice Question
Bradford Electric Illuminating Company is studying the relationship
between kilowatt-hours (thousands) used and the number of rooms in
a private single-family residence. A random sample of 10 homes
yielded the following:
Number of Kilowatt-Hours Number of Kilowatt-Hours
Rooms (thousands) Rooms (thousands)
12 9 8 6
9 7 10 8
14 10 10 10
6 5 5 4
10 8 7 7
What is the correlation between Number of Rooms & Kilowatt-
Hours (thousands)? Develop a regression equation in excel. What
will be the energy consumption in Kilowatt-Hours (thousands) if
there are 8 rooms?
© McGraw Hill 27
Transforming Data 1
Regression analysis and the correlation coefficient require the
relationship to be linear.
But what if data is not linear?
Rescale one or both of the variables so the new relationship is linear.
Common transformations include.
• The base 10 log, log(y).
• The square root.
• The reciprocal.
• Square one or both variables.
Caution: When you are interpreting a correlation coefficient or regression
equation – it could be nonlinear.
© McGraw Hill 28
Transforming Data 2
• Example: GroceryLand Supermarkets is a regional
grocery chain located in the midwestern United States.
• The director of marketing wishes to study the effect of
price on weekly sales of their two-liter private brand diet
cola.
• The objectives of the study are.
1. To determine whether there is a relationship between
selling price and weekly sales. Is this relationship direct
or indirect? Is it strong or weak?
2. To determine the effect of price increases or decreases
on sales. Can we effectively forecast sales based on
the price?
© McGraw Hill 29
Can we model the demand curve?
• Example continued.
GroceryLand Sales and Price Data GroceryLand Sales and Price Data
Store Number Price Sales Store Number Price Sales
A-17 0.50 181 A-30 0.76 91
A-121 1.35 33 A-127 1.79 13
A-227 0.79 91 A-266 1.57 22
A-135 1.71 13 A-117 1.27 34
A-6 1.38 34 A-132 0.96 74
A-282 1.22 47 A-120 0.52 164
A-172 1.03 73 A-272 0.64 129
A-296 1.84 11 A-120 1.05 55
A-143 1.73 15 A-194 0.72 107
A-66 1.62 20 A-105 0.75 119
© McGraw Hill 30
Can we model the demand curve? 4
• Example continued.
Access the text alternative for these images.
© McGraw Hill 31
Can we model the demand curve? 5
• Example continued.
Access the text alternative for these images.
© McGraw Hill 32
Multiple regression: A Case of Cost of Internet
Customer ID Length of wire (in meter) Data Usage (in GB) Cost of Internet (in $)
1 67 42 98
2 64 17 70
3 66 28 78
4 65 24 82
5 45 16 58
6 55 17 62
7 65 23 82
8 66 32 85
9 66 34 86
10 62 35 81
11 43 17 57
12 66 24 78
13 66 24 85
14 64 15 68
15 65 22 81
16 64 23 70
17 66 31 82
18 66 24 80
19 65 26 79
20 59 12 67
© McGraw Hill
Correlation
Length of Wire
Data Usage (in
used Cost of Internet
GB)
(in Meter)
Length of Wire used
1
(in Meter)
Data Usage (in GB) 0.52224346 1
Cost of Internet 0.808272712 0.838295503 1
© McGraw Hill 34
Regression
SUMMARY OUTPUT
Regression Statistics
Multiple R 0.944175169
R Square 0.891466749
Adjusted R Square 0.878698131
Standard Error 3.600862694
Observations 20
ANOVA
Significance
df SS MS F
F
Regression 2 1810.524 905.2622 69.81701 6.34E-09
Residual 17 220.4256 12.96621
Total 19 2030.95
Standar Low Upp
Coefficients t Stat P-value Lower 95% Upper
d er er
95%
Error 95.0 95.
% 0%
Intercept 9.852906455 7.702495 1.279184 0.218018 -6.39794 26.10375 -6.39794 26.10375
Length of Wire used 0.768776598 0.141397 5.437015 4.44E-05 0.470455 1.067098 0.470455 1.067098
Data Usage (in GB) 0.771224293 0.12627 6.107722 1.16E-05 0.504817 1.037631 0.504817 1.037631
© McGraw Hill
Regression
Define the prediction model.
0 + β
=β
Y 1 𝑋1 + β
2 𝑋2 + ε
= 9.852 + 0.768𝑋1 + 0.771𝑋2
Y
© McGraw Hill 36
Regression
How good is this model?
= 9.852 + 0.768𝑋1 + 0.771𝑋2
Y
Adjusted R Square = 0.88
• Approx. 88% variation of the
internet cost is explained by this
model.
• This leaves 12% variation in the
cost unexplained.
© McGraw Hill 37
Regression
What will be the change in internet
cost for every 1 meter increase in
the length?
= 9.852 + 0.768𝑋1 + 0.771𝑋2
Y
For every 1 meter increase in the
length of wire, the internet cost is
estimated to increase on average
by 0.768.
© McGraw Hill 38
Regression
What will be the change in internet
cost for every 1 additional GB usage
of data?
= 9.852 + 0.768𝑋1 + 0.771𝑋2
Y
For every 1 additional GB usage, the
internet cost is estimated to increase
on average by 0.771.
© McGraw Hill 39
Regression
What will be the cost when
length is 52 m and data usage
is 17 GB?
= 9.852 + 0.768𝑋1 + 0.771𝑋2
Y
= 62.94
Y
© McGraw Hill 40
Practice
Salsberry Realty sells homes along the East Coast of the United States. One of the questions most
frequently asked by prospective buyers is: If we purchase this home, how much can we expect to pay to heat
it during the winter?
The analyst team at Salsberry has been asked to develop some guidelines regarding heating costs for
single-family homes. Three variables are thought to relate to the heating costs:
(1) the mean daily outside temperature,
(2) the number of inches of insulation in the attic (roof), and
(3) the age in years of the furnace.
To investigate, Salsberry’s research department selected a random sample of 20 recently sold homes. It
determined the cost to heat each home last January, as well as the January outside temperature in the
region, the number of inches of insulation in the attic, and the age of the furnace.
© McGraw Hill
Practice Data Set
Mean Outside Attic Insulation Age of Furnace
Home Heating Cost ($)
Temperature (°F) (inches) (years)
1 $250 35 3 6
2 360 29 4 10
3 165 36 7 3
4 43 60 6 9
5 92 65 5 6
6 200 30 5 5
7 355 10 6 7
8 290 7 10 10
9 230 21 9 11
10 120 55 2 5
11 73 54 12 4
12 205 48 5 1
13 400 20 5 15
14 320 39 4 7
15 72 60 8 6
16 272 20 5 8
17 94 58 7 3
18 190 40 8 11
19 235 27 9 8
20 139 30 7 5
© McGraw Hill 42
Practice Question
• Define the prediction model.
• What is the coefficient of determination? Is this a good
model?
• What is the estimated cost of heating if the mean outside
temperature is 30 degrees, there are 5 inches of
insulation, and the furnace is 10 years old?
© McGraw Hill 43
Regress
Practice
ion
Statisti
cs
Multiple R 0.896755299
R Square 0.804170066
Adjusted R Square 0.767451954
Standard Error 51.04855358
Observations 20
ANOVA
Significanc
df SS MS F
e F
Regression 3 171220.5 57073.49 21.90118 6.56178E-06
Residual 16 41695.28 2605.955
Total 19 212915.8
Standard Upper Lower Upper
Coefficients t Stat P-value Lower 95%
Error 95% 95.0% 95.0%
Intercept 427.19 59.60 7.17 0.00 300.84 553.54 300.84 553.54
Temperature -4.58 0.77 -5.93 0.00 -6.22 -2.95 -6.22 -2.95
Attic Insulation -14.83 4.75 -3.12 0.01 -24.91 -4.75 -24.91 -4.75
Age of Furnace 6.10 4.01 1.52 0.15 -2.40 14.61 -2.40 14.61
44
© McGraw Hill
Statistics
Practice
Multiple R 0.8967552
99
R Square 0.804
Adjusted R Square 0.767
Standard Error 51.04
Observations 20
ANOVA
Significanc
df SS MS F
e F
Regression 3 171220.5 57073.49 21.90118 6.56178E-06
Residual 16 41695.28 2605.955
Total 19 212915.8
Standard Upper Lower Upper
Coefficients t Stat P-value Lower 95%
Error 95% 95.0% 95.0%
Intercept 427.19 59.60 7.17 0.00 300.84 553.54 300.84 553.54
Temperature -4.58 0.77 -5.93 0.00 -6.22 -2.95 -6.22 -2.95
Attic Insulation -14.83 4.75 -3.12 0.01 -24.91 -4.75 -24.91 -4.75
Age of Furnace 6.10 4.01 1.52 0.15 -2.40 14.61 -2.40 14.61
45
© McGraw Hill
Practice
Define the prediction model. Is this a good model?
= 427.19 - 4.58*Temperature - 14.83*Attic insulation + 6.10*Age of
Y
furnace
Adjusted R-square = approx. 76.7%
Model is significant (p-value < 5%)
Each X is significant (each p-value < 5%)
What is the estimated cost of heating if the mean outside temperature
is 30 degrees, there are 5 inches of insulation, and the furnace is 10
years old?
= 427.19 - 4.58*Temperature - 14.83*Attic insulation + 6.10*Age of
Y
furnace
Cost of heating = 276.64
© McGraw Hill 46
THANK YOU!
© McGraw Hill 47