Autocorrelation is the correlation between a time series and a lagged copy of itself, measured as a function of the lag. The autocorrelation function (ACF) reports this correlation for every lag k, so it shows how much the value at time t is linearly related to the value at time t minus k. In time series & forecasting work within artificial intelligence, autocorrelation is also called serial correlation, and it is the primary diagnostic for memory, trend and seasonality in sequential data.
Autocorrelation matters because most forecasting methods either exploit it or assume it away. Models such as ARIMA and lag-based machine learning models use past values to predict future ones, while regression residuals and forecast errors should show no remaining autocorrelation if the model has captured all predictable structure.
How the autocorrelation function is computed
The sample autocorrelation at lag k equals the autocovariance at lag k divided by the variance of the series. In practice, the series is centered on its mean, each value is multiplied by the value k steps earlier, the products are summed and the sum is divided by the total sum of squares. The result lies between minus one and plus one, and the value at lag zero is always exactly one.
The estimate is meaningful only when the series is roughly stationary, meaning its mean and variance do not drift over time. A strong trend inflates autocorrelation at every lag, so analysts usually difference or detrend the series first. The table below summarizes the core quantities involved.
| Quantity | Meaning | Typical range |
|---|---|---|
| Lag k | Number of time steps between compared values | 1 to about n/4 |
| Autocovariance | Joint variability of values k steps apart | Any real number |
| ACF value | Normalized autocovariance at lag k | -1 to 1 |
| Confidence band | Approximate limit for white noise | About ±1.96/√n |
The confidence band of about ±1.96 divided by the square root of n gives a quick test: ACF values inside it are consistent with no autocorrelation at that lag. With many lags, about one in twenty will cross the band by chance, so isolated small spikes should not be overinterpreted.
Autocorrelation and partial autocorrelation
The partial autocorrelation function (PACF) measures the correlation between values k steps apart after removing the effect of all intermediate lags. The ACF shows total linear dependence, while the PACF isolates the direct contribution of each lag, which makes the two plots complementary.
| Process | ACF pattern | PACF pattern |
|---|---|---|
| AR(p) | Decays gradually | Cuts off after lag p |
| MA(q) | Cuts off after lag q | Decays gradually |
| ARMA(p, q) | Decays after lag q | Decays after lag p |
| White noise | No significant lags | No significant lags |
| Random walk | Very slow linear decay | Large spike at lag 1 |
These signatures form the basis of the Box-Jenkins identification step for ARIMA models. Real data rarely produces textbook patterns, so the plots suggest candidate model orders that are then compared with information criteria such as AIC.
Software usually estimates the PACF with the Durbin-Levinson recursion or by fitting successive autoregressions of increasing order and keeping the last coefficient of each fit. Both approaches share the same white-noise confidence band as the ACF, and both become unstable at high lags when the series is short, so the PACF is most informative for the first few dozen lags.
Reading seasonality and trend in an ACF plot
An ACF plot reveals structure through the shape of its decay and the location of its peaks. Seasonal series show spikes at multiples of the seasonal period, trending series show slow decay, and well-modeled residuals show values scattered inside the confidence band.
| ACF shape | Likely cause | Typical action |
|---|---|---|
| Slow, steady decay | Trend or unit root | Difference the series |
| Peaks at lags 7, 14, 21 | Weekly seasonality in daily data | Add seasonal terms or lags |
| Peaks at lag 12 | Yearly seasonality in monthly data | Seasonal differencing |
| Alternating signs | Overdifferencing or oscillation | Reduce differencing |
| All lags near zero | White noise | No predictable linear structure |
These readings also guide feature engineering for machine learning forecasters. Lags with strong autocorrelation are good candidates for lag features and rolling window features in gradient boosting models, while the seasonal period suggests calendar features or Fourier terms.
Testing residuals for remaining autocorrelation
A good forecasting model leaves residuals that behave like white noise. Significant autocorrelation in residuals means the model missed predictable structure, which usually also makes its prediction intervals too narrow.
| Test | What it checks | Common use |
|---|---|---|
| Ljung-Box test | Joint significance of several ACF lags | ARIMA and general residual checks |
| Box-Pierce test | Same idea, simpler statistic | Largely replaced by Ljung-Box |
| Durbin-Watson test | First-order autocorrelation | Linear regression residuals |
| Breusch-Godfrey test | Higher-order serial correlation | Regression with lagged regressors |
The Ljung-Box test is the standard choice in forecasting libraries. A small p-value indicates that residuals still contain autocorrelation, which suggests adding lags, seasonal terms or exogenous covariates.
Limitations and common mistakes
Autocorrelation captures only linear dependence, so a series can have near-zero ACF values and still be predictable through nonlinear patterns or volatility clustering. Squared residuals, for example, often show autocorrelation in financial returns that the raw series hides.
- Ignoring nonstationarity: computing the ACF on a trending series produces misleading slow decay at every lag.
- Too many lags for short series: estimates beyond about n/4 lags are unreliable and noisy.
- Overreading single spikes: one significant lag among forty is expected under pure noise.
- Leakage in validation: random train-test splits break temporal order and let correlated neighbors leak into evaluation; use time series cross-validation instead.
- Confusing correlation with causation: autocorrelation describes persistence, not a mechanism.
Deep-learning forecasters do not remove the need for this diagnostic. Inspecting the ACF still helps choose the input window length, and it warns when a model trained on strongly autocorrelated data has fewer effectively independent observations than the raw row count suggests.
Put simply
Autocorrelation tells you how much today looks like yesterday. If a hot day is usually followed by another hot day, temperature has strong autocorrelation. If one day says nothing about the next, autocorrelation is close to zero.
You can also compare today with last week or last year. A shop that is busy every Saturday shows a repeating pattern every seven days. Forecasting models use these repeating links to predict what comes next.
In practice
A grocery chain forecasts daily sales of fresh bread for 120 stores. The analyst plots the ACF of two years of sales for one store and sees strong peaks at lags 7, 14 and 21, which confirms weekly seasonality, plus a slow decay caused by a gradual upward trend. After first differencing and seasonal differencing at lag 7, the remaining ACF and PACF suggest a small seasonal ARIMA model.
The team also builds a gradient boosting model with lag features at 1, 7 and 14 days. A Ljung-Box test on its residuals returns a p-value of 0.41, so no significant autocorrelation remains. Evaluated with rolling-origin cross-validation, the model reduces mean absolute error by about 18 percent compared with a seasonal naive forecast, and stores cut end-of-day bread waste accordingly.