{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# BiPLS - Basic example\n\nAn Backward interval Partial Least Squares example showing the spectral intervals optimized by\nthe BiPLS method.\n\nThe example uses a synthetic dataset with 50 standard normally distributed features.\nThe target values only depend on four features: #21 and #24 and #46 and #47.\nIf the BiPLS method is tasked with selecting two intervals of width 5, it identifies two intervals containing the above\nenumerated features.\n\nThe BiPLS method stores the order of removed intervals in the ``rank_`` attribute, i.e. the interval with the lowest\nrelative rank has been removed first, the interval with the second-lowest relative rank has been removed second, and so\non.\nThe finally selected intervals have a relative rank of 1.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom auswahl import BiPLS\n\nnp.random.seed(1337)\nX = np.random.randn(100, 50)\ny = 5 * X[:, 21] - 2 * X[:, 24] + 3 * X[:, 46] + X[:, 47]\n\ninterval_width = 5\nbipls = BiPLS(n_intervals_to_select=2, interval_width=5)\nbipls.fit(X, y)\n\nplt.step(range(len(bipls.rank_)), bipls.rank_, where='post', zorder=3)\nplt.axhline(1, color='C01', zorder=2)\n\nplt.grid()\nplt.xlabel('Feature')\nplt.ylabel('Relative Rank')\n\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.8.13"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}