{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Multiple Coefficient Binning\n\n\nThis example shows how the Multiple Coefficient Binning algorithm\ntransforms a dataset of time series of real numbers into a list of\nsequences of symbols. It is implemented as\n:class:`pyts.approximation.MultipleCoefficientBinning`.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\nfrom pyts.approximation import MultipleCoefficientBinning\n\n# Parameters\nn_samples, n_timestamps = 100, 12\n\n# Toy dataset\nrng = np.random.RandomState(41)\nX = rng.randn(n_samples, n_timestamps)\n\n# MCB transformation\nn_bins = 3\nmcb = MultipleCoefficientBinning(n_bins=n_bins, strategy='quantile')\nX_mcb = mcb.fit_transform(X)\n\n# Show the results for two time series\nplt.figure(figsize=(12, 8))\n\nplt.plot(X[0], 'o--', label='First time series')\nfor x, y, s in zip(range(n_timestamps), X[0], X_mcb[0]):\n    plt.text(x, y, s, ha='center', va='bottom', fontsize=20, color='C0')\n\nplt.plot(X[5], 'o--', label='Second time series')\nfor x, y, s in zip(range(n_timestamps), X[5], X_mcb[5]):\n    plt.text(x, y, s, ha='center', va='bottom', fontsize=20, color='C1')\n\nplt.hlines(mcb.bin_edges_.T, np.arange(n_timestamps) - 0.5,\n           np.arange(n_timestamps) + 0.5, color='g',\n           linestyles='--', linewidth=0.7)\nplt.vlines(np.arange(n_timestamps + 1) - 0.5, X.min(), X.max(),\n           linestyles='--', linewidth=0.5)\n\nplt.legend(loc='best', fontsize=14)\nplt.title(\"Multiple Coefficient Binning\", fontsize=18)\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
}