{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Imbalanced multiclass classification with FROVOCO\n\nThe figures contain the training instances within a section of the selected feature space.\nThe training instances are coloured according to their true labels,\nwhile the feature space is coloured according to predictions on the basis of the training instances,\nmaking the decision boundaries visible.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "print(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.colors import ListedColormap\nfrom sklearn import datasets\n\nfrom frlearn.base import select_class\nfrom frlearn.classifiers import FROVOCO\n\n# Import example data, reduce to 2 dimensions, and create imbalanced selection.\niris = datasets.load_iris()\nX = iris.data[:, :2]\ny = iris.target\nX = np.concatenate([X[:5], X[50:67], X[100:]], axis=0)\ny = np.concatenate([y[:5], y[50:67], y[100:]], axis=0)\n\n# Define color maps.\ncmap_light = ListedColormap(['#FFAAAA', '#AAFFAA', '#AAAAFF'])\ncmap_bold = ListedColormap(['#FF0000', '#00FF00', '#0000FF'])\n\n# Create an instance of the FROVOCO classifier and construct the model.\nclf = FROVOCO()\nmodel = clf(X, y)\n\n# Create a mesh of points in the attribute space.\nstep_size = .02\nx_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1\ny_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1\nxx, yy = np.meshgrid(np.arange(x_min, x_max, step_size), np.arange(y_min, y_max, step_size))\n\n# Query mesh points to obtain class values and select highest valued class.\nZ = model(np.c_[xx.ravel(), yy.ravel()])\nZ = select_class(Z, labels=model.classes)\n\n# Initialise figure.\nplt.figure()\n\n# Plot mesh.\nZ = Z.reshape(xx.shape)\nplt.pcolormesh(xx, yy, Z, cmap=cmap_light)\n\n# Plot training instances.\nplt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold,\n            edgecolor='k', s=20)\n\n# Set plot dimensions.\nplt.xlim(xx.min(), xx.max())\nplt.ylim(yy.min(), yy.max())\n\nplt.title('FROVOCO applied to an imbalanced selection of iris dataset')\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.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}