Skip to main content

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 column is_holiday indicating 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

GitHub

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)

Source distribution for autosarimax 0.1.1
File Size Uploaded
autosarimax-0.1.1.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autosarimax 0.1.1
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page