skforecast/skforecast-ai/autocorrelation-and-lag-selection
- community
Checking that the SKILL.md file is still in the repository.
Analyzes time series dynamics with the fast skforecast.stats functions acf, pacf and calculate_lag_autocorrelation. Covers reading ACF/PACF patterns to identify AR/MA orders and seasonality, ranking lags by partial autocorrelation, and feeding the result to the lags argument of any skforecast forecaster. Use when the user wants to understand the dynamics of a series, choose a candidate set of lags before hyperparameter tuning, or replace a slow statsmodels acf/pacf call.
Install
npx vskill@latest install skforecast/skforecast-ai/autocorrelation-and-lag-selectionSKILL.md
The same SKILL.md was published earlier as skforecast/skforecast/autocorrelation-and-lag-selection.
Autocorrelation and Lag Selection
When to Use
Use this skill when the user wants to:
- Inspect the ACF / PACF of a series before training a forecaster.
- Pick a sensible starting set of lags for
ForecasterRecursive,ForecasterDirect, or any multi-series forecaster. - Detect seasonality (peaks at multiples of the period) from autocorrelation.
- Replace
statsmodels.tsa.stattools.acf/pacfcalls with a faster equivalent on long series.
Related skills
- Next:
feature-engineering(turn the candidate lags into a full feature pipeline with rolling and calendar features) - Next:
hyperparameter-optimization(refine the candidate set via cross-validation withbayesian_search_forecaster) - Next:
feature-selection(prune redundant lags or exog variables withselect_featuresonce the forecaster is configured)
Overview
| Function | Module | Purpose | |
|---|---|---|---|
acf | skforecast.stats | Biased ACF via FFT; optional Bartlett confidence intervals | |
pacf | skforecast.stats | PACF via FFT + Levinson–Durbin; white-noise CI | |
calculate_lag_autocorrelation | skforecast.stats | Tabular ACF + PACF, ranked by |PACF| |
The skforecast functions mirror the public API ofstatsmodels.tsa.stattools.acf/pacfbut are reimplemented from scratch (FFT for the ACF, Levinson–Durbin for the PACF) to maximise speed on long series. Only the most common configuration options are exposed.If the user needs the wider catalogue offered by statsmodels — alternative estimators ('ywunbiased','ols','ld','burg'), Ljung–Box statistics, etc. — recommend callingstatsmodels.tsadirectly.For plotting, keep the statsmodels helpers with their fastest configuration:plot_acf(..., alpha=0.05, fft=True)andplot_pacf(..., alpha=0.05, method='burg').
Computing the ACF
Notes:
nlagsmust satisfy0 < nlags < len(x). IfNone, defaults tomin(int(10 * log10(n)), n - 1).acf_vals[0]is always1.0.- Default is the biased estimator (
adjusted=False, denominatorn). It guarantees a positive semi-definite Toeplitz matrix and is required for downstream PACF computation.
Computing the PACF
Notes:
nlagsmust satisfy0 < nlags < len(x) // 2— Levinson–Durbin becomes unreliable when the AR order approaches half the sample size; the function raises explicitly.- Confidence intervals are asymptotic under the white-noise null:
±z_{α/2} / sqrt(n)for all lags≥ 1. Lag 0 has no uncertainty. - The implementation uses the biased ACF internally, so values can differ slightly (~2e-2 for typical series) from
statsmodels.pacf(method='yw'), which uses the unbiased estimator.
Reading ACF / PACF Patterns
| Pattern | Suggests | |
|---|---|---|
| ACF cuts off after lag q | MA(q) component | |
| ACF decays slowly | AR or mixed process — use PACF | |
| PACF cuts off after lag p | AR(p) component (lags 1..p are the relevant ones) | |
| PACF decays slowly | MA or mixed process | |
| ACF peaks at lags k, 2k, 3k | Seasonality of period k | |
| Persistent slow decay touching every lag | Trend — difference the series before reading orders |
Ranking Lags with calculate_lag_autocorrelation
Returns a DataFrame with columns ['lag', 'partial_autocorrelation_abs', 'partial_autocorrelation', 'autocorrelation_abs', 'autocorrelation'] covering lags 1..n_lags (lag 0 dropped because it is always 1.0).
last_n_samples keeps only the most recent observations — useful when the series is very long and only the recent dynamics matter:
data accepts a pd.Series or a single-column pd.DataFrame. n_lags must be strictly less than len(data) // 2.
End-to-End: From PACF to a Forecaster
The selected lags are an informed starting point, not a final answer — refine with bayesian_search_forecaster (see hyperparameter-optimization) or prune with select_features (see feature-selection).
Common Mistakes
- Using `nlags >= n // 2` for PACF. Levinson–Durbin loses stability as the AR order approaches half the sample size; the function raises explicitly. Reduce
nlagsor use a longer series. - Reading the ACF to choose AR order. ACF is contaminated by indirect dependencies through earlier lags and rarely cuts off cleanly for AR processes — use the PACF for AR order, the ACF for MA order.
- Treating the confidence bands as joint tests. Bartlett (ACF) and white-noise (PACF) bands are pointwise. Several lags will cross the band by chance; use them to spot candidates, not to formally reject white noise.
- Skipping detrending / differencing. A strong trend dominates the ACF and masks higher-lag structure. If the series shows visible trend, read ACF / PACF on
y.diff().dropna()(or usedifferentiation=1in the forecaster). - Switching to `adjusted=True` by default. The biased estimator is preferred for forecasting workflows; the unbiased one can produce
|ACF| > 1at high lags and breaks the positive semi-definite property required by Levinson–Durbin. - Expecting statsmodels-only options.
method='ols',method='burg', alternative confidence intervals, etc. are not exposed byskforecast.stats.pacf. For those, callstatsmodels.tsa.stattools.pacfdirectly — the API is the same. - Passing a multi-column DataFrame to `calculate_lag_autocorrelation`. It accepts a
Seriesor a single-columnDataFrameand raises otherwise. Select the target column first.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskforecast_ai/skills/autocorrelation-and-lag-selection/SKILL.md
Popularity
- Repository stars
- 50
- Repository forks
- 6
- 7-day trend score
- 20
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/skforecast/skforecast-ai/autocorrelation-and-lag-selection)