.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/11_applications/plot_03_regime_explanation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_11_applications_plot_03_regime_explanation.py: Explaining operating regimes ============================ Once the regimes of a process are found, the operators need to know what they mean. A shallow decision tree turns the state labels into readable rules on the process variables; the regime transition network shows how the process moves between them; the boundary contributions tell which variables changed at every switch. .. GENERATED FROM PYTHON SOURCE LINES 11-30 .. code-block:: Python import matplotlib.pyplot as plt import mvtsa as mv from mvtsa import segmentation as sg from mvtsa.explain import ( boundary_contributions, explain_states, transition_graph, ) X, cps, states = mv.datasets.make_regime_process( n_regimes=3, n_segments=12, length=120, random_state=6 ) names = ["temperature", "pressure", "flow", "level"] seg = sg.GaussianHMMSegmenter(n_states=3, sticky=10, min_duration=15).segment( X ) .. GENERATED FROM PYTHON SOURCE LINES 31-33 Rules ----- .. GENERATED FROM PYTHON SOURCE LINES 33-37 .. code-block:: Python ex = explain_states(X, seg, names=names, max_depth=2) print(f"training accuracy of the rules: {ex['accuracy']:.3f}") print(ex["rules"]) print(ex["importances"].round(3)) .. rst-class:: sphx-glr-script-out .. code-block:: none training accuracy of the rules: 0.984 |--- temperature <= -2.05 | |--- flow <= -1.48 | | |--- class: 2 | |--- flow > -1.48 | | |--- class: 2 |--- temperature > -2.05 | |--- level <= -1.12 | | |--- class: 0 | |--- level > -1.12 | | |--- class: 1 level 0.516 temperature 0.482 flow 0.002 pressure 0.000 dtype: float64 .. GENERATED FROM PYTHON SOURCE LINES 38-40 Transitions and their causes ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 40-52 .. code-block:: Python G = transition_graph(seg) for a, b in G.edges: print( f"{a} -> {b}: {G.edges[a, b]['count']} times, p = {G.edges[a, b]['probability']:.2f}" ) print(boundary_contributions(X, seg, kind="all", names=names).round(2).head()) fig, axes = plt.subplots( 1, 2, figsize=(9, 3.6), gridspec_kw={"width_ratios": [2, 1]} ) mv.viz.plot_segmentation(X, seg, truth=cps, ax=axes[0]) mv.viz.plot_transition_graph(G, ax=axes[1]) plt.show() .. image-sg:: /auto_examples/11_applications/images/sphx_glr_plot_03_regime_explanation_001.png :alt: plot 03 regime explanation :srcset: /auto_examples/11_applications/images/sphx_glr_plot_03_regime_explanation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 0 -> 2: 2 times, p = 0.50 0 -> 1: 2 times, p = 0.50 2 -> 1: 2 times, p = 0.67 2 -> 0: 1 times, p = 0.33 1 -> 2: 2 times, p = 0.50 1 -> 0: 2 times, p = 0.50 temperature pressure flow level change_point 125 0.37 0.13 0.16 0.34 229 0.26 0.18 0.23 0.33 337 0.24 0.21 0.20 0.35 444 0.35 0.15 0.17 0.33 611 0.12 0.17 0.23 0.47 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.150 seconds) .. _sphx_glr_download_auto_examples_11_applications_plot_03_regime_explanation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/mvtsa/main?urlpath=lab/tree/notebooks/auto_examples/11_applications/plot_03_regime_explanation.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_regime_explanation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_regime_explanation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_regime_explanation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_