MSTLSeriesTransformer¶
- class MSTLSeriesTransformer(periods: Sequence[int], iterate: int = 2, *, s_windows: Sequence[int | None] | None = None, trend: int | None = None, low_pass: int | None = None, seasonal_deg: int = 1, trend_deg: int = 1, robust: bool = False, seasonal_jump: int = 1, trend_jump: int = 1, inner_iter: int | None = None, outer_iter: int | None = None, boxcox_lambda: float | None = None, impute_missing: bool = True, output: str = 'remainder')[source]¶
Bases:
BaseSeriesTransformerMultiple Seasonal-Trend decomposition using Loess (MSTL) for a single series.
Implements the MSTL algorithm described by Bandara, Hyndman & Bergmeir (2021)[1], extending STL to multiple seasonalities via iterative STL fits. See Algorithm 1 and Appendix A in the paper for defaults of seasonal windows. The R reference is forecast::mstl.
The algorithm iteratively applies STL per seasonal period (smallest to largest), adding back the previously stored seasonal for the current period before refitting, and then subtracting the new estimate (Algorithm 1). The trend is taken from the last STL fit in the final outer iteration.
- Parameters:
- periodsSequence[int]
Seasonal periods to extract (ascending order is not required).
- iterateint, default=2
Number of outer iterations over the list of seasonalities.
- s_windowsSequence[Optional[int]] or None, default=None
Seasonal LOESS windows (odd ints) for each period. If None, defaults are s_window[i] = smallest odd >= 7 + 4*(i+1) i=0..m-1 i.e., 11, 15, 19, …
- trendOptional[int], default=None
STL trend window (odd int, > period). If None, STL default is used per period.
- low_passOptional[int], default=None
STL internal low-pass window. If None, STL default is used per period.
- seasonal_deg{0,1}, default=1
Seasonal LOESS degree for STL calls.
- trend_deg{0,1}, default=1
Trend LOESS degree for STL calls.
- robustbool, default=False
Enable STL robustness iterations in each inner STL.
- seasonal_jumpint, default=1
- Evaluate seasonal LOESS every seasonal_jump points in STL
(knot interpolation).
- trend_jumpint, default=1
Evaluate trend LOESS every trend_jump points in STL (knot interpolation).
- inner_iterOptional[int], default=None
STL inner iterations per STL call; defaults to 2 if robust else 5.
- outer_iterOptional[int], default=None
STL robustness iterations per STL call; defaults to 15 if robust else 0.
- boxcox_lambdaOptional[float], default=None
If given, apply Box–Cox transform before decomposition (strictly positive data). lambda=0 uses log transform.
- impute_missingbool, default=True
Linearly interpolate NaNs before decomposition.
- output{“remainder”,”trend”,”seasonal_sum”,”seasonals”,”all”}, default=”remainder”
“remainder”: (n,)
“trend”: (n,)
“seasonal_sum”: sum of all seasonal components, (n,)
“seasonals”: (n, m) matrix with one column per period (ascending)
“all”: (n, m+2) matrix with columns [*seasonals, trend, remainder]
Notes
Capabilities ¶ Missing Values
Yes
Multithreading
No
Inverse Transform
No
Univariate
Yes
Multivariate
No
References
[1]Bandara, K., Hyndman, R.J., & Bergmeir, C. (2021).
“MSTL: A Seasonal-Trend Decomposition Algorithm for Time Series with Multiple Seasonal Patterns.” arXiv:2107.13462.
Methods
clone([random_state])Obtain a clone of the object with the same hyperparameters.
fit(X[, y, axis])Fit transformer to X, optionally using y if supervised.
fit_transform(X[, y, axis])Fit to data, then transform it.
get_class_tag(tag_name[, raise_error, ...])Get tag value from estimator class (only class tags).
Get class tags from estimator class and all its parent classes.
get_fitted_params([deep])Get fitted parameters.
get_params([deep])Get parameters for this estimator.
get_tag(tag_name[, raise_error, ...])Get tag value from estimator class.
get_tags()Get tags from estimator.
reset([keep])Reset the object to a clean post-init state.
set_fit_request(*[, axis])Configure whether metadata should be requested to be passed to the
fitmethod.set_params(**params)Set the parameters of this estimator.
set_tags(**tag_dict)Set dynamic tags to given values.
set_transform_request(*[, axis])Configure whether metadata should be requested to be passed to the
transformmethod.transform(X[, y, axis])Transform X and return a transformed version.
- clone(random_state=None)[source]¶
Obtain a clone of the object with the same hyperparameters.
A clone is a different object without shared references, in post-init state. This function is equivalent to returning
sklearn.cloneofself. Equal in value totype(self)(**self.get_params(deep=False)).- Parameters:
- random_stateint, RandomState instance, or None, default=None
Sets the random state of the clone. If
None, the random state is not set. Ifint,random_stateis the seed used by the random number generator. IfRandomStateinstance,random_stateis the random number generator.
- Returns:
- estimatorobject
Instance of
type(self), clone of self (see above)
- fit(X, y=None, axis=1)[source]¶
Fit transformer to X, optionally using y if supervised.
Writes to self: - is_fitted : flag is set to True. - model attributes (ending in “_”) : dependent on estimator
- Parameters:
- XInput data
Time series to fit transform to, of type
np.ndarray,pd.Seriespd.DataFrame.- yTarget variable, default=None
Additional data, e.g., labels for transformation
- axisint, default = 1
Axis of time in the input series. If
axis == 0, it is assumed each column is a time series and each row is a time point. i.e. the shape of the data is(n_timepoints, n_channels).axis == 1indicates the time series are in rows, i.e. the shape of the data is(n_channels, n_timepoints)`.``axis is Noneindicates that the axis of X is the same asself.axis.
- Returns:
- selfa fitted instance of the estimator
- fit_transform(X, y=None, axis=1)[source]¶
Fit to data, then transform it.
Fits the transformer to X and y and returns a transformed version of X.
Changes state to “fitted”. Model attributes (ending in “_”) : dependent on estimator.
- Parameters:
- XInput data
Data to fit transform to, of valid collection type.
- yTarget variable, default=None
Additional data, e.g., labels for transformation
- axisint, default = 1
Axis of time in the input series. If
axis == 0, it is assumed each column is a time series and each row is a time point. i.e. the shape of the data is(n_timepoints, n_channels).axis == 1indicates the time series are in rows, i.e. the shape of the data is(n_channels, n_timepoints)`.``axis is Noneindicates that the axis of X is the same asself.axis.
- Returns:
- transformed version of X with the same axis as passed by the user, if axis
- not None.
- classmethod get_class_tag(tag_name, raise_error=True, tag_value_default=None)[source]¶
Get tag value from estimator class (only class tags).
- Parameters:
- tag_namestr
Name of tag value.
- raise_errorbool, default=True
Whether a
ValueErroris raised when the tag is not found.- tag_value_defaultany type, default=None
Default/fallback value if tag is not found and error is not raised.
- Returns:
- tag_value
Value of the
tag_nametag in cls. If not found, returns an error ifraise_errorisTrue, otherwise it returnstag_value_default.
- Raises:
- ValueError
if
raise_errorisTrueandtag_nameis not inself.get_tags().keys()
Examples
>>> from aeon.classification import DummyClassifier >>> DummyClassifier.get_class_tag("capability:multivariate") True
- classmethod get_class_tags()[source]¶
Get class tags from estimator class and all its parent classes.
- Returns:
- collected_tagsdict
Dictionary of tag name and tag value pairs. Collected from
_tagsclass attribute via nested inheritance. These are not overridden by dynamic tags set byset_tagsor class__init__calls.
- get_fitted_params(deep=True)[source]¶
Get fitted parameters.
- State required:
Requires state to be “fitted”.
- Parameters:
- deepbool, default=True
If
True, will return the fitted parameters for this estimator and contained subobjects that are estimators.
- Returns:
- fitted_paramsdict
Fitted parameter names mapped to their values.
- get_params(deep=True)¶
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- get_tag(tag_name, raise_error=True, tag_value_default=None)[source]¶
Get tag value from estimator class.
Includes dynamic and overridden tags.
- Parameters:
- tag_namestr
Name of tag to be retrieved.
- raise_errorbool, default=True
Whether a
ValueErroris raised when the tag is not found.- tag_value_defaultany type, default=None
Default/fallback value if tag is not found and error is not raised.
- Returns:
- tag_value
Value of the
tag_nametag in self. If not found, returns an error ifraise_errorisTrue, otherwise it returnstag_value_default.
- Raises:
- ValueError
if raise_error is
Trueandtag_nameis not inself.get_tags().keys()
Examples
>>> from aeon.classification import DummyClassifier >>> d = DummyClassifier() >>> d.get_tag("capability:multivariate") True
- get_tags()[source]¶
Get tags from estimator.
Includes dynamic and overridden tags.
- Returns:
- collected_tagsdict
Dictionary of tag name and tag value pairs. Collected from
_tagsclass attribute via nested inheritance and then any overridden and new tags from__init__orset_tags.
- reset(keep=None)[source]¶
Reset the object to a clean post-init state.
After a
self.reset()call,selfis equal or similar in value totype(self)(**self.get_params(deep=False)), assuming no other attributes were kept usingkeep.- Detailed behaviour:
- removes any object attributes, except:
hyper-parameters (arguments of
__init__) object attributes containing double-underscores, i.e., the string “__”
runs
__init__with current values of hyperparameters (result ofget_params)- Not affected by the reset are:
object attributes containing double-underscores class and object methods, class attributes any attributes specified in the
keepargument temporary callback context attached by scikit-learn
- Parameters:
- keepNone, str, or list of str, default=None
If
None, all attributes are removed except hyperparameters. Ifstr, only the attribute with this name is kept. Iflistofstr, only the attributes with these names are kept.
- Returns:
- selfobject
Reference to self.
- Raises:
- TypeError
If ‘keep’ is not a string or a list of strings.
- set_fit_request(*, axis: bool | None | str = '$UNCHANGED$') MSTLSeriesTransformer¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
- axisstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
axisparameter infit.
- Returns:
- selfobject
The updated object.
- set_params(**params)¶
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.
- set_tags(**tag_dict)[source]¶
Set dynamic tags to given values.
- Parameters:
- **tag_dictdict
Dictionary of tag name and tag value pairs.
- Returns:
- selfobject
Reference to
self.
- set_transform_request(*, axis: bool | None | str = '$UNCHANGED$') MSTLSeriesTransformer¶
Configure whether metadata should be requested to be passed to the
transformmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
- axisstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
axisparameter intransform.
- Returns:
- selfobject
The updated object.
- transform(X, y=None, axis=1)[source]¶
Transform X and return a transformed version.
- State required:
Requires state to be “fitted”.
- Parameters:
- XInput data
Data to fit transform to, of valid collection type.
- yTarget variable, default=None
Additional data, e.g., labels for transformation
- axisint, default = 1
Axis of time in the input series. If
axis == 0, it is assumed each column is a time series and each row is a time point. i.e. the shape of the data is(n_timepoints, n_channels).axis == 1indicates the time series are in rows, i.e. the shape of the data is(n_channels, n_timepoints)`.``axis is Noneindicates that the axis of X is the same asself.axis.
- Returns:
- transformed version of X with the same axis as passed by the user, if axis
- not None.