Safe, delay-aware SARIMAX with rolling evaluation and AIC-based lag selection
Project description
🧭 dynamic-sarimax
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dynamic_sarimax-0.1.0.tar.gz.
File metadata
- Download URL: dynamic_sarimax-0.1.0.tar.gz
- Upload date:
- Size: 8.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86f6a27cbf991fab6d4afc4682da4143b14995c836832e8435b6fb902ccdf4b2
|
|
| MD5 |
9096da90b112c1deb4ae5fc4b1f23318
|
|
| BLAKE2b-256 |
050afeabc74791d89a46d7792b4f647b7368b053d37e5bf9cd4bd837cb140a1c
|
File details
Details for the file dynamic_sarimax-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dynamic_sarimax-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bc3ac05b78bc9a268906827891b34cda5a311d7185a00ed3b161066c24b5daf
|
|
| MD5 |
30f9d8a331e66ce877066cfb474d54b4
|
|
| BLAKE2b-256 |
766d2956ad9282d9105f534a30b71de40c4e910e297499822b1b133e5fbede1f
|