TimeSeriesFeatureSynchronizer#
- class tslearn.preprocessing.TimeSeriesFeatureSynchronizer(reference_feature_index=0)[source]#
Feature synchronizer for time series.
Synchronizes features of each time series of a dataset to deal with:
acquisition at different sampling rates: linear interpolation is performed to match the sampling rate of the reference feature
desynchronized timestamps: linear interpolation is performed to match the temporal grid of the reference feature
- Parameters:
- reference_feature_indexint (default: 0)
The feature that is used as reference for synchronization among each time series.
Examples
>>> data = [ ... [[1, 2], [2, np.nan]], ... [[1, 2], [np.nan, 3]], ... ] >>> TimeSeriesFeatureSynchronizer().fit_transform(data) array([[[ 1., 2.], [ 2., 2.]], [[ 1., 2.], [nan, nan]]]) >>> data = [[[1, 2], [2, 4] , [9, np.nan]]] >>> timestamps = np.array([ ... [np.array(["2025-01-01", "2025-01-02"], dtype='datetime64'), ... np.array(["2025-01-03", "2025-01-07"], dtype='datetime64'), ... np.array(["2025-01-10", "nat"], dtype='datetime64')], ... ]) >>> TimeSeriesFeatureSynchronizer().fit_transform(data, timestamps=timestamps) array([[[1. , 2. ], [2. , 2.4], [9. , 4. ]]])
Methods
fit(X[, y])A dummy method such that it complies to the sklearn requirements.
fit_transform(X[, y])Fit to data, then transform it.
Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
set_output(*[, transform])Set output container.
set_params(**params)Set the parameters of this estimator.
set_transform_request(*[, timestamps])Configure whether metadata should be requested to be passed to the
transformmethod.transform(X[, y, timestamps])Synchronizes features of each time series with the feature of reference through linear interpolation.
- fit(X, y=None)[source]#
A dummy method such that it complies to the sklearn requirements.
- Parameters:
- Xarray-like of shape (n_ts, sz, d)
Time series dataset.
- yIgnored
Not used, for API consistency by convention.
- Returns:
- self
- fit_transform(X, y=None, **transform_params)[source]#
Fit to data, then transform it.
- Parameters:
- Xarray-like of shape (n_ts, sz, d)
Time series dataset to be synchronized feature wise.
- yIgnored
Not used, for API consistency by convention.
- **transform_paramsdict
proxies timestamps transform parameter
- Returns:
- numpy.ndarray
Time series dataset synchronized feature wise.
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- 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.
- set_output(*, transform=None)#
Set output container.
See Introducing the set_output API for an example on how to use the API.
- Parameters:
- transform{“default”, “pandas”, “polars”}, default=None
Configure output of transform and fit_transform.
“default”: Default output format of a transformer
“pandas”: DataFrame output
“polars”: Polars output
None: Transform configuration is unchanged
Added in version 1.4: “polars” option was added.
- Returns:
- selfestimator instance
Estimator instance.
- 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_transform_request(*, timestamps: bool | None | str = '$UNCHANGED$') TimeSeriesFeatureSynchronizer#
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:
- timestampsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
timestampsparameter intransform.
- Returns:
- selfobject
The updated object.
- transform(X, y=None, timestamps=None)[source]#
Synchronizes features of each time series with the feature of reference through linear interpolation. When timestamps are not provided, constant sampling periods are assumed for all features and identical start and stop timestamps are assumed for all features of a given times series. When timestamps are provided, features are synchronized on the temporal grid of the reference feature.
- Parameters:
- Xarray-like of shape (n_ts, sz, d)
Time series dataset to be synchronized feature wise.
- yIgnored
Not used, for API consistency by convention.
- timestampsnp.datetime64 array-like of shape (n_ts, sz, d) or None (default: None)
Acquisition timestamps, same shape as X if not None. When provided, timestamps should be increasing for each feature and should use np.datetime64(‘nat’) for missing values.
- Returns:
- numpy.ndarray
Time series dataset synchronized feature wise.