.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/approximation/plot_mcb.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_mcb.py: ============================ Multiple Coefficient Binning ============================ Binning continuous data into intervals can be seen as an approximation that reduces noise and captures the trend of a time series. The Multiple Coefficient Binning (MCB) algorithm bins continuous time series into intervals, transforming each time point of all the time series (a sequence of floats) into a sequence of symbols, usually letters. Contrary to SAX which bins each time series independently, MCB bins each time point independently. This example shows how to use this algorithm and illustrates the transformation. It is implemented as :class:`pyts.approximation.MultipleCoefficientBinning`. .. GENERATED FROM PYTHON SOURCE LINES 16-59 .. image-sg:: /auto_examples/approximation/images/sphx_glr_plot_mcb_001.png :alt: Multiple Coefficient Binning :srcset: /auto_examples/approximation/images/sphx_glr_plot_mcb_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 MultipleCoefficientBinning # Parameters n_samples, n_timestamps = 100, 12 # Toy dataset rng = np.random.RandomState(41) X = rng.randn(n_samples, n_timestamps) # MCB transformation n_bins = 3 mcb = MultipleCoefficientBinning(n_bins=n_bins, strategy='quantile') X_mcb = mcb.fit_transform(X) # Show the results for two time series plt.figure(figsize=(6, 4)) plt.plot(X[0], 'o--', ms=4, label='First time series') for x, y, s in zip(range(n_timestamps), X[0], X_mcb[0]): plt.text(x, y, s, ha='center', va='bottom', fontsize=14, color='C0') plt.plot(X[5], 'o--', ms=4, label='Second time series') for x, y, s in zip(range(n_timestamps), X[5], X_mcb[5]): plt.text(x, y, s, ha='center', va='bottom', fontsize=14, color='C1') # Plot the bin edges for i in range(n_bins - 1): plt.hlines(mcb.bin_edges_.T[i], np.arange(n_timestamps) - 0.5, np.arange(n_timestamps) + 0.5, color='g', linestyles='--', linewidth=0.7) plt.vlines(np.arange(n_timestamps + 1) - 0.5, X.min(), X.max(), linestyles='--', linewidth=0.5) plt.legend(loc='best', fontsize=10) plt.xlabel('Time', fontsize=14) plt.title("Multiple Coefficient Binning", fontsize=16) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.450 seconds) .. _sphx_glr_download_auto_examples_approximation_plot_mcb.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_mcb.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mcb.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_