Autocorrelation measures how a time series correlates with a delayed (lagged) version of itself. It reveals repeating patterns, periodicity, and the degree to which past values predict future values. Autocorrelation at lag k tells you how similar the series is to itself shifted by k time steps.
Given a time series and a maximum lag, compute the autocorrelation for each lag from 0 to max_lag.
Note that r_0 = 1 always (a series perfectly correlates with itself at lag 0).
Return max_lag plus one values rounded to six decimals.
Input: series = [1, 2, 3, 4, 5], max_lag = 2
Output: [1.0, 0.4, -0.1]
Explanation: Normalizing each lagged covariance by lag-zero variance makes the first value 1.
Input: series = [1, -1, 1, -1, 1, -1], max_lag = 2
Output: [1.0, -0.833333, 0.666667]
Center the series once and reuse the lag-zero sum of squares as the denominator.
For each lag, multiply only pairs that remain within the series.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Autocorrelation measures how a time series correlates with a delayed (lagged) version of itself. It reveals repeating patterns, periodicity, and the degree to which past values predict future values. Autocorrelation at lag k tells you how similar the series is to itself shifted by k time steps.
Given a time series and a maximum lag, compute the autocorrelation for each lag from 0 to max_lag.
Note that r_0 = 1 always (a series perfectly correlates with itself at lag 0).
Return max_lag plus one values rounded to six decimals.
Input: series = [1, 2, 3, 4, 5], max_lag = 2
Output: [1.0, 0.4, -0.1]
Explanation: Normalizing each lagged covariance by lag-zero variance makes the first value 1.
Input: series = [1, -1, 1, -1, 1, -1], max_lag = 2
Output: [1.0, -0.833333, 0.666667]
Center the series once and reuse the lag-zero sum of squares as the denominator.
For each lag, multiply only pairs that remain within the series.
Sign in to take notes on this problem
Accepts: array
Accepts: number