0% found this document useful (0 votes)
18 views32 pages

TSF - Week 2 - MLS0.2

Uploaded by

Amit Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views32 pages

TSF - Week 2 - MLS0.2

Uploaded by

Amit Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Time Series

Forecasting
(Forecasting)
Week-2

Proprietary content. ©Great Learning. All Rights Reserved. Una


uthorized use or distribution prohibited.
DSBA Curriculum
Design

Domain
Foundations Core Courses
Applications

• Data Science • Advanced Statistics • Financial Risk Analytics


Using Python • Data Mining • Marketing Retail Analytics
• Statistical • Predictive Modelling
Methods for • Machine Learning
Decision Making • Time Series Forecasting
• Data Visualization
• SQL

Proprietary content. ©Great Learning. All Rights Reserved. Una


uthorized use or distribution prohibited.
LEARNING OBJECTIVE
OF THIS SESSION
•Forecasting need and range

•Different types of forecasts

Proprietary content. ©Great Learning. All Rights Reserved. Una


uthorized use or distribution prohibited.
RY ANSWERING THE FOLLOWING
● A more complicated model which
estimates a lot of parameters usually
always performs better (i.e. gives a
better accuracy or less error) on the
training data. – True or False? Discuss.

● For Model Validation in a Time Series


Forecasting problem, the train and test
data can be randomly sampled. True or
False? Discuss.

Proprietary content. ©Great Learning. All Rights Reserved. Una


uthorized use or distribution prohibited.
Forecasting need and range
• Time series forecasting occurs when
you make scientific predictions
based on historical time-stamped
data.

• It involves building models through


historical analysis and using them to
make observations and drive future
strategic decision-making.

• Long-term forecast: 5 to 10 years ̶


Strategic decision making
• Mid-term forecast: 2 to 5 years ̶
Manpower hiring / Route alteration
• Short-term forecast: 2 weeks to 6
months ̶ Pilot / Cabin Crew rostering ̶
Dynamic pricing
Proprietary content. ©Great Learning. All Rights Reserved. Una
uthorized use or distribution prohibited.
Types of Forecasts
1. Moving Average

2. Naïve Forecast

3. SES(Simple Exponential
Smoothing) If the time series
neither has a pronounced trend
nor seasonality but has an
average value for a specific
time period.

4. DES(Double Exponential
Smoothing) Applicable when
time series data has a trend but
no seasonality

5. TES(Triple Exponential
Smoothing ) Applicable when
Proprietary content. ©Great Learning. All Rights Reserved. Una
time series data has a trenduthorized
anduse or distribution prohibited.
Ways to forecast
Based on past data one will use algorithms/models to predict the future
• Few simple methods to consider forecasting
1) Naïve forecast
2) Simple Average
3) Moving average
4) Linear Regression
5) Simple exponential smoothing
6) Double exponential smoothing (Holt’s model)
7) Triple exponential smoothing (Holt’s winter model)
Steps in forecasting

• Previous session -Problem definition (Knowing the horizon),


Gathering information, EDA

• This session
• Preparation of data
• Forecast using models
• Model evaluation
Preparation of data
Train dataset
Latest data

Old data
Test dataset

Split the data


• A part of sample data is used to train (develop) the model: Training Data
• A balance part from the above sample is : Test Data
• The forecasts for training data are called fitted values
Forecast using models
^
𝑌 (𝑡)− 𝐹𝑜𝑟𝑒𝑐𝑎𝑠𝑡𝑒𝑑 𝑉𝑎𝑙𝑢𝑒𝑠
Train dataset

Y(t) – Actual Test


data

• Performance of forecast method is tested by comparing the forecast values with actual test data

• Perform various model evaluation between actual (test data) and forecasted values(fitted values) through
various methods
Model evaluation : How to judge a
model?
Error = Actual– Forecast
• The model is selected to be the best where actual and forecasted values are the closest or the error is
low
Technique Abbreviation Forecast Error

෠‫ݐ‬
Forecast
Error/Bias/ ME ͳ
ߑ ܻ‫ ݐ‬െܻ
Mean Error ܶ


෠‫ݐ‬
Mean Squared ͳ
MSE ߑ ܻ‫ ݐ‬െ ܻ
Error ܶ

Root Mean
RMSE
Square Error

