Time Series Analysis Cheat Sheet
Techniques for analyzing and forecasting time-indexed data, covering stationarity, decomposition, ARIMA modeling, and evaluation with statsmodels.
2 PagesIntermediateFeb 28, 2026
Stationarity & Decomposition
Test for stationarity and split into components.
python
import pandas as pdfrom statsmodels.tsa.stattools import adfullerfrom statsmodels.tsa.seasonal import seasonal_decomposets = pd.read_csv("sales.csv", index_col="date", parse_dates=True)["sales"]# Augmented Dickey-Fuller test for stationarityresult = adfuller(ts)print(f"ADF statistic: {result[0]:.3f}, p-value: {result[1]:.4f}")# p < 0.05 -> reject null -> series is stationary# Decompose into trend, seasonal, and residual componentsdecomposition = seasonal_decompose(ts, model="additive", period=12)decomposition.plot()# Differencing to achieve stationarityts_diff = ts.diff().dropna()
ARIMA Forecasting
Fit an ARIMA model and forecast future values.
python
from statsmodels.tsa.arima.model import ARIMAimport matplotlib.pyplot as plt# ARIMA(p, d, q): p=AR order, d=differencing, q=MA ordermodel = ARIMA(ts, order=(2, 1, 2))fitted = model.fit()print(fitted.summary())# Forecast the next 12 periodsforecast = fitted.get_forecast(steps=12)mean_forecast = forecast.predicted_meanconf_int = forecast.conf_int()plt.plot(ts, label="observed")plt.plot(mean_forecast, label="forecast")plt.fill_between(conf_int.index, conf_int.iloc[:, 0], conf_int.iloc[:, 1], alpha=0.2)plt.legend()
Time Series Concepts
Core vocabulary for sequential data analysis.
- Stationarity- statistical properties (mean, variance) don't change over time; required by many models like ARIMA
- Trend- long-term increase or decrease in the series
- Seasonality- repeating pattern at fixed, known intervals (e.g. daily, yearly)
- Autocorrelation (ACF)- correlation of the series with its own lagged values
- Partial autocorrelation (PACF)- correlation with a lag after removing effects of shorter lags; used to choose AR order
- Differencing- subtracting consecutive observations to remove trend and induce stationarity
- ARIMA(p,d,q)- AutoRegressive Integrated Moving Average model combining lag terms, differencing, and error terms
- Exponential smoothing- forecasting method weighting recent observations more heavily (e.g. Holt-Winters)
Forecast Evaluation Metrics
Ways to score forecast accuracy.
- MAE- Mean Absolute Error; average absolute difference between forecast and actual
- RMSE- Root Mean Squared Error; penalizes large errors more than MAE
- MAPE- Mean Absolute Percentage Error; scale-independent, but unstable near zero actuals
- Walk-forward validation- retrain and re-evaluate on an expanding window to mimic real forecasting
- Baseline comparison- always compare against a naive forecast (e.g. last value or seasonal naive)
Pro Tip
Never randomly shuffle or use standard k-fold cross-validation on time series data — always evaluate with a forward-chaining/expanding-window split (e.g. TimeSeriesSplit) so the model is never trained on future data to predict the past.
Was this cheat sheet helpful?
Explore Topics
#TimeSeriesAnalysis#TimeSeriesAnalysisCheatSheet#DataScience#Intermediate#StationarityDecomposition#ARIMAForecasting#TimeSeriesConcepts#ForecastEvaluationMetrics#MachineLearning#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance