You are on page 1of 11

6/5/2018 Exponential Smoothing for Time Series Forecasting

MENU

Exponential Smoothing for Time Series


Forecasting
Posted by Preetam Jinka on Jun 22, 2017 4:45:00 PM

Time series anomaly detection is a complicated problem with plenty of practical


methods. It’s easy to nd yourself getting lost in all of the topics it encompasses.
Learning them is certainly an issue, but implementing them is often more complicated.
A key element of anomaly detection is forecasting - taking what you know about a time
series, either based on a model or its history, and making decisions about values that
arrive later.

You know how to do this already. Imagine someone asked you to forecast the prices for
a certain stock, or the local temperature over the next few days. You could draw out
your prediction, and chances are it’s a pretty good one. Your brain works amazingly
well for problems like this, and our challenge is to try to get computers to do the same.

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 1/11
6/5/2018 Exponential Smoothing for Time Series Forecasting

MENU

Image Source

If you take an introductory course on time series, you’ll learn how to forecast by tting a
model to some sample data, and then using the model to predict future values. In
practice, especially when monitoring systems, you’ll nd that this approach doesn’t
work well, if at all! Real systems rarely t mathematical models. There is an alternative.
You can do something a lot simpler with exponential smoothing.

First, let’s take a quick look at what kinds of time series we could be working with.
Suppose you measured the cpu.idle metric on a system and have observations that are
plotted below.

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 2/11
6/5/2018 Exponential Smoothing for Time Series Forecasting

MENU

In this case, the time series isn’t particularly interesting. The values vary a reasonable
amount, but overall it’s fairly stable and most values hover around 130 or so. From a
time series analysis perspective, this is considered to be fairly stationary. If you tried to
predict the next value, your best guess would probably be around 130. It’s impossible
to be exactly right with a prediction like this, but picking a value like 130 would appear
to be the least incorrect.

Smoothing
Exponential smoothing refers to the use of an exponentially weighted moving average
(EWMA) to “smooth” a time series. If you have some time series x t , you can de ne a
new time series s t that is a smoothed version of x t .

s t = αx t + (1 − α)s t−1

Here’s a plot of a stationary time series, like the previous example, along with a couple
of smoothed versions. Notice how the smoothing amount changes with α , the
smoothing weight. The smaller the weight, the less in uence each point has on the
smoothed time series. Read our other blog post on how exponentially weighted moving
averages work for more details.

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 3/11
6/5/2018 Exponential Smoothing for Time Series Forecasting

MENU

Suppose you had your time series x t along with a smoothed version s t . You’d like to
predict, or forecast, the next value for x t , which is x t+1 . This is simpler than you may
think! You can just use the last value you calculated for the EWMA, s t . It works out this
way because our smoothed time series is the EWMA of our original series, and because
of the way averages (and expectations) work, s t turns out to be a really good
prediction. Predicting the next value is called the one-step-ahead forecast.

This method doesn’t always work well. Remember, you made an important assumption
for this time series: it’s stationary. What happens when it isn’t?

Stationarity, Trend, and Seasonality


There are many ways to characterize a time series, but we’ll focus on three simple ones
that are closely related: stationarity, trend, and seasonality. Stationarity refers to how
stable the values of a time series are. For simplicity, let’s just say that we consider a
time series to be stationary if it has a constant mean. A stationary time series will not
have any kind of increasing or decreasing pattern, and its points will generally hover
around the same value, the mean. It’s because of this characteristic that a simple
EWMA, which estimates the mean, is so helpful for forecasts.

Trend refers to a long-term movement of a time series in a particular direction. With


linear trend, time series points will approximately follow a line. It’s also possible to have
higher order trends, such as quadratic trend where points follow a parabola.

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 4/11
6/5/2018 Exponential Smoothing for Time Series Forecasting

MENU

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 5/11
6/5/2018 Exponential Smoothing for Time Series Forecasting

Seasonality refers to a periodic pattern. A great example of a seasonal time series