෠‫ݐ‬
Mean Absolute ͳ
MAD ߑ ܻ‫ ݐ‬െܻ
Deviation ܶ Where :
Y(t)- Actual
෠‫ݐ‬
Mean Absolute - Forecast
MAPE ͳ ܻ‫ ݐ‬െ ܻ
Percent Error ߑ ൈͳͲͲ T - # of Observations
ܶ ܻ‫ݐ‬
Method 1: Naïve forecast
Naïve Forecast Squared Sqaure Absolute Percent
Month Volume
Forecast Error Error root Error Error
Janaury 10 # NA
Naive forecasting places
February 12 10 2 4 2 2 16.67%
March 16 12 4 16 4 4 25.00% 100% weight on the
April 13 16 -3 9 3 3 23.08% most recent
May 17 13 4 16 4 4 23.53% observation
June 19 17 2 4 2 2 10.53%
July 15 19 -4 16 4 4 26.67%
It’s the most simple
August 20 15 5 25 5 5 25.00%
September 22 20 2 4 2 2 9.09% way of forecasting
October 19 22 -3 9 3 3 15.79%
November 21 19 2 4 2 2 9.52%
December 19 21 -2 4 2 2 10.53%

Forecast
0.818 RMSE 3.177 MAD 3.00
Error
MSE 10.09 MAPE 17.76%
Method 1a: Naïve forecast

Forecast Squared Sqaure Absolute Percent


Month Volume Naïve Forecast
Error Error root Error Error
Janaury 10 19 -9 81 9 9 90.00%
February 12 19 -7 49 7 7 58.33%
March 16 19 -3 9 3 3 18.75%
April 13 19 -6 36 6 6 46.15%
May 17 19 -2 4 2 2 11.76%
June 19 19 0 0 0 0 0.00%
July 15 19 -4 16 4 4 26.67%
August 20 19 1 1 1 1 5.00%
September 22 19 3 9 3 3 13.64%
October 19 19 0 0 0 0 0.00%
November 21 19 2 4 2 2 9.52%
December 19 19 0 0 0 0 0.00%

Forecast
-2.083 RMSE 4.173 MAD 3.08
Error
MSE 17.42 MAPE 23.32%
Method 2: Average Forecast

Average Forecast Squared Sqaure Absolute Percent


Month Volume
Forecast Error error root Error Error
Janaury 10 16.92 -6.92 47.84 6.92 6.92 69% To forecast one simply
February 12 16.92 -4.92 24.17 4.92 4.92 41%
March 16 16.92 -0.92 0.84 0.92 0.92 6%
considers the average of
April 13 16.92 -3.92 15.34 3.92 3.92 30% observations for a
May 17 16.92 0.08 0.01 0.08 0.08 0% particular time period
June 19 16.92 2.08 4.34 2.08 2.08 11%
July 15 16.92 -1.92 3.67 1.92 1.92 13%
August 20 16.92 3.08 9.51 3.08 3.08 15%
September 22 16.92 5.08 25.84 5.08 5.08 23%
October 19 16.92 2.08 4.34 2.08 2.08 11%
November 21 16.92 4.08 16.67 4.08 4.08 19%
December 19 16.92 2.08 4.34 2.08 2.08 11%

Forecast
0.000 RMSE 3.616 MAD 3.10
Average 203 16.92 Error
12 MSE 13.08 MAPE 20.84%
Method 3: Moving average/Rolling average

Moving Average Forecast Squared Sqaure Absolute Percent


Month Volume
Forecast Error error root Error Error
Janaury 10
• Forecast future values by
February 12 Three month Moving Average using an average of n
March 16
April 13 10 12 16 12.7 0.33 0.11 0.33 0.33 3% number of previous values
May 17 12 16 13 13.7 3.33 11.11 3.33 3.33 20%
June 19 16 13 17 15.3 3.67 13.44 3.67 3.67 19% • Reveals the trend and level
July 15 13 17 19 16.3 -1.33 1.78 1.33 1.33 9% in the series
August 20 17 19 15 17.0 3.00 9.00 3.00 3.00 15%
September 22 19 15 20 18.0 4.00 16.00 4.00 4.00 18% • Removes the seasonal and
October 19 15 20 22 19.0 0.00 0.00 0.00 0.00 0%
November 21 20 22 19 20.3 0.67 0.44 0.67 0.67 3% noise components from the
December 19 22 19 21 20.7 -1.67 2.78 1.67 1.67 9% series
Forecast Error 1.333 RMSE 2.465 MAD 2.00
MSE 6.07 MAPE 10.61%
Method 4: Linear Regression
Linear Regression Forecast Squared Sqaure Absolute Percent
Month Volume
Forecast Error Error root Error Error Linear Regression
Janaury 10 19.99 -9.99 99.76 9.99 9.99 100% 25
February 12 21.74 -9.74 94.93 9.74 9.74 81%
March 16 25.25 -9.25 85.63 9.25 9.25 58% 20 f(x) = 0.877622377622378 x + 11.2121212121212
R² = 0.7019114714282
April 13 22.62 -9.62 92.56 9.62 9.62 74% 15
May 17 26.13 -9.13 83.38 9.13 9.13 54%

