{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 1: Introduction\n",
    "\n",
    "> (c) 2019 Galit Shmueli, Peter C. Bruce, Peter Gedeck \n",
    ">\n",
    "> Code included in\n",
    ">\n",
    "> _Data Mining for Business Analytics: Concepts, Techniques, and Applications in Python_ (First Edition) \n",
    "> Galit Shmueli, Peter C. Bruce, Peter Gedeck, and Nitin R. Patel. 2019."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-05-27T20:01:19.171500Z",
     "iopub.status.busy": "2021-05-27T20:01:19.170973Z",
     "iopub.status.idle": "2021-05-27T20:01:20.906972Z",
     "shell.execute_reply": "2021-05-27T20:01:20.906461Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "no display found. Using non-interactive Agg backend\n"
     ]
    }
   ],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "from pathlib import Path\n",
    "import pandas as pd\n",
    "import matplotlib.pylab as plt\n",
    "import dmba\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Figure 1.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-05-27T20:01:20.910292Z",
     "iopub.status.busy": "2021-05-27T20:01:20.909286Z",
     "iopub.status.idle": "2021-05-27T20:01:20.923653Z",
     "shell.execute_reply": "2021-05-27T20:01:20.923157Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Income</th>\n",
       "      <th>Lot_Size</th>\n",
       "      <th>Ownership</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>60.0</td>\n",
       "      <td>18.4</td>\n",
       "      <td>Owner</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>85.5</td>\n",
       "      <td>16.8</td>\n",
       "      <td>Owner</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>64.8</td>\n",
       "      <td>21.6</td>\n",
       "      <td>Owner</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>61.5</td>\n",
       "      <td>20.8</td>\n",
       "      <td>Owner</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>87.0</td>\n",
       "      <td>23.6</td>\n",
       "      <td>Owner</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Income  Lot_Size Ownership\n",
       "0    60.0      18.4     Owner\n",
       "1    85.5      16.8     Owner\n",
       "2    64.8      21.6     Owner\n",
       "3    61.5      20.8     Owner\n",
       "4    87.0      23.6     Owner"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mower_df = dmba.load_data('RidingMowers.csv')\n",
    "mower_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-05-27T20:01:20.940466Z",
     "iopub.status.busy": "2021-05-27T20:01:20.937278Z",
     "iopub.status.idle": "2021-05-27T20:01:21.183580Z",
     "shell.execute_reply": "2021-05-27T20:01:21.183035Z"
    }
   },
   "outputs": [],
   "source": [
    "def basePlot(ax):\n",
    "    mower_df.loc[mower_df.Ownership=='Owner'].plot(x='Income', y='Lot_Size', style='o', \n",
    "                                                   markerfacecolor='C0', markeredgecolor='C0',\n",
    "                                                   ax=ax)\n",
    "    mower_df.loc[mower_df.Ownership=='Nonowner'].plot(x='Income', y='Lot_Size', style='o',\n",
    "                                                      markerfacecolor='none', markeredgecolor='C1',\n",
    "                                                      ax=ax)\n",
    "    ax.legend([\"Owner\", \"Nonowner\"]);\n",
    "    ax.set_xlim(20, 120)\n",
    "    ax.set_ylim(13, 25)\n",
    "    ax.set_xlabel('Income ($000s)')\n",
    "    ax.set_ylabel('Lot Size (000s sqft)')\n",
    "    return ax\n",
    "\n",
    "fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(9, 3))\n",
    "\n",
    "ax = basePlot(axes[0])\n",
    "y0, y1, y2 = 21.3, 19.8, 16.4\n",
    "x0, x1, x2 = 55, 58, 95\n",
    "ax.plot((20, x0), (y0,y0), color='grey')\n",
    "ax.plot((20, 120), (y1,y1), color='grey')\n",
    "ax.plot((x1, x2), (y2,y2), color='grey')\n",
    "ax.plot((x0, x0), (25,y1), color='grey')\n",
    "ax.plot((x1, x1), (y1,13), color='grey')\n",
    "ax.plot((x2, x2), (y1,13), color='grey')\n",
    "\n",
    "ax = basePlot(axes[1])\n",
    "ax.plot((40, 95), (25,13), color='grey')\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.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.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
