mojolearn.ETS#

class mojolearn.ETS(season_length=1, model='AAN', damped=True, alpha=None, beta=None, phi=None, gamma=None, numeric_mode=None)[source]#

Bases: object

Exponential smoothing (ETS) with a fixed model.

Fits ETS(E, T, S) by maximum likelihood over the smoothing parameters and initial states, following statsforecast’s AutoETS(season_length=m, model=..., damped=...). Supported models: error A or M; trend N or A (optionally damped); season N, A or M.

Unlike statsforecast, the default is a damped additive-trend model (model="AAN", damped=True) and no model letter may be 'Z' (automatic selection). 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, and repeating the same predict on the same fitted series returns the stored result. A series no longer than season_length is fitted without a season, as in statsforecast.

Parameters:
  • season_length (int, default 1) – Number of observations per season; must be greater than 1 for a seasonal model and at most 58.

  • model (str, default “AAN”) – Three letters: error (A/M), trend (N/A) and season (N/A/M).

  • damped (bool, default True) – Damp the trend. Requires a trend (model[1] == "A").

  • alpha, beta, phi, gamma (float or None, default None) – Fix the level, trend, damping and seasonal smoothing parameters; None estimates each.

  • 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:
  • info_ (ndarray of shape (batch_size, 10), float32) – Per-series fit summary. Set by predict().

  • seasonal_states_ (ndarray of shape (season_length,) or (batch_size, season_length), float32) – Final seasonal states, for seasonal models only. Set by predict().

Raises:
  • ValueError – For an invalid model string, damped=True without a trend, a seasonal model with season_length == 1 (“Nonseasonal data”), or additive errors with a multiplicative season (“Forbidden model combination”).

  • NotImplementedError – For a multiplicative trend, 'Z' letters, or season_length above 58 with a seasonal model.

Notes

Input must be float32; float64 raises TypeError. Each series needs at least 4 observations, and more than the number of parameters plus 4. Multiplicative errors or seasons need strictly positive data. Prediction intervals, fitted values and exogenous regressors are not supported and raise NotImplementedError.

Examples

>>> import numpy as np, mojolearn
>>> t = np.arange(120, dtype=np.float32)
>>> y = 50 + 0.2 * t + 5 * np.sin(2 * np.pi * t / 12).astype(np.float32)
>>> model = mojolearn.ETS(season_length=12, model="AAA", damped=False).fit(y)
>>> model.predict(12)["mean"].shape
(12,)
__init__(season_length=1, model='AAN', damped=True, alpha=None, beta=None, phi=None, gamma=None, numeric_mode=None)[source]#

Methods

fit(y[, X])

Check and store one series or a batch of series.

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

Fit y and forecast h steps in one call.

predict(h[, X, level])

Fit the model and forecast h steps ahead.

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

Check and store one series or a batch of series.

The model itself is estimated by predict().

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

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

Returns:

self

Raises:
  • TypeError – If y is float64.

  • ValueError – If a series has fewer than 4 observations, if a multiplicative model meets non-positive or non-finite values, or if there are too many parameters for the number of observations.

  • NotImplementedError – If n_obs is at most the parameter count plus 4.

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

Fit the 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().