mojolearn.CrostonSBA#
- class mojolearn.CrostonSBA(alias=None, numeric_mode=None)#
Syntetos-Boylan approximation (SBA) of Croston’s method.
The
CrostonClassicforecast multiplied by 0.95, which corrects Croston’s bias. Follows statsforecast’sCrostonSBA.fittakes one series or a batch of shape(batch_size, n_obs).- Parameters:
alias (str or None, default None) – A display name for the model, stored as
alias.numeric_mode (str or None, default None) – Numeric mode for this model (
'identical'or'fast'); None uses the process default (seemojolearn.set_numeric_mode()).'fast'is available on Apple GPUs only.
- Variables:
mean_ (ndarray of shape (batch_size,), float32) – The fitted demand rate of each series; the point forecast.
Notes
Input must be float32; float64 raises TypeError. Prediction intervals, fitted values and exogenous regressors are not supported and raise NotImplementedError.
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> y = (rng.random(120) < 0.3).astype(np.float32) * rng.integers(1, 10, 120).astype(np.float32) >>> mojolearn.CrostonSBA().fit(y).predict(12)["mean"].shape (12,)
Methods
fit(y[, X])Fit 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])Forecast h steps ahead.
- fit(y, X=None)#
Fit one series or a batch of series.
- Parameters:
y (array-like of shape (n_obs,) or (batch_size, n_obs)) – The demand series, float32. One row per series for a batch.
X (None) – Exogenous regressors are not supported; anything other than None raises NotImplementedError.
- Returns:
self – The fitted model, with
mean_set.- Raises:
TypeError – If
yis float64.ValueError – If a series has no observations.
- forecast(y, h, X=None, X_future=None, level=None, fitted=False)#
Fit
yand forecasthsteps 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().
- predict(h, X=None, level=None)#
Forecast h steps ahead.
The Croston forecast is flat: each series’ fitted demand rate, repeated
htimes.- Parameters:
h (int) – Forecast horizon,
h >= 0.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.