{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n===========\nWEASEL+MUSE\n===========\nWEASEL+MUSE stand for Word ExtrAction for time SEries cLassification plus\nMultivariate Unsupervised Symbols and dErivatives.\nThis example shows how the WEASEL+MUSE algorithm transforms multivariate time\nseries of real numbers into a sequence of frequencies of words.\nIt is implemented as :class:`pyts.multivariate.transformation.WEASELMUSE`.\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_basic_motions\nfrom pyts.multivariate.transformation import WEASELMUSE\nfrom sklearn.preprocessing import LabelEncoder\n\n# Toy dataset\nX_train, _, y_train, _ = load_basic_motions(return_X_y=True)\ny_train = LabelEncoder().fit_transform(y_train)\n\n# WEASEL+MUSE transformation\ntransformer = WEASELMUSE(word_size=2, n_bins=2, window_sizes=[12, 36],\n                         chi2_threshold=15, sparse=False)\nX_weasel = transformer.fit_transform(X_train, y_train)\n\n# Visualize the transformation for the first time series\nplt.figure(figsize=(8, 5))\nvocabulary_length = len(transformer.vocabulary_)\nwidth = 0.3\nplt.bar(np.arange(vocabulary_length) - width / 2, X_weasel[y_train == 0][0],\n        width=width, label='First time series in class 0')\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.xticks(np.arange(vocabulary_length),\n           np.vectorize(transformer.vocabulary_.get)(\n               np.arange(X_weasel[0].size)),\n           fontsize=12, rotation=60, ha='right')\ny_max = np.max(np.concatenate([X_weasel[y_train == 0][0],\n                               X_weasel[y_train == 1][0]]))\nplt.yticks(np.arange(y_max + 1), fontsize=12)\nplt.xlabel(\"Words\", fontsize=16)\nplt.ylabel(\"Frequencies\", fontsize=16)\nplt.title(\"WEASEL+MUSE 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
}