STL decomposition, short for Seasonal-Trend decomposition using Loess, is a filtering procedure that splits a time series into three additive parts: a trend component, a seasonal component and a remainder. In time series & forecasting it is one of the most widely used tools for understanding structure in data before a model is fitted, because it handles any regular seasonal period and can be made robust to outliers.
The method was published in 1990 by Cleveland, Cleveland, McRae and Terpenning. Its core idea is to estimate each component with locally weighted regression (loess) and to refine the estimates through nested iterations, so that the trend does not absorb seasonality and the seasonal pattern does not absorb the trend.
How STL separates trend, season and remainder
STL assumes the additive model Y = T + S + R, where each observation equals trend plus seasonal plus remainder. The algorithm runs an inner loop that alternates between estimating the seasonal and trend components, wrapped in an optional outer loop that computes robustness weights.
- Detrend the series by subtracting the current trend estimate, which starts at zero.
- Smooth each cycle-subseries with loess; for monthly data, all Januaries form one subseries, all Februaries another.
- Low-pass filter the result with moving averages and loess, then subtract it so the seasonal part carries no trend.
- Deseasonalize the original series by subtracting the new seasonal estimate.
- Smooth the deseasonalized series with loess to obtain the updated trend.
In the outer loop, the remainder R = Y – T – S is used to compute bisquare robustness weights. Observations with large residuals, measured against roughly six times the median absolute residual, receive weights near zero, so isolated spikes stop distorting the trend and seasonal estimates in the next pass.
Key STL parameters and their effects
STL behavior is controlled by a handful of smoothing spans and iteration counts. Most implementations derive sensible defaults from the period, but the seasonal and trend windows deserve deliberate choice because they decide how much change each component may show.
| Parameter | Meaning | Typical setting | Effect of a larger value |
|---|---|---|---|
| Period (n_p) | Observations per seasonal cycle | 12 monthly, 7 daily, 24 hourly | Defines the pattern being extracted |
| Seasonal window (n_s) | Loess span across cycle-subseries | Odd, at least 7 | Seasonal shape changes more slowly |
| Trend window (n_t) | Loess span for the trend | About 1.5 times the period or more | Smoother, less reactive trend |
| Low-pass window (n_l) | Span of the low-pass filter | Smallest odd value above the period | Rarely changed in practice |
| Inner iterations (n_i) | Passes of the inner loop | 2 without robustness, 1 with it | Little gain beyond defaults |
| Outer iterations (n_o) | Robustness passes | 0, or about 5-15 when robust | Stronger outlier downweighting |
Setting the seasonal window to periodic forces an identical seasonal pattern in every cycle, which reproduces classical decomposition behavior. A small seasonal window lets the pattern evolve year by year, which suits retail data whose holiday peak shifts in size over time but risks leaking noise into the seasonal component.
STL compared with other decomposition methods
STL is one of several ways to separate seasonality from trend, and the choice depends on data frequency, required statistical rigor and calendar effects. The table contrasts it with the most common alternatives.
| Method | Seasonal pattern | Strengths | Weaknesses |
|---|---|---|---|
| Classical decomposition | Fixed every cycle | Simple moving averages | No trend at series ends, outlier-sensitive |
| X-13ARIMA-SEATS | Can evolve | Official statistics, trading-day effects | Monthly and quarterly data only |
| STL | Can evolve, user-controlled | Any period, robust option | Additive only, no calendar adjustment |
| MSTL | Several periods at once | Hourly and daily data with multiple cycles | More parameters to tune |
| Prophet components | Fourier-based, smooth | Holidays and changepoints built in | Model-based, less local flexibility |
Unlike X-13ARIMA-SEATS, STL does not adjust for trading days or moving holidays such as Easter. Unlike classical decomposition, it produces trend values at both ends of the series. Its extension MSTL applies STL repeatedly to remove several seasonal periods, for example daily and weekly cycles in electricity load.
Using STL in forecasting and machine learning
STL is a preprocessing and diagnostic step, not a forecasting model by itself. A common pattern is decompose, forecast, recombine: the seasonally adjusted series (trend plus remainder) is forecast with ETS, ARIMA or a neural model, and the seasonal component is projected forward with a seasonal naive rule and added back.
| Use | What STL provides | Downstream step |
|---|---|---|
| Forecasting | Seasonally adjusted series | Fit ETS or ARIMA, then reseasonalize |
| Anomaly detection | Remainder component | Flag points beyond a robust threshold |
| Feature engineering | Trend and seasonal strength | Inputs to global or ensemble models |
| Exploratory analysis | Visual component plots | Judge stability of seasonality |
The strength of seasonality can be measured as one minus the ratio of remainder variance to the variance of seasonal plus remainder; values near 1 indicate strong seasonality. Such statistics are widely used as features when a single global model is trained across thousands of series.
Limitations and common mistakes with STL
The most frequent error is applying additive STL to data with multiplicative seasonality, where seasonal swings grow with the level. The standard remedy is a logarithmic or Box-Cox transformation before decomposition, followed by back-transformation of the components.
- Too short a series: at least two full cycles are required, and reliable seasonal estimates usually need many more.
- Wrong period: an incorrect period produces a meaningless seasonal component and a remainder full of structure.
- Overly flexible windows: a small trend window lets the trend chase noise and short shocks.
- Look-ahead leakage: decomposing the full history before a train-test split lets loess use future values, which inflates backtest accuracy.
- End effects: estimates near the most recent observations are less stable and may revise as new data arrive.
STL also assumes regularly spaced observations and offers no uncertainty intervals for its components. For forecasting with prediction intervals, the decomposition must be combined with a probabilistic model of the adjusted series.
Stripped to the essentials
Many numbers that change over time mix three things. There is a slow long-term direction. There is a pattern that repeats, such as every year or every week. And there is leftover noise.
STL pulls these three apart. It works like sorting a pile of mail into bills, letters and advertising. Each part can then be studied on its own. This makes it much easier to see what is really changing and what is just the usual seasonal rhythm.
Where it is applied
A regional water utility records daily water consumption over six years and wants to plan pumping capacity. Demand rises every summer and dips on weekends, while population growth adds a slow upward drift. Analysts first apply MSTL with periods of 7 and 365 days and enable robust iterations, because a pipe burst produced several days of extreme readings.
The decomposition shows a steady trend increase of about 2% per year, a summer peak roughly 35% above the winter level and a weekend dip of about 8%. The robust weights isolate the burst in the remainder instead of distorting the summer pattern. The team then forecasts the adjusted series with an ETS model and adds the projected seasonal components back, producing a next-summer peak estimate that guides the decision to commission an additional pump before the hot season.