Exponential Smoothing for Time Series Forecasting

Exponential smoothing is a popular time series forecasting method known for its simplicity and accuracy in predicting future trends based on historical data. It assumes that future patterns will be similar to recent past data and focuses on learning the average demand level over time. In this article, we will make a detailed analysis of the Exponential Smoothing for Time Series Forecasting.

Table of Content

  • Exponential Smoothing Forecasting
  • Types of Exponential Smoothing
    • 1. Simple or Single Exponential smoothing
    • 2. Double Exponential Smoothing
    • 3. Holt-Winters’ exponential smoothing
  • Exponential smoothing in Python
    • The dataset
    • Setting up the environment
    • Loading the data
    • Single Exponential smoothing
    • Double Exponential Smoothing
    • Holt-Winter’s Seasonal Smoothing
  • When to use Exponential Smoothing
  • Benefits of Exponential Smoothing
  • Limitations of Exponential Smoothening
  • Conclusion

Exponential Smoothing Forecasting

Time series methods follow the assumption that a forecast is a linear sum of all past observations or delays. Exponential smoothing gives more weight to the most recent observations and reduces exponentially as the distance from the observations rises, with the premise that the future will be similar to the recent past. The word “exponential smoothing” refers to the fact that each demand observation is assigned an exponentially diminishing weight.

  • This technique captures the general pattern and can be expanded to include trends and seasonal variations, allowing for precise time series forecasts using past data.
  • This method gives a bit of erroneous long-term forecasts.
  • It works well with the technique of smoothing when the parameters of the time series change gradually over time.

Types of Exponential Smoothing

Exponential smoothing forecasting can be divided into three main types:

1. Simple or Single Exponential smoothing

Simple smoothing is a method of forecasting time series using univariate data without a trend or seasonality. One must have a single parameter, which is also referred to as alpha ([Tex]\alpha[/Tex]) or smoothing factor so as to check how much the impact of past observations should be minimized.the weight to be given to the current data as well as the mean estimate of the past depends on the smoothing parameter ([Tex]\alpha[/Tex]). A smaller value of a implies more weight on past prediction and vice-versa. The range of this parameter is typically 0 to 1.

The formula for simple smoothing is as follows:

[Tex]s_t = αx_t+(1 – α)s_{t-1}= s_{t-1}+ α(x_t – s_{t-1})[/Tex]

where,

  • [Tex]s_t[/Tex] = smoothed statistic (simple weighted average of current observation xt)
  • [Tex]s_{t-1}[/Tex] = previous smoothed statistic
  • [Tex]α[/Tex] = smoothing factor of data; [Tex]0 < α < 1[/Tex]
  • [Tex]t[/Tex] = time period

2. Double Exponential Smoothing

Double exponential smoothing, also known as the Holt’s trend model, or second-order smoothing, or Holt’s Linear Smoothing is a smoothing method used to predict the trend of a time series when the data does not have a linear trend but does not have a seasonal pattern. The fundamental idea behind double exponential smoothing is to use a term that can take into account the possibility that the series will show a trend.

Double exponential smoothing requires more than just an alpha parameter. It also requires a beta (b) factor to control the decay of the effect of change in the trend. The smoothing method supports both additive and multiplicative trends.

The formulas for Double exponential smoothing are as follows:

[Tex]s_t = αx_t + (1 – α)(s_{t-1} + b_{t-1})[/Tex]

[Tex]β_t = β(s_t – s_{t-1}) + (1 – β)b_{t-1}[/Tex]

where,

  • [Tex]b_t[/Tex] = best estimate of the trend at time [Tex]t[/Tex]
  • [Tex]β[/Tex] = trend smoothing factor; [Tex]0 < β <1[/Tex]

3. Holt-Winters’ exponential smoothing

Triple exponential smoothing (also known as Holt-Winters smoothing) is a smoothing method used to predict time series data with both a trend and seasonal component.

This is the most advanced variation of smoothing. It is used for forecasting time series when the data contains linear trends and seasonality.

The technique uses exponential smoothing applied three times:

  • Level smoothing
  • Trend smoothing
  • Seasonal smoothing

New smoothing parameter, gamma (γ), is used to control the effect of seasonal component.

Exponential smoothing can be divided into two categories, depending on the seasonality. The Holt-Winter’s Additive Method (HWIM) is used for addictive seasonality. The Holts-Winters Multiplicative method (MWM) is used for multiplicative seasonality.

The smoothing method uses three parameters:

  • [Tex](α)[/Tex] the level (intercept),
  • [Tex](β)[/Tex] the trend, and
  • [Tex](γ ) [/Tex] the seasonal component.

The formulas for the triple exponential smoothing are as follows:

[Tex]s_{0} = x_{0}[/Tex]

[Tex]s_t = \alpha (x_t/c_{t – L}) +(1- \alpha)(s_{t-1} +b_{t-1})[/Tex]

[Tex]b_t = \beta(s_t -s_{t – 1} )+(1- \beta)b_{t-1} [/Tex]

[Tex]c_t = \gamma x_t/s_t + (1 – \gamma) c_{t-L}[/Tex]

