mojolearn.AutoTheta#

class mojolearn.AutoTheta(season_length=1, decomposition_type='multiplicative', model=None, initial_smoothed=None, alpha=None, theta=None, numeric_mode=None)[source]#

Bases: object

Automatic theta model selection.

Fits the four theta models (standard, optimized, dynamic, dynamic optimized) and keeps, per series, the one with the least in-sample MSE, or fits the single model named by model. Follows statsforecast’s AutoTheta: a seasonality test and classical decomposition, the theta state-space models, and Nelder-Mead minimization of the MSE.

fit takes one series of shape (n_obs,) or a batch of shape (batch_size, n_obs). The model is estimated when predict() is called; repeating the same predict on the same fitted series returns the stored result.

Parameters:
  • season_length (int, default 1) – Number of observations per season. 1 means no seasonality.

  • decomposition_type ({“multiplicative”, “additive”}, default “multiplicative”) – Seasonal decomposition used when the series tests as seasonal.

  • model ({“STM”, “OTM”, “DSTM”, “DOTM”} or None, default None) – The theta model to fit. None tries all four and keeps the one with the least MSE per series.

  • initial_smoothed (float or None, default None) – Fixes the initial smoothed level; None estimates it.

  • alpha (float or None, default None) – Fixes the smoothing parameter; None estimates it.

  • theta (float or None, default None) – Fixes the theta coefficient; None estimates it.

  • numeric_mode (str or None, default None) – Numeric mode for this model ('identical', 'deterministic' or 'fast'); None uses the process default (see mojolearn.set_numeric_mode()).

Variables:
  • model_ (list of str) – The theta model used for each series ("STM", "OTM", "DSTM" or "DOTM"). Set by predict().

  • info_ (ndarray of shape (batch_size, 8), float32) – Per-series fit summary; column 4 is the index of the chosen model in ("STM", "OTM", "DSTM", "DOTM"). Set by predict().

Notes

Input must be float32; float64 raises TypeError. Each series needs more than 3 observations. Prediction intervals (level), fitted values, non-normal error distributions and exogenous regressors are not supported and raise NotImplementedError.

Examples

>>> import numpy as np, mojolearn
>>> t = np.arange(96, dtype=np.float32)
>>> y = 10 + 0.1 * t + np.sin(2 * np.pi * t / 12).astype(np.float32)
>>> mojolearn.AutoTheta(season_length=12).fit(y).predict(12)["mean"].shape
(12,)
__init__(season_length=1, decomposition_type='multiplicative', model=None, initial_smoothed=None, alpha=None, theta=None, numeric_mode=None)[source]#

Methods

fit(y[, X])

Store one series or a batch of series for forecasting.

forecast(y, h[, X, X_future, level, fitted])

Fit y and forecast h steps in one call.

predict(h[, X, level])

Fit the theta model and forecast h steps ahead.

fit(y, X=None)[source]#

Store one series or a batch of series for forecasting.

The theta model itself is estimated by predict().

Parameters:
  • y (array-like of shape (n_obs,) or (batch_size, n_obs)) – The series, float32, more than 3 observations each. A private copy is kept.

  • X (None) – Exogenous regressors are not supported; anything other than None raises NotImplementedError.

Returns:

self

Raises:
predict(h, X=None, level=None)[source]#

Fit the theta model and forecast h steps ahead.

Parameters:
  • h (int) – Forecast horizon.

  • X (None) – Unused.

  • level (None) – Prediction intervals are not supported; anything other than None raises NotImplementedError.

Returns:

dict – {"mean": forecasts}, shaped (h,) for a single series or (batch_size, h) for a batch.

forecast(y, h, X=None, X_future=None, level=None, fitted=False)[source]#

Fit y and forecast h steps in one call.

Equivalent to fit(y).predict(h). fitted=True (in-sample fitted values) raises NotImplementedError.

Returns:

dict – {"mean": forecasts}, as returned by predict().