Time Series Forecasting - Project Report
Time Series Forecasting - Project Report
Time Series Forecasting - Project Report
MACHINE LEARNING
Oct ‘21
Date: 25/10/2021
2
Table of Contents
Table of Contents.......................................................................................................................2
Table of Figures.........................................................................................................................3
1. Executive Summary............................................................................................................4
2. Introduction.........................................................................................................................4
3. Data Details.........................................................................................................................4
4. Read the data as an appropriate Time Series data and plot the data...................................5
4.1 Reading the Data.........................................................................................................5
4.2 Plotting the Data..........................................................................................................5
5. Perform appropriate Exploratory Data Analysis to understand the data and also perform
decomposition............................................................................................................................7
5.1. EDA.............................................................................................................................7
Null Value Check................................................................................................................7
Duplicate Value Check.......................................................................................................7
Data Description.................................................................................................................8
Yearly Box Plots.................................................................................................................8
Monthly Box Plots............................................................................................................10
Monthly Sales Across Years.............................................................................................11
Yearly Sum of Observations.............................................................................................13
Mean of Observations of each Year.................................................................................14
Sum of Observations of each Quarter...............................................................................15
5.2. Decomposition...........................................................................................................15
6. Split the data into training and test. The test data should start in 1991............................18
7. Build various exponential smoothing models on the training data and evaluate the model
using RMSE on the test data. Other models such as Regression, Naïve forecast models and
simple average models should also be built on the training data and check the performance on
the test data using RMSE.........................................................................................................21
7.1 Linear Regression......................................................................................................21
7.2 Naïve Model..............................................................................................................24
7.3 Simple Average Model..............................................................................................26
7.4 Moving Average Model............................................................................................29
Moving Average Model on the Rose Wine dataset:.........................................................32
Simple Average Model on the Sparkling Wine dataset:...................................................33
7.5 Simple Exponential Smoothing (SES)......................................................................34
7.6 Double Exponential Smoothing (DES).....................................................................38
3
Table of Figure
Figure 27: Moving Average Model Data for Rose and Sparkling wine respectively..............31
4
Figure 28: Moving Average Model Outcome on the Rose wine Time Series.........................32
Figure 29: Moving Average Model Outcome on the Sparkling Wine Time Series.................33
Figure 30: Summarized Performance of the Models...............................................................35
Figure 31: SES Parameters for the Rose and Sparkling wine datasets respectively................36
Figure 32: SES Train and Test data for Rose and Sparkling wine respectively......................37
Figure 33: Simple Exponential Smoothing Outcome on the Rose wine Time Series.............37
Figure 34: Simple Exponential Smoothing Outcome on the Sparkling Wine Time Series.....38
Figure 35: Summarized Performance of the Models...............................................................39
Figure 36: Alpha Beta values for Rose and Sparkling wine respectively................................40
Figure 37: Double Exponential Smoothing Outcome on the Rose wine Time Series.............41
Figure 38: Double Exponential Smoothing Outcome on the Sparkling Wine Time Series.....41
Figure 39: Summarized Performance of the Models...............................................................42
Figure 40: TES Parameters for the Rose and Sparkling wine datasets respectively................43
Figure 41: TES Model Train and Test data for Rose and Sparkling wine respectively...........43
Figure 42: Triple Exponential Smoothing Outcome on the Rose wine Time Series...............44
Figure 43: Triple Exponential Smoothing Outcome on the Sparkling Wine Time Series.......44
Figure 44: Summarized Performance of the Models...............................................................45
Figure 45: Sorted Model Performance Summary for Rose Wine Time Series........................46
Figure 46: Sorted Model Performance Summary for Sparkling Wine Time Series................46
Figure 47: Stationarity - Rose..................................................................................................48
Figure 48: Stationarity Check - Sparkling...............................................................................49
Figure 49: Running Automated ARIMA Model on Rose Wine Dataset.................................52
Figure 50: Results of Automated ARIMA Model on Rose Wine Dataset...............................53
Figure 51: Running Automated ARIMA Model on Sparkling Wine Dataset..........................54
Figure 52: Results of Automated ARIMA Model on Sparkling Wine Dataset.......................55
Figure 53:SARIMA Model on Rose wine data.........................................................................59
Figure 54: SARIMA Model on Sparkling Data.......................................................................62
Table of Tables
1. Executive Summary
For the Time Series Forecasting project, we have been provided with the data of different
types of wine sales in the 20th century. Both of these datasets are from the same company but
for different wines. As an analyst in the ABC Estate Wines, I need to analyse and forecast
2. Introduction
The intent for this project is to perform forecasting analysis on the Rose and Sparkling
dataset. I will try to analyse this dataset by using Linear Regression, Naïve Model, Simple
and Moving Average models, Simple, Double and Triple Exponential Smoothing. These
datasets contains 187 entries each, and I will try to build the most optimum model(s) on the
complete data and predict 12 months into the future with appropriate confidence
intervals/bands.
3. Data Details
Each datasets contain two columns, where the first column shows the month and year of the
4. Read the data as an appropriate Time Series data and plot the data
I have imported both the data series in two different ways. As we can observe, each entry
has an YearMonth value with it, which is not really a datapoint, but an index for the sales
entry. So in reality the datasets have a single column that contains the quantity of wines
sold in that particular month. Here, while reading the datasets into df_rose1 and
df_spark1 I have given the argument in a way so that it parses the first column which is
date column, and indicates to the system that this is a one column series through squeeze.
It can be observed that both the datasets have data starting from January 1980 going till
Now that I have uploaded the df_rose2 and df_spark2 datasets with no arguments (and
hence uploaded the datasets without parsing the dates here), I will need to provide a time
stamp value by ourselves. In addition to that I have removed the YearMonth variable and
As we can observe from the above plots, the sales for Rose Wine are showing a declining
trend and the sales for Sparkling wines are showing an upward trend. There is a certain
seasonality element that is visible in the graphs. We will explore the trend and
seasonality further during decomposition, where we will be able to view a much detailed
5.1. EDA
As we can see, the Rose dataset contains 2 Null values and there are no Null values for
Sparkling dataset; I addressed the Rose dataset Null values using linear interpolation so
as to obtain the imputed values in place of the values that are missing.
Post the imputation, I confirmed that there are no more Null values in the Rose dataset.
There are no duplicate entries in the datasets as each value correspond to a different time
index, so basically these are all sales figures for different months.
9
Data Description
skewed. There is High Standard Deviation for both ethe time series since the Min and
Max have significant difference between them. Moreover, there is difference between the
mean and the median for the same reason of skewness. As mentioned earlier, there are in
Following are the yearly boxplots for the two wine sales time-series:
10
The highest sales for Rose wine can be observed in 1981 and the lowest sales in 1994
(because the 1995 sales seem to be doing well, considering the data is only till July
month and reaching to the 1994 level already in 7 months itself). The highest variation in
monthly sales for Rose wine seems to be in the year 1981 and on the year 1994 there
As we can observe, the Sparkling Wine sales have a variation each year, the years 1985
and 1986 seem to be the years with the least variation, so the 2 years show certain
consistency in terms of sales. The highest sales for Sparkling Wine seems to happen in
the year 1994 and the lowest in the year 1982. Based on the 1995 data of 7 months (till
July), it is difficult to comment on the sales performance of that year. The Sparkling
wine sales appear to be going down from the year 1980 and have started increasing from
11
the year 1983. The variation in Sparkling Wine sales seem to be increasing for the period
1983-1986, while the highest variation in Sparkling wine sales is in the year 1994. There
is clear skewness that can be observed for Sparkling wine sales for all the years, except
maybe in 1981. There are outliers in the yearly sales data, however as it is a Time Series,
Following are the monthly boxplots for the two wine sales time-series:
seasonality element visible in both the Rose as well as Sparkling Wine time series
datasets. The Sparkling wine seem to have a higher seasonality element as compared to
12
Rose Wine. As can be clearly seen that the sales have an increasing sales trend in the last
quarter of the year, with Sparkling wine observing a steeper rise in sales during last
quarter. The sales for Rose wine seems to pick up from January month and is more or
less consistent till June, observes some stagnancy till September month and then starts to
pick up again from October (i.e. last quarter); while for Sparkling wine, the sales is
relatively low in first two quarters, slowly picks up pace during the third quarter and goes
on a rise till the end of the year. Monthly sales data for both the type of wines shows
The monthly sales for the type of wines across years can be seen in the following Pivot
As can be observed from the above two sets of tables and graphs, the months of
December seems to be the month that drives the highest sales figures for both Rose and
Sparkling Wines. The second highest sales for Sparkling being in November while Rose
wine shows a mixed trend, with highest sales in August or July for certain years.
We can observe a seasonality element in the graphs for both Rose and Sparkling wines.
The yearly sum of sales numbers can be observed in the following tables and graphs:
Figure 11: Sum of Yearly Observations for Rose and Sparkling Wine
As can be observed from the above summation tables and the plotted graphs, Rose wine
annual sales year on year observe a downward sales trend. While the sales figures for
15
Sparkling wine show a dip initially with sales picking up from the year 1982 right up to
the year 1988 and then observing another dip in the sales. The steep drop post 1994 for
both Rose and Sparkling wine is because of the relatively less (half year data - till July)
The yearly mean for the sales figures can be observed below:
section. An added observation would be that the mean sales for Rose wine are much
The quarterly sum of sales numbers can be observed in the following tables and graphs:
datasets, we can observe that the Quarterly sales show a downward trend for Rose wine
and an upward trend for Sparkling wine. Also there is a slight element of seasonality in
5.2. Decomposition
I have provided the decomposed elements for both the Time Series below:
17
additive and multiplicative decomposition for both time series so that I can determine if
As we can observe from the above, we can say that the wine time series are clearly
We can also observe again that the Rose wine sales depict a downward sales trend and
the Sparkling wine sales show an upward sales trend. The plots above clearly indicate
that the Wine sales are unstable and not uniform, and they have an apparent seasonality
trend. Moreover, the seasonal variation seems to be more in the case of Sparkling wine
as compared to the Rose wine; while the sales variation seems to be more in case of Rose
6. Split the data into training and test. The test data should start in 1991.
I have split the time series datasets into Train and Test datasets below. It is given the
question that the Test Data should start in 1991, so I have used 71% of the datasets for
the Training dataset (instead of the usual 70%) and the rest of the dataset for Test
datasets.
20
21
Figure 16: Training and Test Datasets for Rose and Sparkling Wine Time Series
I have also confirmed that the Train dataset indeed ends in 1990, and the Test dataset
indeed starts in 1991 by using the Head and Tail functions on the Training and Test
datasets. As we can observe, the size of the Train data frame is 132 observations and that
I have also plotted the Train and test data frames for both time series datasets below:
We can observe the training and test data in the above plots, the Orange part of the plots
depicts the Train datasets (January ’80 – December ‘90), and the Blue part of the plots
evaluate the model using RMSE on the test data. Other models such as
also be built on the training data and check the performance on the test
In this section I will try to run the various available models on both the Rose and
Sparkling wine time series. Let’s kick off the analysis with Linear Regression model.
The extracts of Training and Test data for the Linear Regression can be seen below:
23
Following are the results from a Linear Regression model run on both the Rose and
Figure 19: Linear Regrsn Outcome on the Rose and Sparkling Wine Time Series respectively
The Regression plots above depict the regression on training set as the Red line and that
on the test set as the blue line. As we can observe from the above plots and metrics, Rose
wine sales show a downward trend, and the Sparkling wine sales show an upward trend.
The summarized performance of the models run on the two wine datasets can be seen
below:
The extracts of Training and Test data for the Naïve Model can be seen below:
Wine datasets:
26
Figure 22: Naive Model Outcome on the Rose and Sparkling Wine Time Series respectively
For Rose Wine,
As can be seen from the Naïve model performance for Rose and Sparkling wine datasets
above, the Naïve model is not suitable for any of the wine datasets since the forecasts
The extracts of Training and Test data for the Simple Average Model can be seen below:
28
Figure 24: Training and Test data for Simple Average Model
Following are the results from running a Simple Average Model on both the Rose and
Figure 25: Simple Average Model Outcome on the Rose and Sparkling Wine Time Series
respectively
For Simple Average Model on the Rose Wine dataset,
The summarized performance of the models run on the two wine datasets can be seen
below:
wine datasets above, the Linear Regression model has the best performance among all
the three models run till now for the Rose wine dataset; while the Simple Average model
shows the best performance among all the three models run till now for the Sparkling
wine dataset.
The Moving Average data for the Rose and Sparkling wine datasets can be seen below:
31
32
Figure 27: Moving Average Model Data for Rose and Sparkling wine respectively
Following are the results from running a Moving Average Model on both the Rose and
Figure 28: Moving Average Model Outcome on the Rose wine Time Series
34
Figure 29: Moving Average Model Outcome on the Sparkling Wine Time Series
Moving Average Model on the Rose Wine dataset:
For 2 point Moving Average Model forecast on the Training Data, RMSE = 11.529 |
MAPE = 13.54
For 4 point Moving Average Model forecast on the Training Data, RMSE = 14.451 |
MAPE = 19.49
For 6 point Moving Average Model forecast on the Training Data, RMSE = 14.566 |
MAPE = 20.82
35
For 9 point Moving Average Model forecast on the Training Data, RMSE = 14.728 |
MAPE = 21.01
For 2 point Moving Average Model forecast on the Training Data, RMSE = 813.401 |
MAPE = 19.70
For 4 point Moving Average Model forecast on the Training Data, RMSE = 1156.590 |
MAPE = 35.96
For 6 point Moving Average Model forecast on the Training Data, RMSE = 1283.927 |
MAPE = 43.86
For 9 point Moving Average Model forecast on the Training Data, RMSE = 1346.278 |
MAPE = 46.86
The summarized performance of the models run on the wine datasets can be seen below:
36
As we can observe from the above plots, all of the trailing average plots show prediction
values below the actual train and test data sets, and the 9 point trailing average plot
shows the lowest prediction of all the plots. The closest prediction to actual data is shown
by the 2 point trailing moving average model. This observation is corroborated by the
As can be seen from the summarized performance of all the models, the 2 point moving
average has shown the best performance of all the models run on the Rose and Sparkling
wine datasets.
The SES Parameters for the Rose and Sparkling wine datasets can be seen below:
37
Figure 31: SES Parameters for the Rose and Sparkling wine datasets respectively
The SES train and test data for the Rose and Sparkling wine datasets can be seen below:
38
Figure 32: SES Train and Test data for Rose and Sparkling wine respectively
Following are the results from running a SES Model on both the Rose and Sparkling
Wine datasets:
39
Figure 33: Simple Exponential Smoothing Outcome on the Rose wine Time Series
Figure 34: Simple Exponential Smoothing Outcome on the Sparkling Wine Time Series
For Rose Wine dataset:
For Alpha =0.99 Simple Exponential Smoothening Model forecast on the Test data,
For Alpha =0.99 Simple Exponential Smoothening Model forecast on the Test data,
The summarized performance of the models run on the wine datasets can be seen below:
seasonality, I still applied it on the both the Rose and Sparkling wine data sets so as to
I used Alpha = 1 for the SES model and as expected, it did not perform well as compared
The Alpha, Beta values for the Rose and Sparkling wine datasets can be seen below:
41
42
Figure 36: Alpha Beta values for Rose and Sparkling wine respectively
Following are the results from running a DES Model on both the Rose and Sparkling
Wine datasets:
43
Figure 37: Double Exponential Smoothing Outcome on the Rose wine Time Series
Figure 38: Double Exponential Smoothing Outcome on the Sparkling Wine Time Series
For Rose Wine dataset:
For Alpha = 0.3, Beta = 0.3 Double Exponential Smoothening Model forecast on the
For Alpha = 0.3, Beta = 0.3 Simple Exponential Smoothening Model forecast on the Test
The summarized performance of the models run on the wine datasets can be seen below:
levels and trends, I used the grid search to begin and we reached conclusion that Alpha =
0.3 and Beta = 0.3 show the lowest RMSE and MAPE for both the Rose and Sparkling
wine data sets. The DES model is the model with the worst performance so far for both
The TES Parameters for the Rose and Sparkling wine datasets can be seen below:
45
Figure 40: TES Parameters for the Rose and Sparkling wine datasets respectively
The TES train and test data for the Rose and Sparkling wine datasets can be seen below:
46
Figure 41: TES Model Train and Test data for Rose and Sparkling wine respectively
Following are the results from running a SES Model on both the Rose and Sparkling
Wine datasets:
47
Figure 42: Triple Exponential Smoothing Outcome on the Rose wine Time Series
Figure 43: Triple Exponential Smoothing Outcome on the Sparkling Wine Time Series
For Rose Wine dataset:
The summarized performance of the models run on the wine datasets can be seen below:
Now that we have run all the models planned, let’s view the summary of the performance
Figure 45: Sorted Model Performance Summary for Rose Wine Time Series
Figure 46: Sorted Model Performance Summary for Sparkling Wine Time Series
As we can observe that for the Rose wine dataset, the 2 point trailing moving average
gives the best RMSE and MAPE among all the models.
50
For the Sparkling wine dataset, the TES model offers the best RMSE and MAPE among
8. heck for the stationarity of the data on which the model is being built on
using appropriate statistical tests and also mention the hypothesis for
= 0.05
I have performed the Stationarity Test on both the Rose and Sparkling wine data frames.
I have used an augmented Dickey-Fuller test on the Rose and Sparkling wine data sets to
check the stationarity. The Hypothesis is that the wine data is stationary, Alpha = 0.05
51
seems to be greater than alpha, hence we will have to stationaries the data. That is, the
data properties do not depend on the time when the data series is observed. This is
basically a hint of a seasonality/trend element in the dataset. After taking the difference
53
of 1 in between continuous observations to stationaries the data, we can observe that the
(AIC) on the training data and evaluate this model on the test data using
RMSE.
As we can see from the above, the lowest AIC recorded for Rose wine data is for p,d,q
values of 0,1,2 respectively and the lowest AIC is 1273.194 . The p value of coefficients
MA1 and MA2 are 0 and 0.013 which means that these are pretty significant. The RMSE
The lowest AIC for Sparkling data is 2210.6 for p,d,q, values of 2,1,2 respectively. The p
values of AR1, AR2, MA1, MA2 is Zero, which makes them pretty significant. The
1374.696495
As can be observed, for Rose dataset, the model with p,d,q, as 2,1,3 respectively has the
lowest AIC, which is 951.74. The p value of ar.S.L12 and ma.S.L12 is less than 0.05
which makes them pretty significant. The RMSE and MAPE values are
RMSE: 31.109618689658337
MAPE: 63.63047031555068
For the Sparkling Dataset, as can be observed, the model with p,d,q, as 2,1,3 respectively
has the lowest AIC, which is 1629.07. The p value of ar.S.L12 and ma.S.L12 is less than
0.05 which makes them pretty significant. The RMSE and MAPE values are
RMSE: 809.8955158780718
MAPE: 35.7387905706479