{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n=======================================================\nWord ExtrAction for time SEries cLassification (WEASEL)\n=======================================================\n\nThis example shows how the WEASEL algorithm transforms a time series of\nreal numbers into a sequence of frequencies of words. It is implemented\nas :class:`pyts.transformation.WEASEL`.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\nfrom pyts.datasets import load_gunpoint\nfrom pyts.transformation import WEASEL\n\n# Toy dataset\nX_train, _, y_train, _ = load_gunpoint(return_X_y=True)\n\n# WEASEL transformation\nweasel = WEASEL(word_size=2, n_bins=2, window_sizes=[12, 36], sparse=False)\nX_weasel = weasel.fit_transform(X_train, y_train)\n\n# Visualize the transformation for the first time series\nplt.figure(figsize=(8, 5))\nvocabulary_length = len(weasel.vocabulary_)\nwidth = 0.3\nplt.bar(np.arange(vocabulary_length) - width / 2, X_weasel[y_train == 1][0],\n        width=width, label='First time series in class 1')\nplt.bar(np.arange(vocabulary_length) + width / 2, X_weasel[y_train == 2][0],\n        width=width, label='First time series in class 2')\nplt.xticks(np.arange(vocabulary_length),\n           np.vectorize(weasel.vocabulary_.get)(np.arange(X_weasel[0].size)),\n           fontsize=12, rotation=60)\ny_max = np.max(np.concatenate([X_weasel[y_train == 1][0],\n                               X_weasel[y_train == 2][0]]))\nplt.yticks(np.arange(y_max + 1), fontsize=12)\nplt.xlabel(\"Words\", fontsize=16)\nplt.ylabel(\"Frequencies\", fontsize=16)\nplt.title(\"WEASEL transformation\", fontsize=20)\nplt.legend(loc='best', fontsize=12)\n\nplt.subplots_adjust(bottom=0.27)\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
}