Contents/ Part XXII · Time Series & Forecasting/ Chapter 132

Components of a Time Series

A time series is data indexed by time, and the order carries the meaning: today depends on yesterday. Before forecasting anything, you take a series apart into the pieces every one of them is built from, trend, seasonality, cycle, and irregular noise, and ask the pivotal question: is it stationary?

⏱️ ~22 min read
🐍 Notebook included
📊 Chapter 132

Everything so far treated observations as interchangeable, a bag of rows you could shuffle without loss. A time series breaks that assumption: the observations arrive in order, and each one leans on the ones before it. That memory is both the challenge and the opportunity. The first skill is to decompose a series into its parts, and to check whether it is stationary, the property nearly every forecasting model assumes.

A time series is a sequence of observations ordered in time. Most decompose into a trend (long-run direction), seasonality (a fixed-period repeat), a cycle (longer, irregular swings), and an irregular remainder. A series is stationary when its mean and variance do not change over time.
Why stationarity is the gate

Most models (ARIMA and friends) assume a constant mean and variance. Real series rarely oblige, they trend and they cycle. The fix is differencing: model the change from one period to the next instead of the level. Getting a series stationary is the doorway to every forecasting method ahead.

1

A Time Series Is a Sum of Parts

Look at almost any real series, monthly sales, daily temperature, hourly traffic, and you can pick out four distinct behaviors layered on top of each other. Decomposition is the act of separating them.

observed = trend + seasonality + irregular observed = trend long-run direction + seasonality repeats every period + irregular random noise a longer, non-repeating cycle (business booms and busts) can ride on the trend too, its length is not fixed like a season's
2

Decomposition: Additive vs Multiplicative

The components combine in one of two ways, and knowing which one you have decides how you model it.

Does the seasonal swing stay the same size, or grow with the level? Additive: observed = T + S + I the wave keeps a constant height as it rises Multiplicative: observed = T × S × I the wave grows taller as the level rises

In an additive series the seasonal swing is a roughly constant amount (say, always about $6,000 more in December). In a multiplicative series it grows with the level (always about 20 percent more), so the wave gets visibly taller as the trend climbs. A neat trick: taking logs of a multiplicative series turns it additive, because log(T × S) = log T + log S. In the companion notebook, one line, seasonal_decompose(sales, model='additive', period=12), splits the series and plots all four panels; the residual sits in a flat band, confirming an additive fit here.

3

Stationarity, Differencing & White Noise

A series is stationary when its statistical behavior does not depend on when you look: a constant mean, a constant variance, and no trend or seasonality drifting the picture. It matters because most models are built on that assumption, and most raw series violate it.

Differencing turns a trending series into a stationary one Non-stationary (raw) the mean drifts up → ADF p ≈ 0.90 difference yₜ − yₜ₋₁ Stationary (differenced) flat mean, constant spread → ADF p ≈ 0.02 the same shape as white noise

The formal check is the Augmented Dickey-Fuller (ADF) test: a small p-value (below 0.05) says stationary. Our raw sales series fails badly (p about 0.90) because its mean climbs. Differencing, replacing each value with its change from the month before, strips the trend, and the differenced series passes (p about 0.02). That “difference until stationary” step is the I (integrated) in ARIMA, which the next chapter builds on. Seasonal patterns get their own seasonal difference at the season's lag.

The endpoint of all this is white noise: a series with zero mean, constant variance, and no autocorrelation, no memory from one step to the next. White noise is the part you cannot forecast, and it is the target for your model's residuals. The autocorrelation function (ACF) makes memory visible: our sales series correlates strongly with last month (lag-1 about 0.79) and shows a telltale spike at lag 12 (the yearly echo), while white noise has every bar sitting near zero. When residuals finally look like white noise, the signal has been fully captured.

4

Real-World Example: Six Years of Online Sales

The companion notebook works a real monthly series end to end, decomposing it, testing stationarity, and reading its autocorrelation, all with statsmodels.

📂 Dataset · components-of-a-time-series--monthly_retail_sales.xlsx

