{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn.dummy import DummyRegressor\n",
    "import ch10util\n",
    "from sklearn import metrics\n",
    "import dautil as dl\n",
    "from IPython.display import HTML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y_test = np.load('temp_y_test.npy')\n",
    "X_train = np.load('temp_X_train.npy')\n",
    "X_test = np.load('temp_X_test.npy')\n",
    "y_train = np.load('temp_y_train.npy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "mean = DummyRegressor()\n",
    "median = DummyRegressor(strategy='median')\n",
    "q1 = DummyRegressor(strategy='quantile', quantile=0.25)\n",
    "q3 = DummyRegressor(strategy='quantile', quantile=0.75)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "preds = ch10util.temp_preds()\n",
    "\n",
    "for reg in [mean, median, q1, q3]:\n",
    "    reg.fit(X_train, y_train)\n",
    "    preds.append(reg.predict(X_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "r2s = [metrics.r2_score(p, y_test) for p in preds]\n",
    "mses = [metrics.mean_squared_error(p, y_test)\n",
    "        for p in preds]\n",
    "maes = [metrics.median_absolute_error(p, y_test)\n",
    "        for p in preds]\n",
    "mpes = [dl.stats.mpe(y_test, p) for p in preds]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "labels = ch10util.temp_labels()\n",
    "labels.extend(['mean', 'median', 'q1', 'q3'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "dl.options.mimic_seaborn()\n",
    "context = dl.nb.Context('dummy_reg')\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, r2s, labels)\n",
    "sp.label()\n",
    "\n",
    "ch10util.plot_bars(sp.next_ax(), mses, labels)\n",
    "sp.label()\n",
    "\n",
    "ch10util.plot_bars(sp.next_ax(), maes, labels)\n",
    "sp.label()\n",
    "\n",
    "ch10util.plot_bars(sp.next_ax(), mpes, labels)\n",
    "sp.label()\n",
    "sp.fig.text(0, 1, ch10util.regressors())\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
}