MENU is the
temperature in a particular location. A time series can have multiple seasons with
different periods

The Keeling Curve, which plots the measured concentration of CO2 in the atmosphere,
has a positive trend and seasonality.

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 6/11
6/5/2018 Exponential Smoothing for Time Series Forecasting

MENU

You may notice something interesting going on with the smoothed series with the
lower weight. It tends to lag behind our original data because more recent values have
lower in uence. This is especially noticeable with the seasonal time series. This is
important! Because you’re using the smoothed values to forecast, any signi cant
deviation in the smoothed values will throw off your prediction. If you notice that your
time series is not stationary, you’ll have to nd something other than a simple EWMA
to do your forecasting.

Double and triple exponential smoothing


In the late 1950s, Charles Holt recognized the issue with the simple EWMA model with
time series with trend. He modi ed the simple exponential smoothing model to account
for a linear trend. This is known as Holt’s exponential smoothing. This model is a little
more complicated. It consists of two EWMAs: one for the smoothed values of x t , and
another for its slope. The terms level and trend are also used.

s t = αx t + (1 − α)(s t−1 + bt−1 )


bt = β(s t − s t−1 ) + (1 − β)bt−1

Notice how the smoothed values are much better at following the original time series
with double exponential smoothing. This means you’ll get much better forecasts.

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 7/11
6/5/2018 Exponential Smoothing for Time Series Forecasting

MENU

To forecast with this model, you have to make a slight adjustment. Because there is
another term for the slope, you’ll have to consider that in the forecast. Suppose you’re
trying to forecast the value in m time steps in the future. The formula for the m -step-
ahead forecast, F t+m , is

F t+m = s t + mbt .

Notice how it’s essentially the formula for a line. What if your time series doesn’t have a
linear trend, but rather some sort of seasonality? For that, you’ll need yet another
EWMA.

Holt’s student, Peter Winters, extended his teacher’s model by introducing an


additional term to factor in seasonality. This model, with level, trend, and seasonal
components, is known as Holt-Winters. It is also referred to as triple exponential
smoothing. Notice how there’s another variable L , which depends on the period of the
seasonality and has to be known in advance. 

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 8/11
6/5/2018 Exponential Smoothing for Time Series Forecasting

MENU

The m -step-ahead forecast formula for this is

F t+m = (s t + mbt )gt−L+m .


 

Summary
Real-time anomaly detection is really a forecasting problem since you can’t know what
to expect in the present unless you use the past to forecast. Forecasting time series
data can get really sophisticated and complicated, but a lot of simple and ef cient
techniques like an EWMA can give most of the bene t with a small fraction of the cost,
effort, and complexity. More complex techniques can be good for very speci c cases,
but come at the cost of losing generality and requiring a lot more tweaking and
parameter selection, which can be surprisingly delicate to do well.

Updated 6/22/2017

Tweet Share Like 2 Share

Topics: Math and Statistics

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 9/11
6/5/2018 Exponential Smoothing for Time Series Forecasting

MENU
Recent Posts
Monitor Critical Databases Con dently with the Sensitive Data Vault

New Stats Exposed in Go's database/SQL Package

How SendGrid Ships Better Code Faster with VividCortex

The High Cost and Low Bene t of Unused Index Advice

How to Select the Right Queries to Optimize

What's New: Product Updates  

Come See VividCortex at PostgresConf US 2018

Holt-Winters Forecasting Simpli ed

Strata Conference 2018: What You Missed

Numeric Optimization in Golang with Nelder-Mead and Gonum

Email address

Subscribe to email updates

Posts by Topic
Monitoring (147)
Product Features (89)
MySQL (53)
Culture (47)
News, Press and Media (45)

see all

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 10/11
6/5/2018 Exponential Smoothing for Time Series Forecasting

MENU
300 Preston Ave, Charlottesville, Virginia 22902 United States
VividCortex - © 2018  Terms of service | Privacy policy
 
g k h j

https://www.vividcortex.com/blog/exponential-smoothing-for-time-series-forecasting 11/11

You might also like