Volume
June 19 27.89 -8.89 78.97 8.89 8.89 47% 10
July 15 24.38 -9.38 87.91 9.38 9.38 63%
5
August 20 28.76 -8.76 76.81 8.76 8.76 44%
September 22 30.52 -8.52 72.58 8.52 8.52 39% 0
0 2 4 6 8 10 12 14
October 19 27.89 -8.89 78.97 8.89 8.89 47%
Month
November 21 29.64 -8.64 74.68 8.64 8.64 41%
December 19 27.89 -8.89 78.97 8.89 8.89 47%

Forecast
-9.141 RMSE 9.152 MAD 9.14
Error
MSE 83.76 MAPE 57.76%

Forecast is done based on the relationship between the dependent and independent
variable
Exponential Smoothing

• Weights are added on the observations. Weights decay as observations get older
• Practically speaking, only the recent observations matter
• Alpha (α) acts as a parameter to control how fast the weights decay
Simple Exponential Smoothing(SES)

• If the time series does neither have a pronounced trend nor seasonality: Almost non-available! OR data with no trend or seasonal pattern

Why Exponential?
Y (t+1) = αY(t)+α (1-α)Y(t-1)

= αY(t)+ (1-α)[α Y(t-1) + α (1-α) Y(t-2)]

= αY(t)+ α (1-α)Y(t-1) + α (1-α)2Y(t-2) + α (1-α)3Y(t-3)

• The weight of each observation is determined by smoothing parameter (α).


• SES is usually applied for shorter time period
• Effective in inventory planning
Tuning parameter α

• Smoothing parameter α corresponds


to the level series

• If α is near 1, past values have no


influence over the forecast (under
smoothing)

• If α is near 0, past values have equal


influence on forecast (over smoothing)
Method 5 : Simple Exponential
Smoothing
෠ ‫ ݐ‬െͳ ෠ ‫ ݐ‬െͳ
෠‫ݐ‬
Volume SES forecast Forecast Squared Sqaure Absolut
Month ܻ α Y(t-1) ܻ
(Actual Y(t)) ܻ Error Error root e Error
Janaury 10 10.00 0.1 #NA #NA #NA
February 12 10.00 0.1 10 10.00 10 2.00 4.00 2.00 2.00
March 16 10.00 0.1 12 10.00 10.2 5.80 33.64 5.80 5.80
April 13 10.20 0.1 16 10.20 10.78 2.22 4.93 2.22 2.22
May 17 10.78 0.1 13 10.78 11.00 6.00 35.98 6.00 6.00
June 19 11.00 0.1 17 11.00 11.60 7.40 54.73 7.40 7.40
July 15 11.60 0.1 19 11.60 12.34 2.66 7.07 2.66 2.66
August 20 12.34 0.1 15 12.34 12.61 7.39 54.65 7.39 7.39
September 22 12.61 0.1 20 12.61 13.35 8.65 74.88 8.65 8.65
October 19 13.35 0.1 22 13.35 14.21 4.79 22.92 4.79 4.79
November 21 14.21 0.1 19 14.21 14.69 6.31 39.81 6.31 6.31
December 19 14.69 0.1 21 14.69 15.32 3.68 13.53 3.68 3.68

Forecast
5.172 RMSE 5.610 MAD
Error
MSE 31.47 MAPE 28.44%
Double Exponential
Smoothing(DES)
• Applicable when data has Trend but no seasonality
• An extension of SES
• Two separate components are considered: Level and Trend
• Level is the local mean
• One smoothing parameter α corresponds to the level series
• A second smoothing parameter β corresponds to the trend series
• Also known as Holt model
Holts method

• The k-step-ahead forecast is given by combining the level estimate at time t (Lt) and the trend estimate at
time t (Tt).

level at time t is a weighted average of the


actual value at time t and the level in the
previous period, adjusted for trend

trend at time t is a weighted average of


