AutoSNARIMAX
Using the River and Optuna packages to provide an automatically optimized ARIMA-derived model with the possibility of online updates.
Overview
AutoSNARIMAX is a Python class for automatic hyperparameter optimization of SNARIMAX models using Optuna and the River library. It supports:
- Automatic hyperparameter tuning for SNARIMAX models.
- Incorporation of additional features, including holidays.
- Online updates: the model can be updated incrementally with new observations.
- Forecasting with uncertainty intervals.
Installation
pip install autosarimax
Usage
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from autosarimax import AutoSNARIMAX, add_holiday_feature
# 1️⃣ Create example DataFrame
dates = pd.date_range(start='2025-01-01', periods=30, freq='D')
np.random.seed(42)
y = np.random.randint(50, 150, size=len(dates))
X = pd.DataFrame({'date': dates, 'feature1': np.random.randn(len(dates))})
# 2️⃣ Add holiday feature
X = add_holiday_feature(X, country='BR', date_col='date')
X = X.drop(columns=['date'])
# 3️⃣ Initialize and fit model
model = AutoSNARIMAX(n_trials=5, horizon=1)
model.fit(X, y)
# 4️⃣ Make incremental predictions
pred_df = model.predict(X, force=False)
# 5️⃣ Plot real vs predicted values
plt.figure(figsize=(12, 6))
plt.plot(dates, y, label='Real', marker='o')
plt.plot(dates, pred_df['pred'], label='Predicted', marker='x')
plt.fill_between(dates, pred_df['lower'], pred_df['upper'], color='gray', alpha=0.3, label='Uncertainty')
plt.xlabel('Date')
plt.ylabel('Value')
plt.title('AutoSNARIMAX Forecast vs Real')
plt.legend()
plt.grid(True)
plt.show()
Features
-
add_holiday_feature(df, country, date_col): Adds a binary columnis_holidayindicating whether a date is a holiday. -
fit(X, y): Optimizes hyperparameters and trains the SNARIMAX model. -
update(X, y): Updates the model incrementally with new observations. -
predict(X, horizon, force): Makes forecasts.force=True: forecasts the full horizon without updating the model.force=False: forecasts incrementally and updates the model using the predicted values.
License
MIT License
Metadata
Release files for autosarimax 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| autosarimax-0.1.1.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autosarimax-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.7 kB
Release files / autosarimax-0.1.1.tar.gz
| Download URL | autosarimax-0.1.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff3e2b6792c0a9adf204cc70eae8ef5ba0d0c6a98707252019cf9b578c9154a8
|
|
BLAKE2b-256 checksum How to use checksums |
77cc1656ca939040577a421450de73fa05b9b32f2f7bb3b6ed53eb646ca7b422
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.24
|
Release files / autosarimax-0.1.1-py3-none-any.whl
| Download URL | autosarimax-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81b3bd36da2107e434475fe028aeb1f9e8e554aac74e7b1e4edc8664e7a75ba4
|
|
BLAKE2b-256 checksum How to use checksums |
ed6034ae3656a3547a0286577a8e86de5ee9202c5426ad245ec9c5684a904daf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.24
|