Monthly sales for a growing online store, 72 observations from January 2018 to December 2023. Two columns: month (the calendar month) and sales (total dollars). A clean, compact series with all four components on display.

  • Trend: sales grow about $284 a month (roughly $3,400 a year); the first-year average near $22,000 rises to about $37,000 by the last year.
  • Seasonality: a 12-month pattern peaking in December (about +$6,300) and bottoming in January (about -$3,800).
  • Stationarity: the raw series is non-stationary (ADF p ≈ 0.90); after one difference it is stationary (p ≈ 0.02).
5

Time Series in Machine Learning & AI

Decomposition and stationarity are not just classical-statistics housekeeping; they shape how modern models are built, fed, and judged. The same components resurface as engineered features and as the structure deep models learn.

Where it shows upWhat it looks likeExamples
Classical forecastingModel the components directly after making the series stationaryARIMA / SARIMA, exponential smoothing (ETS), Prophet
Feature engineeringTurn trend and seasonality into columns: lags, rolling means, and calendar parts, then use a tabular modelLag features + XGBoost / LightGBM for demand forecasting
Deep sequence modelsNetworks that learn temporal dependence directly from the raw sequenceRNN, LSTM, GRU, temporal CNNs, Temporal Fusion Transformer
Anomaly detectionFlag points whose value or residual departs from the expected patternFraud, sensor faults, monitoring model drift (see Anomaly Detection)
Foundation modelsLarge pre-trained models that forecast a new series zero-shotTimeGPT, Amazon Chronos, Lag-Llama, Google TimesFM
🔬 Research frontier

The hottest area is time-series foundation models, transformers pre-trained on billions of points across many domains that forecast an unseen series with little or no fine-tuning, echoing what large language models did for text. Whatever the architecture, the ideas in this chapter remain the vocabulary: models still succeed or fail on how well they handle trend, seasonality, and non-stationarity, and they are still judged by whether their residuals look like white noise.

🐍

See the components in Python

The companion notebook loads the six-year sales series, smooths out the trend with a moving average, decomposes it into trend, seasonal, and residual with seasonal_decompose, compares additive versus multiplicative, tests stationarity with the ADF test before and after differencing, and reads the autocorrelation function against white noise, every concept with a plot.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub

View opens the rendered notebook instantly. Open in Colab runs it live. To run locally, install numpy, pandas, matplotlib, statsmodels, and openpyxl.

🎓 Key Takeaways

  • Order carries meaning: a time series cannot be shuffled, each value leans on the ones before it.
  • Four components: trend (long-run direction), seasonality (fixed-period repeat), cycle (variable-length swing), and irregular noise.
  • Additive vs multiplicative: a constant seasonal swing versus one that grows with the level, take logs to turn the second into the first.
  • Stationarity is the gate: constant mean and variance; test with ADF and reach it by differencing (the “I” in ARIMA).
  • White noise is the target: no autocorrelation left; when residuals look like it, the signal is captured, and the ACF is how you check.
6

Practice Challenges

Five exercises on the sales series. Full solutions are in the companion solutions notebook.

1

Year-over-year growth

Compute the 12-month percent change and report the average annual growth rate. Why does this cancel seasonality?

Hint: s.pct_change(12).
2

The seasonal profile

Chart the average sales for each calendar month and name the peak and trough.

Hint: s.groupby(s.index.month).mean().
3

Additive or multiplicative?

Decompose the series both ways and compare how flat the residuals are. Which fits better here?

Hint: seasonal_decompose(model=...).
4

Make it stationary

Difference the series and run the ADF test; also try a seasonal difference at lag 12. Report the p-values.

Hint: adfuller(s.diff().dropna()).
5

Autocorrelation vs white noise

Plot the ACF and PACF, find the seasonal lag, and contrast with the ACF of a white-noise series.

Hint: plot_acf, plot_pacf.
📓

Solutions notebook

All five challenges worked in code, year-over-year growth, the seasonal profile, additive versus multiplicative, differencing to stationarity, and the ACF/PACF against white noise, each with a short explanation.

📓 View Solutions ▶ Open in Colab ⬇ GitHub
7

Quiz: Test Yourself

Eight questions on components, decomposition, stationarity, and white noise. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved.

➡️
Up next

Now that you can decompose a series and make it stationary, you are ready to predict its future. Forecasting Models builds moving averages, exponential smoothing, and ARIMA/SARIMA on exactly these foundations.