Skip to main content

Using the River and Optuna packages to provide an automatically optimized ARIMA-derived model with the possibility of online updates.

Project description

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 numpy pandas optuna river holidays matplotlib

Usage

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from auto_snarimax 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

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

autosarimax-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

autosarimax-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file autosarimax-0.1.0.tar.gz.

File metadata

  • Download URL: autosarimax-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.24

File hashes

Hashes for autosarimax-0.1.0.tar.gz
Algorithm Hash digest
SHA256 51e61770d07a4422bdd9ec56f38e762bb32f65ffefd7987bbcb36b82b7beb271
MD5 2a7a813c1788de8fe30df42273d3e156
BLAKE2b-256 4423673e2721a9130699452c2e1253143dc4149762a176bfa792679bf1a56fb2

See more details on using hashes here.

File details

Details for the file autosarimax-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: autosarimax-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.24

File hashes

Hashes for autosarimax-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c3f413af9ef083a6a481197c9c101dc08cf489b10f1aa84fa043a3b05855e18
MD5 d19432bc22a88abd353d766be616b8b8
BLAKE2b-256 114792e501317ca9ded284329ad2a6477898181f93951f85090a60fd39ac1853

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