where:

  • [Tex]s_t [/Tex] = smoothed statistic; it’s the simple weighted average of current observation Yt
  • [Tex]s_{t-1}[/Tex] = previous smoothed statistic
  • [Tex]α[/Tex] = smoothing factor of data [Tex](0 < α < 1)[/Tex]
  • [Tex]t[/Tex] = time period
  • [Tex]b_t[/Tex] = best estimate of a trend at time t
  • [Tex]β[/Tex] = trend smoothing factor [Tex](0 < β <1)[/Tex]
  • [Tex]c_t[/Tex] = seasonal component at time [Tex]t[/Tex]
  • [Tex]γ[/Tex] = seasonal smoothing parameter [Tex](0 < γ < 1)[/Tex]

The Holt-Winters method is the most precise of the three, but it is also the most complicated. It involves more data and more calculations than the others.

Exponential smoothing in Python

Python has several exponential smoothing libraries, such as Pandas, Statsmodels, Prophet, etc. These libraries offer different functions and methods to implement different types of smoothing methods.

The dataset

For the sake of completeness, we are going to use a dataset called AirPassengers. AirPassengers is a time-series dataset that includes the monthly passenger numbers of airlines in the years 1949 to 1960.

Dataset link: AirPassengers.csv

Setting up the environment

First, let’s set up our environment. We’ll be using Python 3, so make sure you’ve got it installed.

Next, install these libraries using pip:

pip install pandas matplotlib

Once you’ve installed the necessary libraries, you can import them into your Python script:

Python

import pandas as pd import matplotlib.pyplot as plt


Loading the data

After setting up the environment, we can load the AirPassengers dataset into a pandas DataFrame using the read_csv function, We can then inspect the first few rows of the DataFrame using the head function:

Python

data = pd.read_csv('AirPassengers.csv', parse_dates=['Month'], index_col='Month') print(data.head())

Output:

#Passengers
Month
1949-01-01 112
1949-02-01 118
1949-03-01 132
1949-04-01 129
1949-05-01 121

Visualizing the data

Before we apply simple exponential smoothing to the data, let’s visualize it to get a better understanding of its properties. We can use the plot function of pandas to create a line plot of the data:

Python

plt.plot(data) plt.xlabel('Year') plt.ylabel('Number of Passengers') plt.show()

Output:

Visualizing the data

We can see that the number of passengers appears to be increasing over time, with some seasonality as well.

Single Exponential smoothing

Now that we’ve loaded and visualized the data, we can perform simple exponential smoothing using the SimpleExpSmoothing function from the statsmodels library.

Then, we’ll create an instance of the SimpleExpSmoothing class, passing in the data as an argument, and then fit the model to the data using the fit method, This will calculate the smoothing parameters and fit the model to the data.

Python

from statsmodels.tsa.api import SimpleExpSmoothing model = SimpleExpSmoothing(data) model_single_fit = model.fit()

Making predictions

Finally, we can use the forecast method of the model to make predictions for future values of the time series, where the argument represents the number of periods to forecast. This will produce a forecast for the next six months:

Python

forecast_single = model_single_fit.forecast(6) print(forecast_single)

Output:

1961-01-01 431.791781
1961-02-01 431.791781
1961-03-01 431.791781
1961-04-01 431.791781
1961-05-01 431.791781
1961-06-01 431.791781
Freq: MS, dtype: float64

Visualize Single Exponential Smoothing

Let’s set the forecast to 40, and check the trend for next 40 months.

Python

forecast_single = model_single_fit.forecast(40)

Now, let’s Visualize

Python

plt.plot(data, label='Original Data') plt.plot(model_single_fit.fittedvalues, label='Fitted Values') plt.plot(forecast_single, label='Forecast') plt.xlabel('Year') plt.ylabel('Number of Passengers') plt.title('Single Exponential Smoothing') plt.legend() plt.show()

Output:

Visualisation of Simple Exponential Smoothing

Double Exponential Smoothing

Double exponential smoothing, also known as Holt’s method, extends single exponential smoothing to capture trends in the data. It involves forecasting both the level and trend components of the time series.

Now, let’s write the code to perform double exponential smoothing (Holt’s method) using the Holt function from the statsmodels library:

  • Create an instance of Holt class
  • Fit the model to the data
Python

from statsmodels.tsa.api import Holt model_double = Holt(data) model_double_fit = model_double.fit()

Making predictions

Python

forecast_double = model_double_fit.forecast(6) print(forecast_double)

Output:

1961-01-01 436.196220
1961-02-01 440.578651
1961-03-01 444.961083
1961-04-01 449.343515
1961-05-01 453.725946
1961-06-01 458.108378
Freq: MS, dtype: float64

Visualize Double Exponential Smoothing

Let’s set the forecast to 40, and check the trend for next 40 months, same as earlier.

Python

forecast_double = model_double_fit.forecast(40)

Now, let’s visualize

Python

plt.plot(data, label='Original Data') plt.plot(model_double_fit.fittedvalues, label='Fitted Values') plt.plot(forecast_double, label='Forecast') plt.xlabel('Year') plt.ylabel('Number of Passengers') plt.title('Double Exponential Smoothing') plt.legend() plt.show()