the trend in the previous period and the
more recent information on the change
in the level
Method 6: Double Exponential
Smoothing
Alpha 0.2
Beta 0.6
Holt method
DES Forecast Squared Sqaure Absolute Percent
Month Volume Level(Lt) Trend(Tt) Y(t+1)
forecast Error Error root Error Error
Janaury 10 # NA
February 12 12.00 2 # NA
March 16 14.40 2.24 14 14.00 2.00 4.00 2.00 2.00 13%
April 13 15.91 1.8 16.6 16.6 -3.64 13.25 3.64 3.64 28%
May 17 17.57 1.7 17.7 17.7 -0.72 0.51 0.72 0.72 4%
June 19 19.23 1.7 19.3 19.3 -0.29 0.08 0.29 0.29 2%
July 15 19.73 1.0 20.9 20.9 -5.91 34.98 5.91 5.91 39%
August 20 20.56 0.9 20.7 20.7 -0.70 0.50 0.70 0.70 4%
September 22 21.56 1.0 21.5 21.5 0.55 0.30 0.55 0.55 2%
October 19 21.81 0.5 22.5 22.5 -3.52 12.36 3.52 3.52 19%
November 21 22.08 0.4 22.3 22.3 -1.34 1.81 1.34 1.34 6%
December 19 21.76 0.0 22.4 22.4 -3.45 11.88 3.45 3.45 18%

Forecast Error -1.702 RMSE 2.823 MAD 2.21


MSE 7.97 MAPE 13.47%
Triple Exponential Smoothing(TES)-Holt-Winters Seasonal
Method

• To make predictions using data with a trend and seasonality,


• “Additive” structure or a “Multiplicative” structure, where the choice of method depends on
the data set.
• The Additive model is best used when the seasonal trend is of the same magnitude
throughout the data set
• Multiplicative Model is preferred when the magnitude of seasonality changes as time
increases.
Holt winters equation

where α, β, and γ are the three smoothing parameters to deal with the level pattern,
the trend, and the seasonality, respectively.

• Smooths level - 0<α<1


• Smooths Trend - 0<ᵦ <1
• Smooths Seasonality - 0<γ<1
Summary : Forecast of MA better
than other models

Technique Forecast Error MSE RMSE MAPE MAD


Naïve Forecast 0.82 10.09 3.18 18% 3.00
Average Forecast 0.00 13.08 3.62 21% 3.10
Moving Average Forecast 1.33 6.07 2.46 11% 2.00
Linear Reg Forecast -9.14 83.76 9.15 58% 9.14
SES Forecast 5.17 31.47 5.61 28% 5.17
DES Forecast -1.70 7.97 2.82 13% 2.21
Choice of exponential smoothing

Level data Data with level & trend Data with level, trend &
• Moving average • Holts method (α, β) seasonality
• Simple exponential • Holt winters (α, β, )
smoothing (α)

27
Industry Application – Predicting
Government Spending

• Time Series Forecasting procedures are often used in Public


Policymaking. The government has to have an idea about the national
income and the corresponding tax collections.
• Certain regulations can be changed or altered keeping in mind the
upcoming future forecasts. Various economic decisions are taken
based on these future predictions. When a model is being fitted for
such an application, usually white-box models are preferred.

Proprietary content. ©Great Learning. All Rights Reserved. Una


uthorized use or distribution prohibited.
se Study - Predicting Monthly Sales of a Store

In this particular case study, we are going to look at some of the


descriptive measures of statistics to understand the data a bit better.
Then we will go ahead and split the data into training and testing.
After this, we will build diff erent models on the data and choose the
most optimum model.

The objective of this session is to predict the monthly sales of a


particular store for some future time stamps.

Proprietary content. ©Great Learning. All Rights Reserved. Una


uthorized use or distribution prohibited.
ANY QUESTIONS
Proprietary content. ©Great Learning. All Rights Reserved. Una
uthorized use or distribution prohibited.
DATA SCIENCE @ work
Apply Data Science at your workplace to gain some instant benefits:

• Get noticed by your management with your outstanding analysis backed by data
science.

• Create an impact in your organization by taking up small projects/initiatives to solve


critical issues using data science.

• Network with members from the data science vertical of your organization and seek
opportunities to contribute in small projects.

• Share your success stories with us and the world to position yourself as a subject matter expert
in data science.

Proprietary content. ©Great Learning. All Rights Reserved. Una


uthorized use or distribution prohibited.

You might also like