Exponential Smoothing vs Moving Average for Time Series Forecasting

Time series analysis and forecasting are important data science concepts that have a variety of applications. There are different techniques used to make forecasts with time series data. Exponential smoothing and moving average are the two basic and important techniques used for this purpose. In this article, we will look at the comparison between exponential smoothing and moving average for time series forecasting. The main points to be discussed in the article are listed below.

Contents

  1. About exponential smoothing?
  2. Implementation of exponential smoothing methods
  3. About the moving average?
  4. Implementation of the moving average
  5. Exponential Smoothing vs Moving Average

Let’s start by understanding exponential smoothing

About Exponential Smoothing

In time series, exponential smoothing can be considered as a method to smooth time series data. We can also think of it as a rule of thumb technique which is an approximate method of doing something. This method uses an exponential window function that we use to assign decreasing weights exponentially over time. This time series smoothing method can also be used to make many determinations based on a prior assumption. But usually we apply it to smooth time series data.

Are you looking for a comprehensive repository of Python libraries used in data science, check here.

Applying the widow can also be thought of as applying a filter to the time series data so that we can remove the noise from the time series data. Let’s say a univariate time series data is xt at time t = 0 and the result of smoothing using exponential smoothing is st . we can also say that the St is the best estimate of the next value in the time series. Mathematically, we can give exponential smoothing as the following formula.

s0 = x0
st = xt + (1-)st-1 ,  t>0      

Or,

(0<<1) = smoothing factor.

Simple exponential smoothing can also be thought of as recursive filtering and mathematically can be given as follows

The exponential smoothing at time t (st) can also be thought of as the simple weighted average value of the time series at time t (xt) and the last smoothed value st-1. We can even apply these statistics with two sequential values. One thing that stands out here is that as the value of increases, the level of smoothing decreases and there is no perfect method that can be applied to choose the value of .

This method may also be called exponentially weighted moving average (EWMA) and autoregressive integrated moving average (ARIMA) without a constant term in some other cases. There are three types of exponential smoothing that we can find:

  • Simple/single exponential smoothing: This smoothing can be used to make forecasts based on a time series without trend or seasonality.
  • Double exponential smoothing: This type of exponential smoothing comes with support for trend components of time series.
  • Triple exponential smoothing: This type of exponential smoothing comes with support for trend and seasonality components of time series.

Let’s see how this method can be implemented.

Forecast using exponential smoothing

We can use the statsmodel library for implementing exponential smoothing methods. In this library under tsa.holt winters package we can get all implemented methods for exponential smoothing. Let’s look at the implementation of single exponential smoothing.

Data import:

import pandas as pd
ts = pd.read_csv('/content/drive/MyDrive/Copy of shampoo-sales .csv')

Import and adjustment module:

from statsmodels.tsa.holtwinters import SimpleExpSmoothing
model = SimpleExpSmoothing(ts['Sales'])
fit_model = model.fit(smoothing_level=0.2, optimized=False)

Plot of smoothed data:

import matplotlib.pyplot as plt
plt.figure(figsize=(12, 8))
plt.plot(ts['Sales'], color="black")
plt.plot(fit_model.fittedvalues, color="blue")

Production:

Here we can see how the function defined in the library works using the single exponential smoothing method.

About the Moving Average

As the name suggests, it is a method in which the average can be said to evolve. In time series analysis, it is a method of forecasting jobs by capturing the average changes in the time series. In various places, we may also find that this method is referred to as moving average, moving average, moving average (MA) or moving average. It is based on performing a series of averages using the full data subsets. In general, it can also be considered as a computational method for analyzing sequential data.

It also works by applying a filter over a time series and the filter can be thought of as a finite impulse response filter. This filter works by taking the average of a fixed subset of a series of numbers. Let’s say there is a time series which can be split by months, which means we have a set of values ​​and the average of the values ​​of the first month of the time series can be considered as the first moving average of the process of smoothing. Not as time will move through the series, the set of numbers will change and therefore the average value will continue to change.

The image below is a representation of applying a moving average to smooth the time series.

Source of images

Here we can see that the red line is the result of smoothing and we can say that we are applying it to remove the short term fluctuations from the time series so that the long term trend of the time series can be highlighted . There are three types of moving average

  • Simple moving average: This is the simplest form of moving average where the sum of recent values ​​in the time series is divided by time.
  • Exponential Moving Average: This type of moving average focuses more on recent values ​​by providing a greater weight of recent values ​​to the moving average.
  • Cumulative Moving Average: This method focuses on all values ​​in the time series by applying the average of all values ​​and the average should be unweighted.

Let’s see how we can implement a simple moving average using python.

Forecast using moving average

We can perform time series forecasting using moving average method only with pandas library. In the above, we imported shampoo sales data. Let’s plot the data.

plt.plot(ts['Sales'])

Production:

Let’s plot the data after applying the moving average.

ts['Sales'].plot(figsize=(10,6))
ts['Sales'].rolling(window =5).mean().plot()

Production:

In the above, we have seen how we can implement and define both methods. Let’s take a look at the difference between these two smoothing methods.

Exponential Smoothing vs Moving Average

One of the important differences between these two methods can be assumed by using their name. On one side exponential smoothing applies exponential windowing while on the other side we can see average windowing is applied to the data to reduce data noise.

Under exponential smoothing we have methods that provide support with respect to time series components such as trend and seasonality while talking about moving average we can say that methods under this smoothing process are more focused on values ​​with their delays. As the exponential moving average focuses on recent values.

Another thing that makes a big difference between these methods is that the exponential smoothing can be done using even two data points and to start the moving average we need to set the window size which needs to be greater than three to perform the real smoothing.

Here we can say that exponential removes more noise from the data based on the smoothing factor and moving average removes noise using the average value of the data points.

Last words

In the article, we discussed exponential smoothing and moving average. Both of these methods are smoothing methods for time series data. The way the algorithms work makes them both different from each other, as we discussed in our last sentient.

References

Link to codes above

Comments are closed.