tslearn.utils.from_sktime_dataset

tslearn.utils.from_sktime_dataset(X)[source]

Transform a sktime-compatible dataset into a tslearn dataset.

Parameters:
X: pandas data-frame

sktime-formatted dataset (cf. link)

Returns:
array, shape=(n_ts, sz, d)

tslearn-formatted dataset

Notes

Conversion from/to sktime format requires pandas to be installed.

Examples

>>> import pandas as pd
>>> sktime_df = pd.DataFrame()
>>> sktime_df["dim_0"] = [pd.Series([1, 2, 3]), pd.Series([4, 5, 6])]
>>> tslearn_arr = from_sktime_dataset(sktime_df)
>>> tslearn_arr.shape
(2, 3, 1)
>>> sktime_df = pd.DataFrame()
>>> sktime_df["dim_0"] = [pd.Series([1, 2, 3]),
...                       pd.Series([4, 5, 6, 7])]
>>> sktime_df["dim_1"] = [pd.Series([8, 9, 10]),
...                       pd.Series([11, 12, 13, 14])]
>>> tslearn_arr = from_sktime_dataset(sktime_df)
>>> tslearn_arr.shape
(2, 4, 2)
>>> sktime_arr = numpy.random.randn(10, 1, 16)
>>> from_sktime_dataset(
...     sktime_arr
... )  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ValueError: X is not a valid input sktime array.