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 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

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.1.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.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: autosarimax-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 ff3e2b6792c0a9adf204cc70eae8ef5ba0d0c6a98707252019cf9b578c9154a8
MD5 9036b396d97471b6cbb2a459f03264e6
BLAKE2b-256 77cc1656ca939040577a421450de73fa05b9b32f2f7bb3b6ed53eb646ca7b422

See more details on using hashes here.

File details

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

File metadata

  • Download URL: autosarimax-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 81b3bd36da2107e434475fe028aeb1f9e8e554aac74e7b1e4edc8664e7a75ba4
MD5 1904b8ba60814674af17a9e0a6ca0285
BLAKE2b-256 ed6034ae3656a3547a0286577a8e86de5ee9202c5426ad245ec9c5684a904daf

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