Trend, seasonality and noise

Decompose a series into the parts a forecaster has to model, and read autocorrelation plots to see them.

Lesson 52 of 6610 minIntermediate

You will learn to

  • Identify trend, seasonality and residual in a time series
  • Choose additive or multiplicative decomposition
  • Read ACF and PACF plots

Before this lesson

Intuition

Think about the number of visitors to a beach. Over the years the town grows, so there are more visitors: that is the trend. Every summer is busier than every winter: that is seasonality, a pattern that repeats at a fixed period. And on any given day the weather, a holiday or pure luck adds or removes a few visitors: that is the residual, or noise.

A forecaster has to model the first two and accept the third. If you do not know which part you are looking at, you may fit a straight line through a seasonal pattern, or forecast a bump that was a one-time event. Decomposition makes the parts visible, one panel each, so you can decide what the model must capture.

A fourth idea sits next to these: autocorrelation. A value in a time series is usually related to the values just before it, and to the value one season ago. The autocorrelation plots measure that relation, and they are the quickest way to see whether a pattern repeats and how long it takes.

Picture it

The top panel is what you observe. Underneath, the same series is split into a slow trend, a repeating seasonal pattern and a small residual. Adding the three lower panels gives back the top one.

ObservedTrendSeasonalResidualTime (months)→
Decomposition of a monthly series (illustrative data): observed = trend + seasonal + residual.

The math

Let yty_t be the value at time tt, TtT_t the trend, StS_t the seasonal part and RtR_t the residual. The additive model is

yt=Tt+St+Rty_t = T_t + S_t + R_t

and the multiplicative model is

yt=Tt×St×Rty_t = T_t \times S_t \times R_t

In the additive model the seasonal part is a number added to the level (for example, plus 15 units in December). In the multiplicative model it is a factor (for example, times 1.2 in December), so the swing grows when the level grows. Taking the logarithm turns a multiplicative series into an additive one, because log⁡(T×S×R)=log⁡T+log⁡S+log⁡R\log(T \times S \times R) = \log T + \log S + \log R.

Classical decomposition estimates the trend with a moving average over one full season, then averages the detrended values for each position in the season to get the seasonal part. The residual is what remains.

The autocorrelation at lag kk is the correlation of the series with itself shifted by kk steps:

rk=∑t=1n−k(yt−yˉ)(yt+k−yˉ)∑t=1n(yt−yˉ)2r_k = \frac{\sum_{t=1}^{n-k}(y_t-\bar{y})(y_{t+k}-\bar{y})}{\sum_{t=1}^{n}(y_t-\bar{y})^2}

where yˉ\bar{y} is the mean of the series and nn the number of points. The partial autocorrelation (PACF) at lag kk is the correlation that remains after the effect of the lags in between is removed. It tells you whether lag kk adds information of its own, or only repeats what lags 1 to k−1k-1 already say.

On an ACF or PACF plot, bars outside the shaded confidence band are unlikely to be zero by chance.

Worked example

Additive. A shop sells 142 units in December. The trend estimate for that month is 130 units, December is usually 15 units above the trend, and so the residual is 142 - 130 - 15 = -3. Check: 130 + 15 - 3 = 142.

Multiplicative. A second shop has a trend of 200 units in December and a seasonal factor of 1.2 for December. The expected value is 200 x 1.2 = 240. If it sells 235.2, the residual factor is 235.2 / 240 = 0.98, so it sold 2% less than the pattern predicts. A year later the trend is 300: the same factor now means 360 units, a swing of 60 units instead of 40. That growing swing is why the multiplicative form is the right one here.

Autocorrelation by hand. Take six points: 2, 4, 5, 7, 8, 10.

  1. The mean is 36 / 6 = 6, so the deviations are -4, -2, -1, 1, 2, 4.
  2. The denominator is the sum of squared deviations: 16 + 4 + 1 + 1 + 4 + 16 = 42.
  3. For lag 1, multiply each deviation by the next one: 8, 2, -1, 2, 8. They add up to 19, so r1=19/42≈0.45r_1 = 19/42 \approx 0.45.
  4. For lag 2 the products are 4, -2, -2, 4, which add up to 4, so r2=4/42≈0.10r_2 = 4/42 \approx 0.10.

The positive autocorrelation at lag 1 comes from the upward trend: neighbours are on the same side of the mean. This is also why a trending series shows a slowly fading ACF, a point the next lesson uses.

How mlflow does it

  • Where to look. For a run that forecasts a time series, the run page has a Forecast tab with the views Forecast, Decomposition, Residuals and ACF / PACF. The model candidate page also lists Decomposition, Autocorrelation and Partial autocorrelation under the Curves group of its Plots tab.
  • How the decomposition is made. The plot uses classical decomposition and is additive by default. The seasonal period comes from the frequency of the dates (for example 12 for monthly data) when it is not given.
  • Which series. The decomposition, ACF and PACF are drawn from the training series, not from the model's forecasts.
  • Settings. You pick the Date column, Forecast horizon and CV folds in the Forecast settings card. The docs page on time series forecasting covers these settings.

Common mistakes

  • Reading a trend as seasonality. A rising series has a high ACF at many lags, which is easy to mistake for a pattern. Remove the trend first (see the next lesson) and look again.
  • Using additive decomposition on a growing swing. The residual then grows with the level and keeps a pattern. Use the multiplicative form, or take the log of the series first.
  • Guessing the seasonal period. A wrong period spreads the seasonal part into the residual. Match it to the data: 12 for monthly data with a yearly cycle, 7 for daily data with a weekly cycle, 4 for quarterly data.
  • Ignoring the residual panel. It is the quality check. A pattern in the residual means the decomposition, or later the model, missed something.
  • Decomposing a series that is too short. You need at least two full seasons to separate seasonality from trend. With less, the parts are not reliable.

Try it in mlflow

Open the decomposition plot

  1. Open Runs and choose a run that forecasts a time series.
  2. Open the Forecast tab.
  3. Switch to Decomposition and look at the Trend, Seasonal and Residual panels.
  4. Switch to ACF / PACF and look for a tall bar at the seasonal lag.
Open in mlflow

Read in the docs

Check your understanding

  1. 1. Monthly ice-cream sales rise a little every year, and the summer peaks grow taller as the level rises. Which decomposition fits best?
  2. 2. The ACF of a monthly series has a clear peak at lag 12 and at lag 24. What does this suggest?
  3. 3. After you remove trend and seasonality, the residual still shows a slow wave. What does that mean?