Explore decomposition, trend, seasonality, smoothing, and forecasting with prediction intervals across three real-world datasets. Learn to spot and prevent temporal leakage.
Select Dataset
Monthly retail revenue with strong trend and seasonality (4 years, 2020–2023).
Original Time Series
48 monthly observations, 2020–2023
Additive Decomposition
Separates the series into trend, seasonal, and residual components. Trend is extracted with a 12-month centred moving average; seasonal is the average deviation from trend by calendar month.
Additive decomposition: Observed = Trend + Seasonal + Residual. The trend captures long-run direction, the seasonal component captures repeating patterns, and the residual is what neither model explains.
Smoothing Methods
Adjust the sliders to see how each method handles noise.
Moving Average
Smooths out short-term fluctuations
A larger window produces a smoother line but introduces more lag. Small windows track the data closely but retain noise.
Exponential Smoothing
Weights recent data more heavily
ES[t] = α · y[t] + (1−α) · ES[t−1]. High α reacts quickly to changes but stays noisy. Low α is smoother but slow to adapt.
12-Month Forecast with Prediction Intervals
Extends a linear trend fitted by least squares to the deseasonalized history, plus the learned monthly seasonal pattern. The shaded band widens with the forecast horizon using a simplified rule of thumb, PI ≈ ŷ ± 1.96 · σ · √(1 + h/n). Real forecasting libraries derive interval width from the fitted model (for example ARIMA state-space variances) rather than this shortcut.
Hold-Out Accuracy (fit on 2020–2022, evaluated on 2023)
The model is fit on the first 36 months only, then forecasts the final 12 months it never saw. The metrics below compare those forecasts against the held-out 2023 actuals. Scoring a model on data it was fit on would be data leakage, and the numbers would look better than the model deserves.
MAE
27.86$
Mean Absolute Error: average unsigned forecast error.
RMSE
34.41$
Root Mean Squared Error: penalises large errors more than MAE.
MAPE
1.7%
Mean Absolute Percentage Error: relative accuracy. Caveat: MAPE is unreliable when values approach or cross zero.
Critical Concept
Critical Pitfall: Temporal Data Leakage
The most common mistake in time series modeling, and how to avoid it.Click to expand
Stationarity
A series is stationary when its mean, variance, and autocorrelation do not change over time. Many forecasting models require stationarity, achieved through differencing or log transforms.
Autocorrelation (ACF)
The correlation of a series with a lagged version of itself. Seasonal series show spikes at lags 12, 24 in monthly data. The ACF guides lag selection in ARIMA models.
Walk-Forward Validation
The correct CV strategy for time series: train on all data up to time t, predict t+1..t+h, advance by one step. Never shuffle time series data for cross-validation.