{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn import metrics\n",
    "import numpy as np\n",
    "import ch10util\n",
    "import dautil as dl\n",
    "from IPython.display import HTML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "context= dl.nb.Context('roc_auc')\n",
    "lr = dl.nb.LatexRenderer(chapter=10, start=5, context=context)\n",
    "lr.render(r'\\text{FPR}=\\frac{F_p}{F_p+T_n}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y_test = np.load('rain_y_test.npy')\n",
    "roc_aucs = [metrics.roc_auc_score(y_test, preds)\n",
    "            for preds in ch10util.rain_preds()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "dl.options.mimic_seaborn()\n",
    "dl.nb.RcWidget(context)\n",
    "dl.nb.LabelWidget(2, 1, context)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "sp = dl.plotting.Subplotter(2, 1, context)\n",
    "ch10util.plot_bars(sp.ax, roc_aucs)\n",
    "sp.label()\n",
    "\n",
    "cp = dl.plotting.CyclePlotter(sp.next_ax())\n",
    "\n",
    "for preds, label in zip(ch10util.rain_preds(),\n",
    "                        ch10util.rain_labels()):\n",
    "    fpr, tpr, _ = metrics.roc_curve(y_test, preds,\n",
    "                                    pos_label=True)\n",
    "    cp.plot(fpr, tpr, label=label)\n",
    "    \n",
    "fpr, tpr, _ = metrics.roc_curve(y_test, y_test)\n",
    "sp.ax.plot(fpr, tpr, 'k', lw=4, label='Ideal')\n",
    "sp.ax.plot(np.linspace(0, 1), np.linspace(0, 1), \n",
    "           '--', label='Baseline')\n",
    "sp.label()\n",
    "sp.fig.text(0, 1, ch10util.classifiers())\n",
    "HTML(sp.exit())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "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.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
