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:
objectExponential 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: errorAorM; trendNorA(optionally damped); seasonN,AorM.Unlike statsforecast, the default is a damped additive-trend model (
model="AAN",damped=True) and no model letter may be'Z'(automatic selection).fittakes 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 samepredicton the same fitted series returns the stored result. A series no longer thanseason_lengthis 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 (seemojolearn.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=Truewithout a trend, a seasonal model withseason_length == 1(“Nonseasonal data”), or additive errors with a multiplicative season (“Forbidden model combination”).NotImplementedError – For a multiplicative trend,
'Z'letters, orseason_lengthabove 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
yand forecasthsteps 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
yis 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_obsis 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.