{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn import metrics\n",
    "import ch10util\n",
    "from sklearn.dummy import DummyClassifier\n",
    "from IPython.display import HTML\n",
    "import dautil as dl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y_test = np.load('rain_y_test.npy')\n",
    "X_train = np.load('rain_X_train.npy')\n",
    "X_test = np.load('rain_X_test.npy')\n",
    "y_train = np.load('rain_y_train.npy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "stratified = DummyClassifier(random_state=28)\n",
    "frequent = DummyClassifier(strategy='most_frequent',\n",
    "                           random_state=28)\n",
    "prior = DummyClassifier(strategy='prior', random_state=29)\n",
    "uniform = DummyClassifier(strategy='uniform',\n",
    "                          random_state=29)\n",
    "preds = ch10util.rain_preds()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "for clf in [stratified, frequent, prior, uniform]:\n",
    "    clf.fit(X_train, y_train)\n",
    "    preds.append(clf.predict(X_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "accuracies = [metrics.accuracy_score(y_test, p)\n",
    "              for p in preds]\n",
    "precisions = [metrics.precision_score(y_test, p)\n",
    "              for p in preds]\n",
    "recalls = [metrics.recall_score(y_test, p)\n",
    "           for p in preds]\n",
    "f1s = [metrics.f1_score(y_test, p)\n",
    "       for p in preds]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "labels = ch10util.rain_labels()\n",
    "labels.extend(['stratified', 'frequent',\n",
    "               'prior', 'uniform'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "dl.options.mimic_seaborn()\n",
    "context = dl.nb.Context('dummy_clf')\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",
    "ch10util.plot_bars(sp.ax, accuracies, labels, rotate=True)\n",
    "sp.label()\n",
    "\n",
    "ch10util.plot_bars(sp.next_ax(), precisions, labels, rotate=True)\n",
    "sp.label()\n",
    "\n",
    "ch10util.plot_bars(sp.next_ax(), recalls, labels, rotate=True)\n",
    "sp.label()\n",
    "\n",
    "ch10util.plot_bars(sp.next_ax(), f1s, labels, rotate=True)\n",
    "sp.label()\n",
    "sp.fig.text(0, 1, ch10util.classifiers(), fontsize=10)\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
}
