L5 - Forecasting
L5 - Forecasting
Applications
• Subjective methods
• Methods based on intuition, experience
• time series is modeled to determine its • uses the information in a time series to
indexed set of
equally spaced
measures
2007 2019
Accumulation and Interpretation
Missing,
Accumulation Zero Value
Interpretation
08/09/2022 14
12/09/2022 7
19/09/2022 17
Date Website Visits
23/09/2022 5
09/2022 -
01/10/2022 12
10/2022 -
09/10/2022 8
14/10/2022 13
transactional 20/10/2022 15
data
Accumulation – Method within Interval
transactional 20/10/2022 15
data
Accumulation – Method within Interval
transactional 20/10/2022 15
data
Accumulation – Method within Interval
01/2022 24 01/2022 24
02/2022 11 02/2022 11
03/2022 54 03/2022 54
04/2022 0 04/2022 40
05/2022 64 05/2022 64
06/2022 . 06/2022 40
07/2022 46 07/2022 46
08/2022 27 08/2022 27
09/2022 54 09/2022 54
Accumulated Interpreted
time series time series
Time Series Components
Time Series Components
• Seasonality: repeating patterns that occur at regular intervals within the data
• A cycle occurs when the data exhibit rises and falls that are not of a fixed frequency.
• These fluctuations are often associated with economic, political, or societal factors and may
span multiple seasons or years
Seasonal or Cyclic?
Seasonal Cyclic
• no seasonality
• downward trend
• long cycle?
1. Data collection
Time Series Forecasting Steps
1. Data collection
1. Data collection
3. Data preprocessing
Time Series Forecasting Steps
1. Data collection
3. Data preprocessing
1. Data collection
3. Data preprocessing
5. Model selection
Time Series Forecasting Steps
1. Data collection
3. Data preprocessing
5. Model selection
6. Model training
Time Series Forecasting Steps
1. Data collection
3. Data preprocessing
5. Model selection
6. Model training
7. Model evaluation
Time Series Forecasting Steps
1. Data collection
3. Data preprocessing
5. Model selection
6. Model training
7. Model evaluation
8. Model tuning
Time Series Forecasting Steps
3. Data preprocessing
5. Model selection
6. Model training
7. Model evaluation
8. Model tuning
Time Series Forecasting Steps
3. Data preprocessing
5. Model selection
6. Model training
7. Model evaluation
8. Model tuning
Time Series Forecasting Steps
5. Model selection
6. Model training
7. Model evaluation
8. Model tuning
Time Series Forecasting Steps
5. Model selection
6. Model training
7. Model evaluation
8. Model tuning
Model Evaluation
Model Evaluation
• Visualization: examining time plots of the actual and predicted series can
shed light on performance and hint toward possible improvements
Naïve Forecasts
• A naive forecast is the most recent value of the series: at time t, the forecast
for any future period t+k is simply the value of the series at time t
MAE
Example: MAE
ACTUAL ABSOLUTE VALUE OF
YEAR SALES OF WIRELESS FORECAST SALES ERRORS (DEVIATION),
SPEAKERS (ACTUAL – FORECAST)
1 110 —
2 100 110
3 120 100
4 140 120
5 170 140
6 150 170
7 160 150
8 190 160
9 200 190
10 190 200
11 — 190
Example: MAE
ACTUAL FORECAST SALES ABSOLUTE VALUE OF
YEAR SALES OF WIRELESS ERRORS (DEVIATION),
SPEAKERS naïve model
(ACTUAL – FORECAST)
1 110 —
2 100 110
3 120 100
4 140 120
5 170 140
6 150 170
7 160 150
8 190 160
9 200 190
10 190 200
11 — 190
Example: MAE
ACTUAL FORECAST SALES ABSOLUTE VALUE OF
YEAR SALES OF WIRELESS ERRORS (DEVIATION),
SPEAKERS naïve model
(ACTUAL – FORECAST)
1 110 — —
2 100 110 |100 – 110| = 10
3 120 100 |120 – 100| = 20
4 140 120 |140 – 120| = 20
5 170 140 |170 – 140| = 30
6 150 170 |150 – 170| = 20
7 160 150 |160 – 150| = 10
8 190 160 |190 – 160| = 30
9 200 190 |200 – 190| = 10
10 190 200 |190 – 200| = 10
11 — 190 —
Sum of |errors| = 160
MAE = 160/9 = 17.8
Example: MAE
ACTUAL ABSOLUTE VALUE OF
YEAR SALES OF WIRELESS FORECAST SALES ERRORS (DEVIATION),
SPEAKERS (ACTUAL – FORECAST)
1 110 — —
2 100 110 |100 – 110| = 10
3 120 100 |120 – 100| = 20
4 140 120 |140 – 120| = 20
5 170 140 |170 – 140| = 30
∑ 𝑓𝑜𝑟𝑒𝑐𝑎𝑠𝑡 𝑒𝑟𝑟𝑜𝑟 160
6 150 𝑀𝐴𝐸 = 170 = = 17.8
|150 – 170| = 20
𝑛 9
7 160 150 |160 – 150| = 10
8 190 160 |190 – 160| = 30
9 200 190 |200 – 190| = 10
10 190 200 |190 – 200| = 10
11 — 190 —
Sum of |errors| = 160
MAE = 160/9 = 17.8
Measures of Forecast Accuracy
MSE ∑(𝑒𝑟𝑟𝑜𝑟)!
𝑀𝑆𝐸 =
𝑛
MAPE
Accuracy as a percentage of the error
𝑒𝑟𝑟𝑜𝑟
∑
𝑀𝐴𝑃𝐸 = 𝑎𝑐𝑡𝑢𝑎𝑙 x 100%
𝑛
• BIAS
Tells if the forecast it too high/low and by how much ∑ 𝑒𝑟𝑟𝑜𝑟
𝐵𝐼𝐴𝑆 =
𝑛
Model Selection
Model Selection
Forecasting Methods
Exponential
ARIMA …
Smoothing
… …
Model Selection: Smoothing Methods
Smoothing Methods
Moving Average
Moving Average
Centered Moving Average (CMA)
n=5
January 10
February 12 (10 + 12 + 13)/3 = 11.67
March 13 (12 + 13 + 16)/3 = 13.67
April 16 (13 + 16 + 19)/3 = 16.00
May 19 (16 + 19 + 23)/3 = 19.33
June 23 (19 + 23 + 26)/3 = 22.67
July 26 (23 + 26 + 30)/3 = 26.33
August 30 (26 + 30 + 28)/3 = 28.00
September 28 (30 + 28 + 18)/3 = 25.33
October 18 (28 + 18 + 16)/3 = 20.67
November 16 ??
December 14
Simple Moving Average (SMA)
The next forecast is the average of the most recent n data values from the time
series
n values
Wallace Garden Supply wants to forecast the monthly demand for its Storage
Shed
January 10
February 12
March 13
April 16
May 19
June 23
July 26
August 30
September 28
October 18
November 16
December 14
January —
Example: Wallace Garden Supply
January 10
February 12
March 13
April 16 (10 + 12 + 13)/3 = 11.67
May 19 (12 + 13 + 16)/3 = 13.67
June 23 (13 + 16 + 19)/3 = 16.00
July 26 (16 + 19 + 23)/3 = 19.33
August 30 (19 + 23 + 26)/3 = 22.67
September 28 (23 + 26 + 30)/3 = 26.33
October 18 (26 + 30 + 28)/3 = 28.00
November 16 (30 + 28 + 18)/3 = 25.33
December 14 (28 + 18 + 16)/3 = 20.67
January — ???
Example: Wallace Garden Supply
January 10
February 12
March 13
April 16 (10 + 12 + 13)/3 = 11.67
May 19 (12 + 13 + 16)/3 = 13.67
June 23 (13 + 16 + 19)/3 = 16.00
July 26 (16 + 19 + 23)/3 = 19.33
August 30 (19 + 23 + 26)/3 = 22.67
September 28 (23 + 26 + 30)/3 = 26.33
October 18 (26 + 30 + 28)/3 = 28.00
November 16 (30 + 28 + 18)/3 = 25.33
December 14 (28 + 18 + 16)/3 = 20.67
January — (18 + 16 + 14)/3 = 16.00
Weighted Moving Average (WMA)
3 Last month
3 x Sales last month + 2 x Sales two months ago + 1 x Sales three months ago
January 10
February 12
March 13
April 16 [(3 X 13) + (2 X 12) + (10)]/6 = 12.17
January — ???
Example: Wallace Garden Supply
January 10
February 12
March 13
April 16 [(3 X 13) + (2 X 12) + (10)]/6 = 12.17
• domain knowledge in terms of relevance of past values and how fast the
series changes
• Easy to use
Ft+1 = Ft + α (Yt − Ft )
where
Ft+1 = new forecast (for time period t + 1)
Ft = previous forecast (for time period t)
a = smoothing constant (0 ≤ a ≤ 1)
Yt = previous period’s actual demand
Ft+1 = Ft + α (Yt − Ft )
• value close to 1 indicates fast learning (that is, only the most recent values
have influence on forecasts)
• value close to 0 indicates slow learning (past values have a large influence
on forecasts)
FORECAST
ACTUAL TONNAGE FORECAST
QUARTER USING
UNLOADED USING a = 0.10
a = 0.50
Σ|errors|
MAE = !
= 10.31 MAE = 12.33
Example - Port of Baltimore
Absolute Deviations and MAEs
ACTUAL FORECAST ABSOLUTE FORECAST ABSOLUTE
QUARTER TONNAGE WITH DEVIATIONS FOR WITH DEVIATIONS FOR
UNLOADED a = 0.10 a = 0.10 a = 0.50 a = 0.50
1 180 175 5 175 5
Σ|errors|
MAE = !
= 10.31 MAE = 12.33
Advanced Exponential Smoothing
Model Selection: Regression Methods
Model with Seasonality
• For seasonality: create a new categorical variable that denotes the season for each
value
• 13 predictors:
• 11 dummies for month,
• and x and x2 for trend
ARIMA
ARIMA
Stationarity of a time series models
https://www.oreilly.com/library/view/hands-on-machine-learning/9781788992282/15c9cc40-
bea2-4b75-902f-2e9739fec4ae.xhtml