to_time_series_dataset#

tslearn.utils.to_time_series_dataset(dataset, dtype=<class 'float'>, be=None)[source]#

Transforms a time series dataset so that it fits the format used in tslearn models.

Parameters:
datasetarray-like, shape=(n_ts, sz, d) or (n_ts, sz) or (sz,)

The dataset of time series to be transformed. A single time series will be automatically wrapped into a dataset with a single entry.

dtypedata type (default: float)

Data type for the returned dataset, depending on the backend.

beBackend object or string or None

Backend. If be is an instance of the class NumPyBackend or the string “numpy”, the NumPy backend is used. If be is an instance of the class PyTorchBackend or the string “pytorch”, the PyTorch backend is used. If be is None, the backend is determined by the input arrays. See our dedicated user-guide page for more information.

Returns:
dataset_outarray-like, shape=(n_ts, sz, d)

The transformed dataset of time series.

See also

to_time_series

Transforms a single time series

Examples

>>> to_time_series_dataset([[1, 2]])
array([[[1.],
        [2.]]])
>>> to_time_series_dataset([1, 2])
array([[[1.],
        [2.]]])
>>> to_time_series_dataset([[1, 2], [1, 4, 3]])
array([[[ 1.],
        [ 2.],
        [nan]],

       [[ 1.],
        [ 4.],
        [ 3.]]])
>>> to_time_series_dataset([]).shape
(0, 0, 0)