Time Series Analysis
Time series analysis studies time-ordered data to find trends, seasonality, and anomalies and to forecast future values with statistical and deep models.
Time series analysis is the study of data points recorded in time order, usually at regular intervals, such as hourly sensor readings, daily sales, or the number of vehicles a traffic camera sees each minute. What sets it apart from other data analytics is that order carries information: each observation depends on the ones before it, so shuffling the data destroys the patterns of interest. The main goals are describing a series through its trend and seasonal patterns, forecasting future values, detecting anomalies, and classifying whole series, such as heart rhythms in an ECG.
Trend, Seasonality, and Stationarity#
Most series combine a few components. The trend is the long-term direction, seasonality is a pattern that repeats over a fixed period such as a day, week, or year, cycles are longer rises and falls without a fixed period, and the residual is what remains. Decomposition separates them, classically with moving averages and more robustly with STL, the seasonal-trend decomposition based on local regression that Robert Cleveland and colleagues published in 1990.
Autocorrelation, the correlation of a series with a lagged copy of itself, exposes this structure: a strong value at lag 24 in hourly data means each hour resembles the same hour a day earlier. Many statistical models also assume stationarity, meaning the mean, variance, and autocorrelation do not change over time. The augmented Dickey-Fuller test checks for a common form of non-stationarity, and differencing, which models the change from one step to the next instead of the level, removes a trend.
This example simulates four weeks of hourly vehicle counts with a daily cycle, a slow upward trend, and noise, measures its autocorrelation, and forecasts the last day two ways:
import numpy as np
import pandas as pd
# Four weeks of hourly vehicle counts: a daily cycle, a slow upward trend, and noise
rng = np.random.default_rng(0)
hours = pd.date_range("2026-03-01", periods=24 * 28, freq="h")
daily_cycle = 40 + 30 * np.sin(2 * np.pi * (hours.hour - 9) / 24)
counts = pd.Series(daily_cycle + 0.02 * np.arange(len(hours)) + rng.normal(0, 5, len(hours)), index=hours)
# Autocorrelation: how strongly each count resembles the count 1, 12, and 24 hours earlier
for lag in [1, 12, 24]:
print(f"Autocorrelation at lag {lag}: {counts.autocorr(lag):.2f}")
# Forecast the final day from the 27 days before it
history, actual = counts[:-24], counts[-24:].to_numpy()
naive = np.full(24, history.iloc[-1]) # repeat the last observed count
seasonal_naive = history.iloc[-24:].to_numpy() # repeat the same hour of the previous day
print(f"Naive MAE: {np.abs(actual - naive).mean():.1f} vehicles")
print(f"Seasonal naive MAE: {np.abs(actual - seasonal_naive).mean():.1f} vehicles")The autocorrelation is 0.92 at lag 1, -0.89 at lag 12, where the afternoon peak lines up with the night low, and 0.95 at lag 24. Repeating the last observed count misses by 24.5 vehicles per hour on average, while repeating the previous day misses by 5.6, so the seasonal naive forecast is the baseline a forecasting model has to beat.
Forecasting Methods#
Statistical methods remain strong, especially for short series. Exponential smoothing, developed by Charles Holt and Peter Winters around 1960, weights recent observations most and adds trend and seasonal terms. ARIMA models, popularized by George Box and Gwilym Jenkins in 1970, combine autoregression, differencing, and moving averages of past errors. Meta's Prophet fits trend, seasonality, and holiday effects for business data.
Machine learning models treat forecasting as predictive modeling on lagged values and calendar features. Gradient-boosted trees such as LightGBM dominated the 2020 M5 competition on Walmart sales, while the 2018 M4 competition, with 100,000 series, was won by Slawek Smyl's hybrid of exponential smoothing and a recurrent neural network. Deep learning models include LSTMs, state space models, and transformers, and pretrained foundation models such as Amazon's Chronos and Google's TimesFM forecast new series zero-shot. Kalman filters cover the related task of estimating a hidden state, such as an object's position, from noisy measurements in real time.
Evaluation must respect time. Random cross-validation lets a model see the future, a form of data leakage, so forecasts are tested with rolling-origin evaluation, which trains on everything before a cutoff, predicts the period after it, and repeats as the cutoff moves forward.
Time Series From Video#
Computer vision turns video into time series. Object counting on a traffic camera produces vehicles per minute, object tracking produces positions and speeds per frame, and store cameras produce occupancy counts per hour. These series then feed the same methods: forecasting rush hours or staffing needs, and anomaly detection that flags a sudden drop in traffic after an accident. In the Ultralytics Analytics solution, analytics_type="line" tracks objects with a YOLO26 model and plots the number of objects in view every 30 frames, about once per second for 30 fps video, so a camera feed becomes a count series as it plays.
Time series analysis overlaps with sequence modeling in natural language processing, where text is ordered by position and has no sampling interval. Counts and speeds extracted from video by detection, tracking, and video understanding models take far less space than the frames, so years of them can be stored and compared across cameras.










