Introduction to Time Series Analysis
Analyze ordered observations, compare forecasts with honest baselines, and avoid leakage, automatic stationarity claims and misleading error metrics.
On This Page
Order is part of the data
A time series records a variable over time. Adjacent observations may depend on one another, so shuffling rows and applying ordinary independent-observation methods can erase relevant structure. Record the time interval, gaps, aggregation and whether definitions change.
Plot the series first. Look for trend, recurring seasonal patterns, abrupt level changes, outliers and missing periods. A seasonal pattern repeats at a calendar frequency; other longer fluctuations need not have a fixed period.
Worked example: build a forecasting baseline
Suppose hypothetical weekly counts observed so far are 10, 12, 11, 13, 12, 14. A naive forecast predicts the next week using the last value: 14. A trailing three-week average predicts (13 + 12 + 14)/3 = 13.
If the next observed count is 15, errors defined as actual minus forecast are 1 and 2. This single comparison favors the naive forecast but cannot establish general superiority. Evaluate across several forecast origins using information available at each origin.
A seasonal naive forecast uses the latest observation from the same seasonal position, such as the same month last year. Complex models should justify their added effort by improving on appropriate simple baselines.
Chronological validation prevents a common form of leakage
Train using an earlier period and evaluate using later observations. For rolling-origin evaluation, repeatedly fit using data up to an origin and forecast the next horizon. Match the horizon to the decision: one-step accuracy does not demonstrate six-month accuracy.
Fit transformations, scaling and feature rules using training data only. A centered moving average incorporates future values and cannot be used as a real-time predictor without leakage. Repeated tuning against the same holdout can also overfit that period.
Stationarity and differencing need context
Weak stationarity involves a stable mean and autocovariance depending on lag rather than calendar time, with finite variance. Some methods require stationarity of the modeled component, while other models explicitly represent changing levels or trends. Not all forecasting methods require the original series to be stationary.
First differences for the six counts above are 2, −1, 2, −1, 2. Differencing may remove a changing level, but it does not automatically produce stationarity. Over-differencing can introduce avoidable variation. Seasonal differencing uses a seasonal lag and addresses a different pattern.
Autocorrelation summarizes relationships across lags. A spike is a clue to investigate, not an automatic instruction to select a particular ARIMA order. Check residual patterns and uncertainty after fitting.
Evaluate error in meaningful units
For actual values 10, 20, 30 and forecasts 12, 18, 33, errors are −2, 2, −3. MAE = 7/3 = 2.3333 units and RMSE = √(17/3) = 2.3805 units. Which error is acceptable depends on the decision and a baseline, not a universal “under 10%” rule.
MAPE divides by actual values and is undefined at zero; it can behave badly near zero. Prediction intervals should express forecast uncertainty, including its change with horizon, rather than simply plotting a fitted line.
Practice
Can tomorrow’s observation be used to calculate today’s centered average in a live forecasting evaluation?
Show the explanation
No. That information was unavailable at today’s forecast origin. Use a trailing feature based only on observations already known, and reproduce that timing in evaluation.
Continue
Review regression diagnostics. NIST introduces time-series structure; the authors of Forecasting: Principles and Practice explain accuracy evaluation and stationarity.
Did this explanation help?
Your response helps us identify lessons that need more work.