sktime.transformations.panel.segment

class sktime.transformations.panel.segment.IntervalSegmenter(intervals=10)[source]

Bases: sktime.transformations.base._PanelToPanelTransformer

Interval segmentation transformer.

Parameters
  • intervals (int, np.ndarray or list of np.ndarrays with one for each) –

  • of input data. (column) – Intervals to generate. - If int, intervals gives the number of generated intervals. - If ndarray, 2d np.ndarray [n_intervals, 2] with rows giving intervals, the first column giving start points, and the second column giving end points of intervals

fit(X, y=None)[source]

Fit transformer, generating random interval indices.

Parameters
  • X (pandas DataFrame of shape [n_samples, n_features]) – Input data

  • y (pandas Series, shape (n_samples, ..), optional) – Targets for supervised learning.

Returns

self

Return type

an instance of self.

transform(X, y=None)[source]

Transform X, segments time-series in each column into random intervals using interval indices generated during fit.

Parameters

X (nested pandas DataFrame of shape [n_samples, n_features]) – Nested dataframe with time-series in cells.

Returns

Xt – Transformed pandas DataFrame with same number of rows and one column for each generated interval.

Return type

pandas DataFrame

class sktime.transformations.panel.segment.RandomIntervalSegmenter(n_intervals='sqrt', min_length=None, max_length=None, random_state=None)[source]

Bases: sktime.transformations.panel.segment.IntervalSegmenter

Transformer that segments time-series into random intervals with random starting points and lengths. Some intervals may overlap and may be duplicates.

Parameters
  • n_intervals (str, int or float) –

    Number of intervals to generate. - If “log”, log of m is used where m is length of time series. - If “sqrt”, sqrt of m is used. - If “random”, random number of intervals is generated. - If int, n_intervals intervals are generated. - If float, int(n_intervals * m) is used with n_intervals giving the fraction of intervals of the time series length.

    For all arguments relative to the length of the time series, the generated number of intervals is always at least 1.

    Default is “sqrt”.

  • random_state (int, RandomState instance or None, optional (default=None)) – If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

fit(X, y=None)[source]

Fit transformer, generating random interval indices.

Parameters
  • X (pandas DataFrame of shape [n_samples, n_features]) – Input data

  • y (pandas Series, shape (n_samples, ..), optional) – Targets for supervised learning.

Returns

self – This estimator

Return type

RandomIntervalSegmenter

class sktime.transformations.panel.segment.SlidingWindowSegmenter(window_length=5)[source]

Bases: sktime.transformations.base._PanelToPanelTransformer

This class is to transform a univariate series into a multivariate one by extracting sets of subsequences. It does this by firstly padding the time series on either end floor(window_length/2) times. Then it performs a sliding window of size window_length and hop size 1.

e.g. if window_length = 3

S = 1,2,3,4,5, floor(3/2) = 1 so S would be padded as

1,1,2,3,4,5,5

then SlidingWindowSegmenter would extract the following:

(1,1,2),(1,2,3),(2,3,4),(3,4,5),(4,5,5)

the time series is now a multivariate one.

Parameters

window_length (int, length of interval.) –

Returns

df – [n_instances, n_timepoints]

Return type

pandas dataframe of shape

Proposed in the ShapeDTW algorithm.

transform(X, y=None)[source]

Function to perform the transformation on the time series data.

Parameters

X (a pandas dataframe of shape = [n_instances, 1]) – The training input samples.

Returns

dims

Return type

a pandas data frame of shape = [n_instances, n_timepoints]