A one-page segmentation report#

A segmentation is only useful if it can be explained. The dashboard combines the segmented series, the timeline of states, the cost curve of the merge hierarchy and the contributions of the variables to every change (shifts of the mean, the variance and the correlation). The segment table summarizes every segment by its statistics and principal directions.

import matplotlib.pyplot as plt

import mvtsa as mv
from mvtsa import segmentation as sg
from mvtsa.explain import boundary_contributions, describe_segments

X, cps, states = mv.datasets.make_regime_process(
    n_regimes=3, n_segments=6, length=150, random_state=4
)
names = ["temperature", "pressure", "flow", "level"]

The dashboard#

st = sg.StateSegmenter(
    segmenter=sg.BottomUp("normal", n_segments=6, initial_size=15), n_states=3
)
seg = st.segment(X)
tree = sg.BottomUp("normal", initial_size=15).full_tree(X)
mv.viz.segmentation_dashboard(X, seg, names=names, truth=cps, tree=tree)
plot 01 dashboard
<Figure size 900x640 with 5 Axes>

Which variables changed?#

print(boundary_contributions(X, seg, kind="all", names=names).round(2))
print(describe_segments(X, seg, names=names).round(2).iloc[:, :8])
plt.show()
              temperature  pressure  flow  level
change_point
195                  0.21      0.17  0.37   0.26
330                  0.41      0.32  0.10   0.17
525                  0.18      0.22  0.32   0.28
630                  0.20      0.16  0.36   0.28
780                  0.35      0.27  0.11   0.27
   segment  start  ...  std_temperature  slope_temperature
0        0      0  ...             0.81              -0.00
1        1    195  ...             0.64               0.00
2        2    330  ...             1.09              -0.00
3        3    525  ...             0.92              -0.01
4        4    630  ...             0.70               0.00
5        5    780  ...             0.92               0.00

[6 rows x 8 columns]

Total running time of the script: (0 minutes 0.152 seconds)

Gallery generated by Sphinx-Gallery