Lecture 05 - Predictive Analytics: Exponential Smoothing and Regression Analysis

IIT Roorkee July 201
61 followers
Jan 4, 2025
[Music]
[Music]
welcome friends so in our uh last class
we discussed the applications of
Predictive Analytics for forecasting
purpose we discussed that how you can uh
use very simple methods of Predictive
Analytics just uh you need to understand
the pattern of your data and uh we
started with a use case of forecasting
that if you can see the pattern of the
data and try to extrapolate the same
pattern you can make decisions about the
forecast FAS we discussed that how
moving average methodologies are so
simple to apply that you are taking
average of past periods and that average
of past period is the forecast for the
next period in the last of the Season uh
class we discussed about uh more
improved method in the form of
exponential smoothing methods where we
discuss that how on a regular basis we
can improve our forecast and we will try
to reduce the uncertainty in our
forecast because whatever uncertainities
are happening in the current period we
are trying to incorporate some component
of that uncertainity in our
forecast that is what we are going to
discuss in this session also and another
very popular method of Predictive
Analytics that is regression analysis
will also be we discussed in this
particular class now what we were
discussing in the previous session about
uh exponential smoothing method and we
discussed that exponential smothing is
uh simply the smoothening of the
fluctuations by applying a particular
way of incorporating some of these
fluctuations in my base data and I will
continuously improve the base data I was
talking in my last class
that this is
how my past data is moving now here I am
today and I want to forecast for this
next period This is my period
T and I want to
forecast for period t + 1 now what we do
as we have already discussed that any
demand data has two components some
component we call as label component
because uh this data is also consist of
let's
say this dotted line you see this is the
label data so I will
determine this label value for the
current period which I say St and this
label value of the current period I
assume will remain same for the next
period
so this St for the next period will
become my
forecast for this period Next Period and
for getting the value of St for the
current period I have two very important
piece of
data this is T minus
one so at T minus one what was the
base St minus1
and what is the demand in the current
period
DT so the current base
St is basically a function of the
current
demand and the base of
previous period and this can be
represented in this simple
equation where this Alpha is a smoothing
constant value of
alpha varies from 0 to
1 and uh you may take more common values
which are generally generally Alpha
is though 0 to 1 but common is
1
2 3 these are generally the common
values of alpha which uh we generally
use in our uh practical purposes now if
you just simplify that this becomes
Alpha DT + 1 - Alpha into St minus1 so
whatever is your current demand for
example if my current demand is uh let's
say DT
is 100
St minus 1 is 90 so stus 1 90 means for
my current period i forecasted 90 units
but the actual demand came to be 100
units I want to forecast for the next
period so what I'm going to do let me
take Alpha equals
to2 so with this data 2 into DT 100
+8 into
90 that becomes my
St and that is
20 +
72 92 is my current base value and this
92 which is my current base value will
become the forecast for the next period
now in this I have updated my current
base from 90 to 92 and how could I do
this because I realize that there is a
gap of 10 units in my forecast and
actual demand for the current period so
I considered some fluctuation that I
should take some of these fluctuations
I'm not taking the 100% fluctuation I'm
taking only 20% of the current period
fluctuation for improving my forecast
and uh two units % of 10 is 2 so 90 + 2
92 is my new base and that new base is
my
forast similarly when I will reach to
this particular period I will get a new
DT
one and in that iterative manner I will
continuously improve my forecast so if I
see one practical example the data which
we used in our previous uh class also
that this is the four period
data W1 W2 W3
W4
for month of
April data is like 38 35
77 and 90 now exponential is smoothing I
have to use Alpha is given to me as 0.1
I have to determine forecast for
Week 1 of
may now forecast for Week 1 of May is
basically as of week four of
April so with this data I will try to
calculate what is the base for fourth
week of April whatever is the base for
fourth week of April that will become my
forecast for first week of May
now to start this process in a iterative
manner let me start with the first
period of April month and for that first
period of April month let me consider
the data is W1 W2 W3 W4 now for first
period the forecast is given to me is
60 and that 60 we have calculated
by the process of initialization and
that process of initialization is
simply the average value of four demands
so the average value of for demand is
calculated on the screen and that is
coming to be
60 so this is the calculation of initial
base and this initial base is the
forecast for the first period and now
the actual demand for the first period
is 38 so you get fub1 minus D1 = to
22 now you see that formula for our
calculation is St = to St minus 1 now s
is given to you we have to calculate S1
which will be
Alpha D1 + 1 -
alpha s
now D1 is 38 Alpha we have
taken 9 into
60 this will come as S1 when I calculate
S2 it will be Alpha
D2 + 1 - Alpha
S1 now this S1 will come
here D2 is given to us that is 35
using S1 and D2 you will calculate
S3 Alpha
D3 + 1 - Alpha
S2 and then you will calculate
S4 here you will use D3 = to
77 Alpha
D4 + 1 - Alpha
S3 where you will use D4 = to
90 and this
S4
is
forecast
for first week of
May so in this systematic iterative
manner you will calculate the forecast
for the period of May and uh this is how
the calculation will take place like1
into 38 +.9 into 60 and as I just
explained you can continuously do these
calculations and
finally you may check your calculation
that F5 that is the S4 F5 is
basically S4 this will come to be
60.90 after understanding this uh
exponential smoothing method it is also
important to understand that exponential
smoothing is possible in variety of ways
like uh for
example we in this particular case used
only
label but you can use label and Trend
also you can use
label
Trend seasonal Factor also and there may
be fluctuations in Trend also there may
be fluctuation in seasonal Factor also
so here you are using only Alpha here
you will use Alpha and
beta and here you will use alpha beta
and gamma also so depending upon how
many different uh type of
characteristics you are taking in your
past data more number of
smoo ring constants may be required all
these smooth ring constants
have 0 to one
variation all these smooth ring
constants have 0 to one variation before
I go further I will like to tell you one
more thing that if you see this
particular equation Alpha DT + 1 - alpha
s minus 1 so generally all other
equations will be also in the same way
Alpha
DT + 1 - alpha s tus 1 is the formula
for calculating new base now all the
smoothing constants are between 0 to one
whether it is Alpha whether it is beta
whether it is gamma popular values are
between .1 to3 these are popular
values this is possible values
now between this 0 to 1 sometime you
will see that you take extreme values of
either zero or one these are the extreme
values either 0o or one if you take a
extreme value of alpha = to 0 what
happens St = to St minus 1 if Alpha = to
1 what happens St = to DD
now what do you infer from these two
extreme cases if Alpha = to 0 and Alpha
= to 1 if Alpha = to
0 our new base is equal to Old base it
means we have totally ignored the
fluctuations I do not want to include
any of the fluctuation for estimation of
my new base these fluctuations are of
very temporary reason they should not be
used for updating the forecast values so
I want to ignore these
fluctuations and when Alpha equals to 1
it means I totally ignore my past base
the demand has a new characteristic
there are some permanent uh changes in
the way and therefore I Am shifting to a
new base label that is represented by
new demand data I do not want to include
the fluctuations or the data of the past
so these are the two extreme cases of
Alpha = to0 and L = to 1 in one case I
am totally ignoring the present
happenings and in one case I am
accepting only the present things and
totally ignoring the past data so these
are two special cases now after
understanding the exponential smoothing
uh basic method Now we move
to another very popular Predictive
Analytics tool that is the regression
analysis and regression analysis I hope
most of you are already aware that how
useful it is not only useful how
efficient also it is initial efforts are
required in developing the regression
analysis because uh it is something like
uh you
have a dependent
variable which is
depending on some number
of independent variable so my first
effort dependent variable I always
know known means I know what I want to
determine known means the value is not
known but I know what is to be
determined that is the meaning of known
here but this Factor Y which I want to
determine on what factors this is
depending what can be X1 X2 X3 and xn
this requires my understanding also so
identifying the right factors
independent factors which may affect the
value of y that is a important
challenge that is number one second is
developing a proper mathematical
relation between this dependent variable
and independent variable is another
challenge so that these independent
variables with that proper mathematical
expression can explain the variation in
uh dependent variable so these are two
very important things which are required
for regression analysis now in this
particular session I'm talking about a
special type of very simple case of
regression method that is simple linear
regression
model which
is having only one independent variable
this is independent
variable this is dependent variable
and since it's a linear function so the
relation between X and Y is a linear
function y =
to mx +
C something of this type
where you have uh
m c m is a kind of a parameter for x and
C is also a kind of a
constant with the help of M and C you
are able to develop a relationship
between X and Y so whenever we are
trying to develop a relation between uh
Y and X our job is to identify to
calculate the value of M and C so that a
specific relation between Y and X X can
be
established however uh there may be more
complex relations between Y and X but uh
we are beginning our discussions so I'm
considering only simple linear
regression model in some case let's say
y = x² this is another possibility y =
under root X Y = to sin
x all these are
other possible
relations and there may be many more
such relations it's not simply these
three relations are complete you can
create infinite type of relations
between Y and X but my interest is in
this linear
relation however it is quite possible
that the value of this constant C may be
zero also in some case and if it is zero
then in that case it may be simply y =
mx so it is also a linear linear uh
relation so linear relation may also
take uh some forms it may be y = to - MX
it is also acceptable but there cannot
be a power to the X variable that is the
meaning of
linearity you can see on your screen
some of the relations between Y and X
here these pictures are good enough to
tell you that uh because y =
to mx + C we are developing this
relationship and in this
relationship if Y
is like
this then it means as X is moving Y is
also moving in the similar
direction that is a strong relationship
but if you see the
right hand side images here Y is quite
scattered and when it is
scattered it is uh not very sure because
when X is moving let's say
here one possibility of Y this
also and another possibility this
also and another possibility is this
also
so here in this case the relationship
which we will be developing y = mx + C
is not going to give you a very good uh
you can say estimation prediction of Y
because for one value of i x there are
different possible values of Y but my
relation will give you only one value
and Y may take any other value also so
therefore our regression analysis will
have low
predictability and here very high
predictions if you have strong
relationship and sometime this strong
and weak relationships are possible
because of wrong identification of X
whether the correct X is taken or not on
that also this strong and weak
relationships may vary this is a very
generic uh you can say expression for
representing your regression equation Y
is the dependent variable as we have
already
discussed this is uh because the
regression
equation is uh like
this it is X this is y and this is that
line which is the line of regression now
this line is
intercepting this y AIS here this
interception of y- AIS is beta KN or
which I was saying earlier as C
also
then there is a coefficient of the slope
of X and then there is a random error
term also
if you see on this particular uh
diagram it is very well
articulated xaxis Y axis this is the
line regression
line and on this regression line if you
see this is The Intercept on the y- axis
which is B KN this intercept the slope
of this line is actually can be seen
from here that is beta 1 which is the
coefficient for independent variable
XI and then the random error term that
when you the meaning of this random
error is that for any value of x x
i you are estimating y here this is the
estimated value predicted value of y but
the observed value of y may be different
like here we have shown here but it can
be here also predicted value will always
be on the line predicted value of the
variable will always be on this line of
regression it is possible that uh
observed value of y may also be on the
same line or observed value may be at
the height or at the lower place of the
line also so the difference between
predicted value and the observed value
that is basically your error term random
error at particular value of x so that
is how in this diagram you are able to
understand the meaning of this linear
regression equation generally for our uh
calculation purpose we are using this
equation this is y + B + B1 X1 which is
the case of simple linear regression
model and uh as we discussed already
whenever we are going to use any kind of
model we will be using that model for
estimating the values of B KN and B1 and
here if you see uh we are uh we can use
very conveniently Excel because it is
easy to use but you can always find so
many other softwares also which are
dedicated
for this kind of Predictive Analytics
you can use matlb you can do programming
in Python also you can use SPSS all
these are the different types of
softwares and solutions which are
available for getting you a reg gration
equation there may be some minor
difference for the same data if you use
uh different Computing Solutions there
may be some minor differences because of
the rounding issues uh in the
calculations for uh B not and B1 for
example if I take uh this particular
case where a particular real estate
agent he wishes to examine the
relationship between the selling price
of a home and its
size that uh generally we expect that if
the size of a particular house is bigger
the selling price will also be bigger
now I want to develop the relation that
the price of a house is a function of
the area of the house let me say house
prices is a function
of area of
house this is what relationship I think
is there now whether the price of a
house is double the area triple the area
four times the area or whatever is the
relation that we want to see in this
particular case now we have taken uh
sample of 10 houses and we know from
that sample of 10 houses that uh
price
area house
number 1 to 10 their prices are given to
us and areas are also available to us
and then with the help of
of area on x-axis price on Y axis if
area is this much this much area what is
the price area is this much what is the
price area is this much what is the
price for same area it is possible that
two prices may be available because you
all can easily understand that house
price may also be very much dependent
upon the location also not only the area
but the location where it is house
prices may depend on various other
factors also how close is your house uh
location to the market so these are the
different factors which may affect the
house price So based on those things we
may go for more complex uh regression
equation also but since in this example
we are considering only one variable
that is the area of the house and using
this data
of 10 houses 1 2 3 4 5 6 7 8 9
10 now this is the independent variable
this is the dependent variable and we
are looking to develop this
relationship now there are rade
softwares available and uh this is what
the scatter plot you are going to get
when you are putting this data in any of
the Excel uh table and uh you can
generate this uh scatterer plot from the
data now if you see the regression
equation will be something like this on
this which is also known as line of
least
Square line of least Square because this
line line of least Square means this
line is the best representative of this
data this line is expressed as b + B1 X1
so this line is best representing this
data set and that is our regression
equation also and uh for that purpose if
you see we can do this in the form of
excel also where we have put this data
on the table and you can see the
screenshot of the excel in the screen
that is uh all the table data which I
was presenting here we have punched that
data in the Excel and then in the data
itself you can invoke this regression
option and when you invoke the
regression option you can see that one
field requires the Y range and another
field requires the X range y range means
the dependent variable X range means
independent variable and therefore we
have given the appropriate address for
both these ranges a12 A1 B12 b11 for
these two things we have also clicked
the
label because A1 and B1 here you see A1
and B1 these two fields are containing
the label of the data house price and
square feet respectively and then we
have uh clicked all okay and then we can
see the regression outcome the
regression outcome which comes is like
this type of outcome in the Excel table
uh which is uh easily readable now there
are many things which are available in
this table I will not go to all of them
at this moment I'm only
interested in this outcome where you get
the value of B
not and this is the value of
B1 B not is let's say
98 uh let us not make it very
complicated so you can say y equals
to
98
+10 area is into let's say x so that is
the simple equation you are getting
where the value of B KN is coming 98 and
value of B1 is
coming1 now you can put in this equation
the area of any new house and you can
estimate the possible price for this
particular house that is the Predictive
Analytics that you can predict that if
the area of the house is this much in
this city what can be the possible price
for that house we may discuss other
things which are available on the
outcome of this regression analysis but
since we have not gone into that aspect
it is not advisable to have uh that
discussion at the moment so we are
leaving uh that remaining discussion and
I hope with this we have understood the
basics of Predictive Analytics
particularly in the use of Time series
analysis in the use of moving average
and uh uh exponential smoothing as well
as in the use of regression analysis
with this we come to end of this
particular session thank you very much
[Music]
