.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/preprocessing/plot_scalers.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_preprocessing_plot_scalers.py: ======= Scalers ======= Scaling data is a usual requirement for many algorithms and allows to have identical scales for time series with originally different scales. For time series, scaling is performed sample-wise instead of feature-wise. This example illustrates several scaling algorithms made available in :mod:`pyts.preprocessing`. .. GENERATED FROM PYTHON SOURCE LINES 12-56 .. image-sg:: /auto_examples/preprocessing/images/sphx_glr_plot_scalers_001.png :alt: Scaling time series with different strategies, Original time series, Scaled time series :srcset: /auto_examples/preprocessing/images/sphx_glr_plot_scalers_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.preprocessing import (StandardScaler, MinMaxScaler, MaxAbsScaler, RobustScaler) # Parameters n_samples, n_timestamps = 100, 48 marker_size = 5 # Toy dataset rng = np.random.RandomState(41) X = rng.randn(n_samples, n_timestamps) # Scale the data with different scaling algorithms X_standard = StandardScaler().transform(X) X_minmax = MinMaxScaler(sample_range=(0, 1)).transform(X) X_maxabs = MaxAbsScaler().transform(X) X_robust = RobustScaler(quantile_range=(25.0, 75.0)).transform(X) # Show the results for the first time series plt.figure(figsize=(16, 6)) ax1 = plt.subplot(121) ax1.plot(X[0], 'o-', ms=marker_size, label='Original') ax1.set_title('Original time series', fontsize=16) ax1.legend(loc='best', fontsize=12) ax2 = plt.subplot(122) ax2.plot(X_standard[0], 'o--', ms=marker_size, color='C1', label='StandardScaler') ax2.plot(X_minmax[0], 'o--', ms=marker_size, color='C2', label='MinMaxScaler') ax2.plot(X_maxabs[0], 'o--', ms=marker_size, color='C3', label='MaxAbsScaler') ax2.plot(X_robust[0], 'o--', ms=marker_size, color='C4', label='RobustScaler') ax2.set_title('Scaled time series', fontsize=16) ax2.legend(loc='best', fontsize=12) plt.suptitle('Scaling time series with different strategies', fontsize=20) plt.tight_layout() plt.subplots_adjust(top=0.85) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.423 seconds) .. _sphx_glr_download_auto_examples_preprocessing_plot_scalers.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_scalers.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_scalers.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_