{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Imputer\n\n\nThis example shows how one can impute missing values using\n:class:`pyts.preprocessing.InterpolationImputer`.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\nfrom pyts.preprocessing import InterpolationImputer\n\n# Parameters\nn_samples, n_timestamps = 100, 48\n\n# Toy dataset\nrng = np.random.RandomState(41)\nX = rng.randn(n_samples, n_timestamps)\nmissing_idx = rng.choice(np.arange(1, 47), size=14, replace=False)\nX[:, missing_idx] = np.nan\n\n# Show the results for different strategies for the first time series\nplt.figure(figsize=(16, 10))\nfor i, strategy in enumerate(['linear', 'quadratic', 'cubic', 'nearest']):\n    imputer = InterpolationImputer(strategy=strategy)\n    X_imputed = imputer.transform(X)\n\n    plt.subplot(2, 2, i + 1)\n    plt.plot(X_imputed[0], 'o--', color='C1', label='Imputed')\n    plt.plot(X[0], 'o--', color='C0', label='Original')\n    plt.title(\"{0} Interpolation\".format(strategy.capitalize()), fontsize=16)\n    plt.legend(loc='best', fontsize=14)\n\nplt.suptitle('Interpolating missing values with different strategies',\n             fontsize=20)\nplt.tight_layout()\nplt.subplots_adjust(top=0.9)\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}