Time Series Forecasting Tutorial: ARIMA, Prophet, LSTMs, Transformers (2026)
Time series forecasting has applications in finance, supply chain, energy, and operations. Specialized approaches are needed for temporal dependencies, seasonality, and autocorrelation.
The forecasting toolkit includes classical ARIMA, accessible Prophet, and deep learning approaches like LSTMs and Transformers for complex patterns.
Time Series Fundamentals
Stationarity is key for many models. The ADF test checks for stationarity. Differencing transforms non-stationary series. ACF and PACF plots guide AR and MA order selection.
I spend significant time on decomposition before modeling. Seasonal decomposition using statsmodels reveals patterns that guide the entire approach.
from statsmodels.tsa.stattools import adfuller\nresult = adfuller(series)\nprint(f"ADF: {result[0]:.3f}, p-value: {result[1]:.3f}")\nfrom statsmodels.tsa.seasonal import seasonal_decompose\ndecomposition = seasonal_decompose(series, model="additive", period=12)
ARIMA and SARIMA Models
ARIMA captures autoregression, differencing, and moving average components. SARIMA adds seasonal terms. The auto_arima function automates order selection.
For monthly sales, auto_arima selected SARIMA(1,1,1)(1,1,1,12). The model produced reasonable 12-month forecasts with widening prediction intervals.
from statsmodels.tsa.arima.model import ARIMA\nfrom pmdarima import auto_arima\nmodel = ARIMA(series, order=(1,1,1), seasonal_order=(1,1,1,12))\nresult = model.fit()\nforecast = result.forecast(steps=12)
Facebook Prophet
Prophet decomposes series into trend, seasonality, and holiday components. Handles missing data, outliers, and changepoints automatically.
I used Prophet for web traffic forecasting with weekly and yearly seasonality plus holiday effects. Additive vs multiplicative seasonality handles varying amplitude.
from prophet import Prophet\ndf = pd.DataFrame({"ds": dates, "y": values})\nmodel = Prophet(yearly_seasonality=True, weekly_seasonality=True)\nmodel.add_country_holidays(country_name="US")\nmodel.fit(df)\nforecast = model.predict(model.make_future_dataframe(periods=365))
LSTM Networks
LSTMs learn long-range dependencies for sequence forecasting. They handle non-linear patterns and multiple input features but require more data.
For electricity load forecasting with 168-hour sequences, the LSTM outperformed SARIMA by 15 percent MAPE, primarily due to handling temperature-load interactions.
class LSTMForecast(nn.Module):\n def __init__(self, input_size, hidden_size=64, num_layers=2):\n super().__init__()\n self.lstm = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True)\n self.fc = nn.Linear(hidden_size, 1)\n def forward(self, x):\n return self.fc(self.lstm(x)[0][:, -1, :])
Transformer Time Series
Transformers achieve state-of-the-art on long-horizon forecasting. Self-attention captures dependencies between any time steps. PatchTST divides series into patches as tokens.
PatchTST reduced MAE by 22 percent compared to LSTM on multivariate energy forecasting. Patching preserves local patterns while reducing sequence length.
class PatchTST(nn.Module):\n def __init__(self, patch_len, d_model=128):\n super().__init__()\n self.patch_linear = nn.Linear(patch_len, d_model)\n self.transformer = nn.TransformerEncoder(nn.TransformerEncoderLayer(d_model, 8), 3)\n self.head = nn.Linear(d_model, 1)
Forecast Evaluation and Deployment
MAE, RMSE, MAPE, and MASE measure forecast accuracy. Time series cross-validation with expanding windows respects temporal order.
In production, combine models through averaging or stacking. Monitor forecast accuracy over time to detect concept drift needing retraining.
from sklearn.model_selection import TimeSeriesSplit\nfor train_idx, test_idx in TimeSeriesSplit(n_splits=5).split(X):\n model.fit(X[train_idx]); predictions = model.predict(X[test_idx])
Frequently Asked Questions
Difference between ARIMA and Prophet?
ARIMA models autocorrelation for stationary series. Prophet decomposes into trend, seasonality, and holidays. Prophet is easier to use, ARIMA more accurate on clean data.
Do I need deep learning for forecasting?
Classical methods perform well on most univariate tasks. Use deep learning for multiple related series, long sequences, or complex non-linear patterns.
How to handle multiple seasonality?
Prophet handles multiple seasonality natively. For ARIMA, use SARIMA with the longest period. For LSTMs, include multiple seasonal features as inputs.
How to generate prediction intervals?
ARIMA and Prophet provide built-in intervals. For LSTMs, use quantile regression, Monte Carlo dropout, or conformal prediction.
Originally published on Ayodhyyya. Last updated June 1, 2026.