Decompose a series without confusing trend and seasonality
In this article (5 sections)
Time-series decomposition rewrites an observed series as components. In an additive specification,
observed = trend + seasonal + remainder.
That identity is useful for visualization, diagnostics and feature design. It does not prove that the trend caused growth or that a seasonal component represents a particular holiday. The components depend on the chosen period, smoothing method, edge policy and additive or multiplicative form.
Execute and verify the identity
The local forecasting lab applies classical additive decomposition to the first 120 months of an authored demand series with period 12. The extrapolated trend moves from 53.92 at the beginning to 94.18 at the end. The largest absolute reconstruction difference is about 7.1e-15, floating-point noise.
from timeseries_cases import decomposition_case
result = decomposition_case()
assert result["period"] == 12
assert result["max_reconstruction_error"] < 1e-10
print(round(result["trend_start"], 2), round(result["trend_end"], 2))This prints 53.92 94.18. Verifying reconstruction catches alignment mistakes, missing edge values and accidental mixing of multiplicative and additive formulas.
The estimated seasonal cycle for months 1–12 is approximately [-8.68, -8.57, -5.36, -2.05, 1.59, 13.55, 7.35, 5.93, 1.98, -0.98, 3.71, -8.46]. It sums near zero, as expected for an additive seasonal component. The high sixth component reflects both the authored seasonal pattern and planned promotions that recur in the fixture; decomposition cannot label which mechanism produced it.
Choose the form from scale behavior
An additive model treats seasonal swings as roughly constant units as the level changes. A multiplicative model treats them as roughly constant proportions. Plot seasonal amplitude across low- and high-level periods, check whether values can be zero or negative, and compare out-of-sample behavior. A log transform can turn a positive multiplicative relationship into an additive one, but retransformation and intervals then need care.
Period selection comes from the sampling cadence and plausible business recurrence. Twelve is defensible for annual recurrence in monthly data. It is not evidence that only one cycle exists. Daily data may contain weekly and annual effects; a single classical decomposition cannot express every overlapping seasonal pattern well.
Respect the endpoints
Centered moving averages do not naturally estimate a trend at the first and last observations. The lab asks statsmodels to extrapolate the trend over those edges so all 120 rows reconstruct. That is an explicit convenience for this demonstration, not observed evidence. Forecasting with extrapolated decomposition components requires a separate model and validation.
Use the remainder as a diagnostic. Plot it against time and known events; check changing variance, autocorrelation and outliers. A remainder with structure means the decomposition has not captured everything. It does not automatically identify the missing cause.
The Data Science course connects these diagnostics with forecasting, feature construction and evaluation rather than presenting a component plot as a completed forecast.
Exercise
Repeat the decomposition with periods 6 and 12. Compare reconstruction, component shapes and residual autocorrelation. Explain which period is supported by the monthly business cycle before comparing any forecast score.
Continue learning
This article is part of the Forecasting and time-series analysis sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Review the prerequisite or neighbouring task in MAE, MAPE and WAPE when demand contains zeros.
- Continue with Stationarity: what differencing changes and what it loses.
References: statsmodels seasonal decomposition API and Forecasting: Principles and Practice on time-series components.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our Data Science programme — 6 months. From data foundations to machine learning, deep learning and deployment.
Explore Data Science