Skip to main content

Safe, delay-aware SARIMAX with rolling evaluation and AIC-based lag selection

Project description

🧭 dynamic-sarimax

PyPI Version Python Versions License Tests


Delay-aware SARIMAX wrapper that fixes the common pitfalls of statsmodels.SARIMAX: proper lag alignment for exogenous variables, train-only scaling, and safe rolling-origin evaluation — all built-in.


✨ Why this exists

Plain SARIMAX requires you to hand-align exogenous regressors (e.g. lagged mobility, weather), risking leakage or off-by-one bugs.
dynamic-sarimax makes this safe by construction.

Key guarantees

  • ✅ For delay b, trains only on valid pairs (y_t, x_{t-b}) — never imputes missing lags.
  • ✅ Scalers are fit only on training windows during CV.
  • ✅ Forecasting refuses to run if required future exogenous rows are missing.
  • ✅ Rolling-origin evaluation and AIC-based delay selection included.

🚀 Quickstart

# create venv and install deps
poetry install

# run example (uses example CSV under examples/)
poetry run python examples/ili_quickstart.py
from dynamic_sarimax import (
    SarimaxConfig,
    select_delay_by_aic,
    rolling_evaluate,
)

cfg = SarimaxConfig(order=(5,0,2), seasonal_order=(1,0,0,52))
best_b, best_aic = select_delay_by_aic(y_train, x_train, delays=[1,2,3], cfg=cfg)
print(f"Best lag = {best_b}  |  AIC = {best_aic:.2f}")

res = rolling_evaluate(y, x, cfg, delay=best_b, horizons=24, train_frac=0.8)
print(res.head())

📈 Example output

Chosen delay b (on 80% train): 2 | Train AIC: 1234.56

Per-horizon scores (rolling validation on last 20%):
 h  n_origins     MSE  sMAPE
 1         52   0.103   8.12
 2         51   0.109   8.54
 ...

Average MSE   = 0.124
Average sMAPE = 8.77 %

⚙️ Installation

pip install dynamic-sarimax
# or
poetry add dynamic-sarimax

Python ≥ 3.10, tested on 3.10–3.12.


🧩 Components

Module Purpose
config.py Parameter dataclasses for SARIMAX and lag spec
features.py Safe lagging + scaling transformer
model.py Wrapper around statsmodels.SARIMAX
selection.py Delay (lag) selection via AIC
evaluation.py Rolling-origin cross-validation
metrics.py MSE & sMAPE helpers

🧪 Testing

poetry run pytest -q

🪞 Project links


📜 License

Apache-2.0 © 2025 Nirupom Bose Roy Contributions welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamic_sarimax-0.1.1.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamic_sarimax-0.1.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file dynamic_sarimax-0.1.1.tar.gz.

File metadata

  • Download URL: dynamic_sarimax-0.1.1.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.14.0-32-generic

File hashes

Hashes for dynamic_sarimax-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ebbf0275c71777108df31d6747c4e034b53c505c64159894ae9cecd9a18b162d
MD5 cc319b8885f3f167d92ca9a9c49ddfee
BLAKE2b-256 7d138467ef6df1fc4da9abff7e85e37125f266b4c10aba6ecf4242ac1cdbb97b

See more details on using hashes here.

File details

Details for the file dynamic_sarimax-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dynamic_sarimax-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.14.0-32-generic

File hashes

Hashes for dynamic_sarimax-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8e84fbe468f425022538e64a3857d167462240473de1e7a8a2a26b476395bdb
MD5 186db0a19218b1b08afaabf9af6db277
BLAKE2b-256 7d0d26936c19176161559a11c9704a5f78b1bcc93fc261d57c49b63e4b34695f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page