.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/approximation/plot_paa.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_approximation_plot_paa.py: ================================= Piecewise Aggregate Approximation ================================= Time series with a high sampling rate can be very noisy. In order to reduce noise, a technique called *Piecewise Aggregate Approximation* was invented, consisting in taking the mean over back-to-back points. This decreases the number of points and reduces noise while preserving the trend of the time series. This example illustrates the transformation. It is implemented as :class:`pyts.approximation.PiecewiseAggregateApproximation`. .. GENERATED FROM PYTHON SOURCE LINES 14-46 .. image-sg:: /auto_examples/approximation/images/sphx_glr_plot_paa_001.png :alt: Piecewise Aggregate Approximation :srcset: /auto_examples/approximation/images/sphx_glr_plot_paa_001.png :class: sphx-glr-single-img .. code-block:: default # Author: Johann Faouzi # License: BSD-3-Clause import numpy as np import matplotlib.pyplot as plt from pyts.approximation import PiecewiseAggregateApproximation # Parameters n_samples, n_timestamps = 100, 48 # Toy dataset rng = np.random.RandomState(41) X = rng.randn(n_samples, n_timestamps) # PAA transformation window_size = 6 paa = PiecewiseAggregateApproximation(window_size=window_size) X_paa = paa.transform(X) # Show the results for the first time series plt.figure(figsize=(6, 4)) plt.plot(X[0], 'o--', ms=4, label='Original') plt.plot(np.arange(window_size // 2, n_timestamps + window_size // 2, window_size), X_paa[0], 'o--', ms=4, label='PAA') plt.vlines(np.arange(0, n_timestamps, window_size) - 0.5, X[0].min(), X[0].max(), color='g', linestyles='--', linewidth=0.5) plt.legend(loc='best', fontsize=10) plt.xlabel('Time', fontsize=12) plt.title('Piecewise Aggregate Approximation', fontsize=16) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.430 seconds) .. _sphx_glr_download_auto_examples_approximation_plot_paa.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_paa.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_paa.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_