tslearn.utils.to_time_seriesΒΆ

tslearn.utils.to_time_series(ts, remove_nans=False)[source]ΒΆ

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

Parameters:
ts : array-like

The time series to be transformed.

remove_nans : bool (default: False)

Whether trailing NaNs at the end of the time series should be removed or not

Returns:
numpy.ndarray of shape (sz, d)

The transformed time series.

See also

to_time_series_dataset
Transforms a dataset of time series

Examples

>>> to_time_series([1, 2])
array([[1.],
       [2.]])
>>> to_time_series([1, 2, numpy.nan])
array([[ 1.],
       [ 2.],
       [nan]])
>>> to_time_series([1, 2, numpy.nan], remove_nans=True)
array([[1.],
       [2.]])