Skip to content
openforecast-orgPublic

About

The set of functions used for time series analysis and in forecasting.

Topics

Resources

Stars

107 stars

Watchers

4 watching

Forks

Repository files navigation

smooth

License: LGPL-2.1

R:

CRAN_Status_Badge Downloads R-CMD-check

Conda version Conda downloads

Python:

PyPI version PyPI - Downloads Python versions Python CI SLSA Build Level 3

Python wheels on PyPI ship with PEP 740 attestations — SLSA Build Level 3 provenance, signed via Sigstore on the GitHub Actions runner that built them. Verifiable client-side with pypi-attestations.

The smooth package implements Single Source of Error (SSOE) state-space models for forecasting and time series analysis, available for both R and Python.

hex-sticker of the smooth package for R hex-sticker of the smooth package for Python

Both the R and Python versions of smooth depend on the greybox package for distributions, information criteria, and supporting utilities (in Python this also provides the LOWESS smoother). It is installed automatically with smooth.

Installation

R (CRAN):

install.packages("smooth")

R (github):

if (!require("remotes")) install.packages("remotes")
remotes::install_github("openforecast-org/smooth")

Python (PyPI):

pip install smooth

Python (github, dev):

pip install "git+https://github.com/openforecast-org/smooth.git@master#subdirectory=python"

For development versions and system requirements, see the Installation wiki page.

Quick Examples

R

library(smooth)

# ADAM - the recommended function for most tasks
model <- adam(y, model="ZXZ", lags=12)
forecast(model, h=12)

# Exponential Smoothing
model <- es(y, model="ZXZ", lags=12)

# Automatic model selection for ETS+ARIMA and distributions
model <- auto.adam(y, model="ZZZ",
                   orders=list(ar=2, i=2, ma=2, select=TRUE))

Python

from smooth import ADAM, ES

# ADAM model
model = ADAM(model="ZXZ", lags=12)
model.fit(y)
model.predict(h=12)

# Exponential Smoothing
model = ES(model="ZXZ")
model.fit(y)

TBATS

tbats() in R and TBATS in Python implement TBATS (De Livera, Hyndman and Snyder, 2011) in ADAM's single source of error framework: an ETS level and trend, a trigonometric seasonality for each period, ARMA errors, all after a Box-Cox transform. The seasonal periods can be several and need not be integers (52.18 weeks in a year, 8766 hours), and the number of harmonics, the trend, the ARMA orders and the distribution are selected automatically. R and Python fit the same model to the same data.

library(smooth)

# Ten years of weekly data with a yearly cycle of 52.18 weeks
y <- ts(100 + 0.05*(1:520) + 10*sin(2*pi*(1:520)/52.18) + rnorm(520, 0, 2), frequency=52)
model <- tbats(y, lags=c(1, 52.18), h=52, holdout=TRUE)
model$model     # TBATS(lambda, {p,q}, phi, <52.18,k>)
forecast(model, h=52, interval="prediction")
import numpy as np
from smooth import TBATS

t = np.arange(1, 521)
y = 100 + 0.05 * t + 10 * np.sin(2 * np.pi * t / 52.18) + np.random.normal(0, 2, 520)
model = TBATS(lags=[1, 52.18], h=52, holdout=True).fit(y)
print(model.model_name)
fc = model.predict(h=52, interval="prediction")

See the TBATS wiki page for the details.

Documentation

Full documentation is available on the GitHub Wiki, including:

Book: Svetunkov, I. (2023). Forecasting and Analytics with the Augmented Dynamic Adaptive Model (ADAM). Chapman and Hall/CRC. Online: https://openforecast.org/adam/

About

smooth is developed and maintained by OpenForecast, a demand forecasting and inventory management consultancy. The package implements the methods we use in our consulting and teach in our training courses.

About

The set of functions used for time series analysis and in forecasting.

Topics

Resources

Stars

107 stars

Watchers

4 watching

Forks

Releases

Used by

Contributors

Languages