mojolearn.STL#
- class mojolearn.STL(endog, period=None, seasonal=7, trend=None, low_pass=None, seasonal_deg=1, trend_deg=1, low_pass_deg=1, robust=False, seasonal_jump=1, trend_jump=1, low_pass_jump=1, numeric_mode=None)[source]#
Bases:
objectSeason-Trend decomposition using Loess.
Splits each series into seasonal, trend and residual components with statsmodels’ STL algorithm and parameters.
endogmay be one series of shape(n_obs,)or a batch of shape(batch_size, n_obs), one series per row, all sharing the configuration.Unlike statsmodels,
periodis required: statsmodels can infer it from a pandas index, which is not supported here.- Parameters:
endog (array-like of shape (n_obs,) or (batch_size, n_obs)) – The series, float32. float64 raises TypeError.
period (int) – Periodicity of the season, at least 2. Required.
seasonal (int, default 7) – Length of the seasonal smoother (odd).
trend (int or None, default None) – Length of the trend smoother. None uses statsmodels’ default, the smallest odd integer at least
1.5 * period / (1 - 1.5 / seasonal).low_pass (int or None, default None) – Length of the low-pass filter. None uses the smallest odd integer greater than
period.seasonal_deg, trend_deg, low_pass_deg ({0, 1}, default 1) – Degree of each Loess fit (0 constant, 1 linear).
robust (bool, default False) – Use robust fitting with outer iterations and robustness weights.
seasonal_jump, trend_jump, low_pass_jump (int, default 1) – Evaluate each smoother every
jumppoints and interpolate between.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()).
- Raises:
TypeError – If
endogis float64.ValueError – If
periodis missing or below 2, a degree is not 0 or 1, orendogis not 1-D or 2-D.
Examples
>>> import numpy as np, mojolearn >>> t = np.arange(144, dtype=np.float32) >>> y = 0.05 * t + np.sin(2 * np.pi * t / 12).astype(np.float32) >>> res = mojolearn.STL(y, period=12).fit() >>> res.seasonal.shape (144,)
- __init__(endog, period=None, seasonal=7, trend=None, low_pass=None, seasonal_deg=1, trend_deg=1, low_pass_deg=1, robust=False, seasonal_jump=1, trend_jump=1, low_pass_jump=1, numeric_mode=None)[source]#
Methods
fit([inner_iter, outer_iter])Run the decomposition.
Attributes
The decomposition settings as a dict.
- property config#
The decomposition settings as a dict.
- fit(inner_iter=None, outer_iter=None)[source]#
Run the decomposition.
- Parameters:
inner_iter (int or None, default None) – Inner loop iterations. None uses 2 when
robustand 5 otherwise, as statsmodels does.outer_iter (int or None, default None) – Outer (robustness) iterations. None uses 15 when
robustand 0 otherwise.
- Returns:
DecomposeResult –
observed,seasonal,trend,residandweights, each shaped likeendog.