.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/preprocessing/plot_imputer.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_imputer.py: ======= Imputer ======= Missing values are common in real-word datasets and most algorithms cannot deal with them. Thus it is standard to impute them. For time series, the imputation is based on interpolation from other time points in order to preserve temporal correlation between consecutive time points. Different strategies for interpolation are made available. This example illustrates these different strategies. It is implemented as :class:`pyts.preprocessing.InterpolationImputer`. .. GENERATED FROM PYTHON SOURCE LINES 14-48 .. image-sg:: /auto_examples/preprocessing/images/sphx_glr_plot_imputer_001.png :alt: Interpolating missing values with different strategies, Linear Interpolation, Quadratic Interpolation, Cubic Interpolation, Nearest Interpolation :srcset: /auto_examples/preprocessing/images/sphx_glr_plot_imputer_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 InterpolationImputer # Parameters n_samples, n_timestamps = 100, 48 # Toy dataset rng = np.random.RandomState(41) X = rng.randn(n_samples, n_timestamps) missing_idx = rng.choice(np.arange(1, 47), size=14, replace=False) X[:, missing_idx] = np.nan # Show the results for different strategies for the first time series plt.figure(figsize=(16, 10)) for i, strategy in enumerate(['linear', 'quadratic', 'cubic', 'nearest']): imputer = InterpolationImputer(strategy=strategy) X_imputed = imputer.transform(X) plt.subplot(2, 2, i + 1) plt.plot(X_imputed[0], 'o--', color='C1', label='Imputed') plt.plot(X[0], 'o--', color='C0', label='Original') plt.title("{0} Interpolation".format(strategy.capitalize()), fontsize=16) plt.legend(loc='best', fontsize=14) plt.suptitle('Interpolating missing values with different strategies', fontsize=20) plt.tight_layout() plt.subplots_adjust(top=0.9) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.696 seconds) .. _sphx_glr_download_auto_examples_preprocessing_plot_imputer.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_imputer.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_imputer.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_