Output:

Visualize Double Exponential Smoothing

Holt-Winter’s Seasonal Smoothing

Holt-Winter’s Seasonal Smoothing, extends double exponential smoothing to capture seasonality in the data. It involves forecasting the level, trend, and seasonality components of the time series.

Now, let’s write the code to perform triple exponential smoothing (Holt-Winters method) using the ExponentialSmoothing function from the statsmodels library:

Python

from statsmodels.tsa.api import ExponentialSmoothing # Create an instance of ExponentialSmoothing class model_triple = ExponentialSmoothing( data, seasonal_periods=12, trend='add', seasonal='add') # Fit the model to the data model_triple_fit = model_triple.fit()

Making predictions

Python

forecast_triple = model_triple_fit.forecast(6) print(forecast_triple)

Output:

1961-01-01 451.577073
1961-02-01 427.257748
1961-03-01 464.699360
1961-04-01 500.103185
1961-05-01 508.660794
1961-06-01 567.713873
Freq: MS, dtype: float64

Visualize Triple Exponential Smoothing

Let’s set the forecast to 40, and check the trend for next 40 months, same as earlier.

Python

forecast_triple = model_triple_fit.forecast(40)

Now, let’s visualise

Python

plt.plot(data, label='Original Data') plt.plot(model_triple_fit.fittedvalues, label='Fitted Values') plt.plot(forecast_triple, label='Forecast') plt.xlabel('Year') plt.ylabel('Number of Passengers') plt.title('Triple Exponential Smoothing') plt.legend() plt.show()

Output:

Visualize Triple Exponential Smoothing

When to use Exponential Smoothing

The selection of an exponential smoothing method is dependent on the properties of the time series and the forecasting needs.

  1. Simple Exponential Smoothing (SES):
    SES best suits time series data with no trend and no seasonality. It is basic, which can be applied when there is no overall systematics in trends or anomalies and straightforward forecasting based on the last observation and the preceding forecast. Because SES is based on computing and is simple to set up, it’s ideal for forecasting in real time or where there’s a lack of data.
  2. Holt’s Linear Smoothing:
    Holt’s Linear Smoothing is used for time series data with a trend. A trend is a systematic change in a time series value over time. It’s an extension of Simple Exponential Smoothing that includes a trend component along with the level component. This allows for trend patterns to be captured in the data.
    Holt’s Linear Smoothing is used when the data has a consistent upward or down trend. A forecast that takes into account both current level and trend is required.
    It is also used when the data does not have seasonality but has a trend.
  3. Holt-Winter’s Seasonal Smoothing:
    Holt-Winter’s seasonal smoothing is used in cases of trend and seasonality time series data. It is an extension of the DES, adding a seasonal component to the level and trend components such that seasonal patterns in data could be captured.
    Holt-Winter’s Seasonal Smoothing method can be applied where the data exhibits both the trend and the repeating pattern over time, like monthly seasonality or quarterly seasonality. In this regard, Holt-Winter’s Seasonal Smoothing is able to produce forecasts that can keep up with the current level, trend, and seasonality, thus being very suitable for forecasting situations where the trend and seasonality coexist.

The choice of an exponential smoothing method may also depend on your specific needs in the forecasting: desired horizon of forecast, level of accuracy, availability of historic data, etc. You would then have to test a number of different methods and adjust smoothing parameters—like alpha and beta—since it is necessary to find the best approach for your particular time series data and forecasting goals.

It is always a good practice to test the accuracy of your forecast with performance metrics and validate the forecast using out-of-sample data before finalizing the decisions.

Benefits of Exponential Smoothing

Analysts can modify the rate at which older observations become less significant in the computations by varying the values of these parameters. As a result, analysts can adjust the weighting of recent observations in relation to previous observations to suit the needs of their field.

On the other hand, the moving average approach assigns 0 weight to observations outside of the moving average window and assigns equal weight to all historical observations when they occur within its frame. Because exponential smoothing models error, trend, and seasonality in time series data, statisticians refer to it as an ETS model, just like they do with the Box-Jenkins ARIMA methodology.

Limitations of Exponential Smoothening

However, there are some drawbacks to exponential smoothing.

For example, it may not work well for time series with complex patterns or anomalies, such as sudden level or trend changes, outliers or sudden seasonality.

In these cases, other sophisticated forecasting techniques may be more suitable.

Also, the selection of smoothing parameters, such as alpha, beta and γ, can affect the precision of the forecasts. Finding the best values for these parameters might require some trial and error or model selection techniques.

Conclusion

Exponential smoothing belongs to the most favorite and effective time series forecasting methods; with it, you can derive very accurate predictions while it is very efficient and adaptive at the same time.

  • Simple exponential smoothing works best when the time series has no trend and no seasonality.
  • Double or triple exponential smoothing works well for time series with trend and seasons.

This is, of course, limited by the limitations of every forecasting technique, including exponential smoothing, and should be used carefully by considering the characteristics of your time series data and your forecasting requirements.



Contact Us