A Primer to Time Series Forecasting

Dhirendraddsingh
Nerd For Tech
Published in
6 min readMay 11, 2021

--

Photo by Aron Visuals on Unsplash

This article serves as a follow up to my article From a Business Analyst to a Data Scientist wherein I discussed topics and resources one can study to become an entry level Data Scientist without having any background in the field. In this article, I will take one of the topics Time Series Forecasting and go a bit deep into it’s components. Why Time Series Forecasting ? Most of the companies I applied for asked TSF in the interview, my current work involves using a lot of TSF and of course it’s pretty interesting. My aim with this article is not to make you a Time Series Forecasting expert(no article can do that) but to give you a broad overview of the full field so you get a structure or learning. Let’s jump in

I have seen the future and it is very much like the present, only longer.

Kehlog Albran, The Profit

What is Time Series Forecasting and why it’s important?

First of all what is a Time Series? It is simply a set of data points ordered in time. Using these points, we try to predict values of future points assuming future trends will be same as historical trends, that in a nutshell is TSF. It helps us in getting some idea and some certainty of the future events so we are better prepared, a great example is mathematicians in India trying to forecast when will Covid’19 cases peak so that the healthcare system is better equipped with all the supplies etc.

Basic Components of a Time Series

  1. Level- It is the average value of the series
  2. Trend- The increasing or decreasing of values in the series
  3. Seasonality- Trends that repeat over a period of time. Ex:- Every Christmas specific item sales starts picking up
  4. Noise or Residual- The unexplained component of the time series which the model can’t define

These all parts combine and make up a Time Series and form the basic structure of whichever methods you use to forecast the series . Let’s consider a time series which represents number of flights taken each month from year 1949 to 1961, these are how the components will look like

Image was taken from here

Statistical methods to Time Series Forecasting

  1. Naive Method- The simplest of all the methods in TSF, the logic is the next point in time series is same as the last observed point

2. Simple Average- We all know what a simple average is, the premise of this method is the next value is a simple average of all previous values

3. Moving Average- This is an updated version of the previous method. Instead of taking all previous values you decide a sliding window(let’s say n), the next value is average of all previous n values, of course this assumes only recent values are important unlike the previous method

Here we have a taken n= 6 and dragged on

4. Weighted Moving Average- It’s an updated version of the previous method wherein you assign different weights to different values under the sliding window. The logic ? Well assume you have to forecast sales for next month and you have 365 values for the previous year(1 for each day),wouldn’t you like to attribute more weight to the sales in last month December compared to the starting month January

5. Single Exponential Smoothing- Like previously, this is an updated version of weighted moving average, except we are now taking all the values in the series. But how will we assign weights to all values, we will use α and 1−α. Here α or alpha is called a smoothing factor. So basically the next value is a weighted average of previous two values

What does α do? Think of it as a decay factor , the higher the value of α, the faster the method forgets previous values.

6. Double Exponential Smoothing- Till now , what we were doing was forecasting the level, now we are adding another component to the equation- Trend. So basically we are applying exponential smoothing to both level and trend.

7. Triple Exponential Smoothing a.k.a Holt-Winters Method- Now we are adding one more level and the final component, seasonality. The idea is to apply smoothing to all three components of the time series

General Time Series Forecasting models

  1. Autoregression or AR- The premise of the model like all previously discussed methods is the next value in a time series depends upon the previous values. We build a linear regression equation using previous values and then fit new values to make a prediction.
  2. Moving-Averages or MA- Don’t confuse it with the moving averages method discussed previously. So unlike the autoregression model which uses the past values, the MA model uses past errors to make a forecast
  3. ARIMA- Well as you would have guessed it, ARIMA is a mixture of the previous two models and stands for Auto Regressive Integrated Moving Average. The method uses both, the past values and the past errors of the time series to forecast future values. An ARIMA model is always denoted as ARIMA(p,d,q). Here p stands for the number of AR terms, q stands for the number of MA terms and d stands for differencing. What is differencing? It is transforming a time series into another one where each value is the difference of the previous two values. It is done to make the time series stationary. What is stationarity? A time series is called stationary when its statistical component like mean, variance etc. are constant over a period of time.
  4. SARIMA- It stands for Seasonal Autoregressive Integrated Moving Average, SARIMA is an extension of ARIMA which supports time series forecasting where seasonality is a component.
  5. SARIMAX- Here X stands for eXogenous factors. What are eXogenous factors ? All the previous models we discussed are used for univariate time series forecasting which means your time series has only one variable which is the time series itself. But what if we are trying to predict next month’s sales and we want to incorporate extra variables like geography, marketing budget etc., these are eXogenous variables which are independent and to incorporate them we use SARIMAX
  6. VARMAX- What if the variables we are using are dependent on the time series, let’s say you are trying to predict supply using demand but we also know both are interdependent on each other so we will use VARMAX

More Resources and Articles

Most of the links for time series you can find here in my previous article, additional links are mentioned below

  1. https://grisha.org/blog/2016/02/16/triple-exponential-smoothing-forecasting-part-ii/
  2. https://www.machinelearningplus.com/time-series/arima-model-time-series-forecasting-python/
  3. https://www.kaggle.com/raenish/cheatsheet-date-helpers

Summary

I purposely did not cover any models which use neural networks or deep learning to forecast like LSTM etc. because of two reasons :-

1- They are beyond the scope for this article

2- There is no point jumping to complex algorithms without having a solid base

All the topics mentioned here are more than enough to give you a solid understanding of Time Series Forecasting and if you explore each topic one by one, you can and will handle any forecasting problem. Let me know in the comments if you want me to emphasize on anything particular in the next article and also please feel free to reach out to me on LinkedIn if you have any more questions, I will do my best to reply.

--

--

Dhirendraddsingh
Nerd For Tech

A Data Scientist , football lover and a student of Pyschology