{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import dautil as dl\n",
    "from sklearn import metrics\n",
    "import numpy as np\n",
    "import ch10util\n",
    "from IPython.display import HTML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "context = dl.nb.Context('matthews_correlation')\n",
    "lr = dl.nb.LatexRenderer(chapter=10, start=14, context=context)\n",
    "lr.render(r'\\text{MCC} = \\frac{ T_p \\times T_n - F_p \\times F_n } {\\sqrt{ (T_p + F_p) ( T_p + F_n ) ( T_n + F_p ) ( T_n + F_n ) } }')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y_test = np.load('rain_y_test.npy')\n",
    "accuracies = [metrics.accuracy_score(y_test, preds)\n",
    "              for preds in ch10util.rain_preds()]\n",
    "precisions = [metrics.precision_score(y_test, preds)\n",
    "              for preds in ch10util.rain_preds()]\n",
    "recalls = [metrics.recall_score(y_test, preds)\n",
    "           for preds in ch10util.rain_preds()]\n",
    "f1s = [metrics.f1_score(y_test, preds)\n",
    "       for preds in ch10util.rain_preds()]\n",
    "mc = [metrics.matthews_corrcoef(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, 2, context)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "sp = dl.plotting.Subplotter(2, 2, context)\n",
    "dl.plotting.plot_text(sp.ax, accuracies, mc,\n",
    "                      ch10util.rain_labels(), add_scatter=True)\n",
    "sp.label()\n",
    "\n",
    "dl.plotting.plot_text(sp.next_ax(), precisions, mc,\n",
    "                      ch10util.rain_labels(), add_scatter=True)\n",
    "sp.label()\n",
    "\n",
    "dl.plotting.plot_text(sp.next_ax(), recalls, mc,\n",
    "                      ch10util.rain_labels(), add_scatter=True)\n",
    "sp.label()\n",
    "\n",
    "dl.plotting.plot_text(sp.next_ax(), f1s, mc,\n",
    "                      ch10util.rain_labels(), add_scatter=True)\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
}
