.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_latent_segmentation/plot_06_energy_regression.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_03_latent_segmentation_plot_06_energy_regression.py: Operating ranges of an energy indicator ======================================= Abonyi, Kulcsár, Balaton and Nagy (2013) segment energy monitoring data so that within every segment the key energy indicator depends linearly on the operating variables. The cost of a segment is the residual of a regression of the target column on the others (:class:`~mvtsa.segmentation.CostRegression`); a change of the coefficients -- a different operating regime -- is a change point even when every variable moves smoothly. .. GENERATED FROM PYTHON SOURCE LINES 12-25 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import pandas as pd import mvtsa as mv from mvtsa import segmentation as sg from mvtsa.evaluation import evaluate_segmentation X, cps, _ = mv.datasets.make_energy_process( n_segments=4, length=250, random_state=0 ) .. GENERATED FROM PYTHON SOURCE LINES 26-28 Regression cost versus a mean/covariance cost --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 28-44 .. code-block:: Python reg = sg.BottomUp( sg.CostRegression(targets=[0]), n_segments=4, initial_size=20 ).segment(X) gauss = sg.BottomUp("normal", n_segments=4, initial_size=20).segment(X) print( pd.DataFrame( [ {"cost": n, **evaluate_segmentation(cps, s, len(X), margin=25)} for n, s in [("regression", reg), ("Gaussian", gauss)] ] )[["cost", "f1", "covering"]] ) mv.viz.plot_segmentation( X, reg, truth=cps, names=["energy indicator", "load", "feed temperature"] ) .. image-sg:: /auto_examples/03_latent_segmentation/images/sphx_glr_plot_06_energy_regression_001.png :alt: plot 06 energy regression :srcset: /auto_examples/03_latent_segmentation/images/sphx_glr_plot_06_energy_regression_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none cost f1 covering 0 regression 1.0 0.972438 1 Gaussian 1.0 0.972438 .. GENERATED FROM PYTHON SOURCE LINES 45-47 The local models ---------------- .. GENERATED FROM PYTHON SOURCE LINES 47-54 .. code-block:: Python for a, b in reg.segments: A = np.c_[np.ones(b - a), X[a:b, 1:]] coef = np.linalg.lstsq(A, X[a:b, 0], rcond=None)[0] print( f"[{a:4d},{b:4d}) KEI = {coef[0]:6.2f} {coef[1]:+.3f}*load {coef[2]:+.3f}*feed" ) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none [ 0, 320) KEI = 16.48 -0.204*load -0.056*feed [ 320, 580) KEI = 18.07 -0.179*load -0.096*feed [ 580, 780) KEI = 10.64 -0.192*load -0.012*feed [ 780, 999) KEI = 31.45 -0.145*load -0.836*feed .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.048 seconds) .. _sphx_glr_download_auto_examples_03_latent_segmentation_plot_06_energy_regression.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/03_latent_segmentation/plot_06_energy_regression.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_06_energy_regression.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_06_energy_regression.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_06_energy_regression.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_