mvtsa.Segmentation#

class mvtsa.Segmentation(change_points, n_samples, labels=None, memberships=None, scores=None, cost=None, meta=<factory>)[source]#

Bases: object

A segmentation of one series.

Parameters:
change_pointsarray of int

Sorted start indices of the 2nd, 3rd, … segment (0 < t < T).

n_samplesint

Length T of the segmented series.

labelsarray of int, optional

State (regime) label of each segment; segments with the same label belong to the same state.

membershipsarray (T, c), optional

Fuzzy memberships of the samples in the segments (fuzzy segmentation).

scoresarray, optional

Method-specific score of each change point (e.g. merge cost, change probability, classification score).

costfloat, optional

Total cost of the segmentation (cost-based methods).

metadict

Method name, parameters and other diagnostics.

Examples

>>> s = Segmentation([3, 7], 10)
>>> s.segments
[(0, 3), (3, 7), (7, 10)]
>>> s.to_labels().tolist()
[0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
property bounds#

[0, t_1, ..., t_{c-1}, T].

classmethod from_labels(labels, **kwargs)[source]#

Build a segmentation from a per-sample label sequence.

Every run of equal labels becomes a segment; the run labels become the state labels.

>>> Segmentation.from_labels([0, 0, 1, 1, 0]).labels.tolist()
[0, 1, 0]
property segments#

List of half-open (start, stop) index ranges.

shift(offset, n_samples=None)[source]#

Change points moved by offset (used when a method works on a lagged or trimmed copy of the series).

to_frame(X=None, names=None)[source]#

One row per segment: start, stop, length, state and (if X is given) the mean of every variable.

to_labels(states=False)[source]#

Label of every sample: its segment index, or its state if states.

to_ruptures()[source]#

Breakpoints in the ruptures convention (the end T included).

with_labels(labels)[source]#

Copy with state labels attached.

Examples using mvtsa.Segmentation#

Clustering segments: recurring patterns across series

Clustering segments: recurring patterns across series