Lessons in the Research-to-Production Pipeline: From Data Science to Software Engineering
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

589 lines
110 KiB

{
"cells": [
{
"cell_type": "markdown",
"id": "cf3750f4-b08d-4931-b2a0-81bc02a3356f",
"metadata": {},
"source": [
"# Room-Occupancy Classification"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "humanitarian-burke",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "dedicated-employee",
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('../datatest.csv')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "quality-peoples",
"metadata": {},
"outputs": [],
"source": [
"signal = df['HumidityRatio'].values[:-2000]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "matched-current",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"Int64Index: 2665 entries, 140 to 2804\n",
"Data columns (total 7 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 date 2665 non-null object \n",
" 1 Temperature 2665 non-null float64\n",
" 2 Humidity 2665 non-null float64\n",
" 3 Light 2665 non-null float64\n",
" 4 CO2 2665 non-null float64\n",
" 5 HumidityRatio 2665 non-null float64\n",
" 6 Occupancy 2665 non-null int64 \n",
"dtypes: float64(5), int64(1), object(1)\n",
"memory usage: 166.6+ KB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "virgin-taylor",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACX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RNDrxb1xI4GGBuo//ZSiX53NzrvujrdaA5K0iy6MSi7j+q6pA2c/SPPdhz+MYddKmG1nn0Px9TcQ9Hioe/sdPBs3Ir3eLpl7bzBmZ5Nz371Yxo7t8bkHIlLKyPtc/sif2oxDD3eOCucG5D78UPMzdLeKrVAulxC+khK2nTqHvL/+hUA4Dj0QiK9SijYRQoCu69Yi4Q/qkBf/hwwGIyFouwUCEAgQiMOqvDkyGER6vdqdQg/H6g9E/Lt2sfnoYyLPg97dceiZt9yMecRI7AcdSMZ112n7bmgG3jRsCEJXHgeN1Qpd0YsY9cNiEo87Fud333coZ50yBfuhh+Jeuyam+YwFBQCRcr06m621Me9FeDZtYsOU/XEs3Jc0dEVXkn7ppSQcfhjCZMKYlxcp3Obdvp2EQw7CnBSfxaAy6Ipeg/R4cHz+Bd6tWzuV9axfj680tigXndWKsFgizQmqnn5ai0PvpMGGQuHdvp1t55xDzauvUjh2HNsvuRQA14qVOL75Lm56KZeLotfQPM26I7zFxfgrK/FsjK1jUaChAel24yvRyug2fDZPOx5F4S3RhS4fRd9j62mnI10uTIO0ZvfhpihNS5fiLyvD69Bjsikfeq/AkJWFPjODgr/9Ld6qKNogUFMDaI0oYsFfocW
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots()\n",
"ax.plot(df['Humidity']/100)\n",
"light = df['Light']/np.max(df['Light'])\n",
"ax.plot(light)\n",
"ax.plot(df['Temperature']/80)\n",
"# ax.plot(df['HumidityRatio']*40)\n",
"ax.plot(df['Occupancy'], ls='--')\n",
"plt.show(fig)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "coordinated-celebrity",
"metadata": {},
"outputs": [],
"source": [
"occupancy = df.Occupancy.values\n",
"humidity = df.Humidity.values\n",
"light = df.Light.values"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "chicken-teacher",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([0.45353836, 0.07583515, 0.19437358, 0.28346148, 0.08540657,\n",
" 0.04564834, 0.03092307, 0.03534065, 0.02282417, 0.01914285]),\n",
" array([22.1 , 22.90225, 23.7045 , 24.50675, 25.309 , 26.11125,\n",
" 26.9135 , 27.71575, 28.518 , 29.32025, 30.1225 ]),\n",
" <BarContainer object of 10 artists>)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAANfUlEQVR4nO3df6zdd13H8efL2w2NiCC9E2iLrViyNGRuy6XyB4ZAxLRzoSNq3CAyRdIUM3Qk01VJSJR/KBh/QKZNI4uYkDQzDGxcyQAVleBG79gPKFuhqcPedbjLUOeCUjre/nG+w+Pdufee295zzr2fPR/Jyf1+P99Pz/d9Pjl77XO+5/v9nlQVkqT17/smXYAkaXUY6JLUCANdkhphoEtSIwx0SWrEhknteOPGjbV169ZJ7V6S1qV77rnnG1U1PWjbxAJ969atzM7OTmr3krQuJfnaYts85CJJjTDQJakRBrokNcJAl6RGGOiS1AgDXZIaYaBLUiMMdElqhIEuSY2Y2JWiF+TMvePZz0uuGM9+JGkVOEOXpEYY6JLUCANdkhphoEtSIwx0SWqEgS5JjTDQJakRBrokNcJAl6RGGOiS1AgDXZIaYaBLUiMMdElqhIEuSY0w0CWpEQa6JDXCQJekRhjoktQIA12SGmGgS1Ijhgr0JLuSnEhyMsn+Jfq9MslTSX5h9UqUJA1j2UBPMgXcAuwGdgDXJdmxSL8DwJ2rXaQkaXnDzNB3Aier6lRVnQUOA3sG9HsH8FHgsVWsT5I0pGECfRNwum99rmv7niSbgDcCB5d6oiR7k8wmmZ2fn19prZKkJQwT6BnQVgvW/x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ff5I3AI9U1f2
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.hist(humidity[occupancy == 1], density=True)\n",
"plt.hist(humidity[occupancy == 0], alpha=0.2, density=True)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "disturbed-bandwidth",
"metadata": {},
"outputs": [],
"source": [
"from scipy.stats import gaussian_kde as kde"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "known-prairie",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAEICAYAAABRSj9aAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAA5hklEQVR4nO2de5gU5ZX/P2cGECIKqKgowpBomIEZEBzxumIwgq4kblTiJeEnI8aw8UpiEndJQJL4+yXGDd5IfNiQIZK4CkSzXldkSdaoEAEvDOyA4TGAE1AQBcSAMDPn90dVz/T0dFdVT1f19Xyep5+ZrnrrrdM1Pd9667znPUdUFcMwDKN4Kcu1AYZhGEa0mNAbhmEUOSb0hmEYRY4JvWEYRpFjQm8YhlHkmNAbhmEUOSb0JYyIPCQi3w+pr0Eisk9Eyt33fxSR68Po2+3vORG5Nqz+0jjvj0TkfRF5N83jAl9bEVkgIj/qmoUgIlNE5KWuHp+v5zLCw4S+SBGRzSKyX0Q+EpHdIvKKiEwTkba/uapOU9UfBuzr815tVHWrqvZW1ZYQbL9TRH6T0P/FqvrrTPtO046TgG8Bw1T1+CT7zxeRpmTHBr22Ae1QETk5jL4Cnm+CiLzofnd2isj/iMgXs3V+I3xM6IubL6jqEcBg4MfAd4H5YZ9ERLqF3WeeMBjYpao7cm1IthCRK4DFwMPAQOA4YCbwhVzaZWSGCX0JoKp7VPVJ4ErgWhGpho4uAxE5RkSedkf/H4jIn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XJsMoQd79+N20tgchmUtERAKHIXbr1o3W1ta294krfBP7SXz
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"n = len(df) // 2\n",
"i = np.arange(len(df))\n",
"np.random.shuffle(i)\n",
"i = i[:n]\n",
"h = humidity[i]\n",
"o = occupancy[i]\n",
"k1 = kde(h[o == 1])\n",
"k0 = kde(h[o == 0])\n",
"plt.scatter(humidity, k1.pdf(humidity))\n",
"plt.scatter(humidity, k0.pdf(humidity))\n",
"plt.scatter(humidity, k1.pdf(humidity), label=\"occupied\")\n",
"plt.scatter(humidity, k0.pdf(humidity), label=\"unoccupied\")\n",
"plt.title(\"Distribution of Light by Class\")\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "annual-physics",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEICAYAAABI7RO5AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAq2klEQVR4nO3dfZxVZb3//9fb4TZvQAVNBQSLNARBGPE28fszBdRErbw5Wt7UMX6lHo/VEY6FWPrNk+VR0uRYmlreQP6UKPWYZmV5kwyCKCmKSjJAgBigcj98fn+sNbTZ7JnZa2bP7D3wfj4e+7H3vtZ1XeuzFpv57HVda6+liMDMzKxYO5U7ADMza1+cOMzMLBMnDjMzy8SJw8zMMnHiMDOzTJw4zMwsEycOy0TSZEnfLlFffSR9IKkqff8HSV8uRd9pf49JOr9U/WVY77WS3pX094ztit63ku6SdG3zIgRJF0j6c3PbV+q6rG04cdgWkhZIWivpfUkrJT0raaykLZ+TiBgbEd8tsq9PN1YnIt6JiF0ioq4EsU+U9Iu8/kdHxN0t7TtjHL2BrwMDIuKjBZYfJ6m2U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MPFRlZmaZbBdDVT169Ii+ffuWOwwzs3Zl5syZ70ZEz6Zrbm27SBx9+/alpqam3GGYmbUrkv7WdK1teajKzMwyceIwM7NMnDjMzCyT7WKOw8zaj40bN1JbW8u6devKHcoOo0uXLvTq1YuOHUtzQWEnDjNrU7W1tey666707duXba/taKUWEaxYsYLa2lr69etXkj537MQxsVuBslVtH4fZDmTdunVOGm1IEnvuuSfLly8vWZ877hxHoaTRWLmZlYyTRtsq9f7ecROHmZk1ixOHmVkbmD59Otdff32mNn379uXdd99tpYiab8ee4zAzayOnnnoqp556arnDKAkfcZhZRZs2axFHX/8U/cY9wtHXP8W0WaW5vfuNN97IwIEDGThwIDfddBMA99xzD4cccgiDBw/mC1/4AgBLly7l9NNPZ/DgwQwePJhnn32WBQsWMHDgwC19/eAHP2DixIkAHHfccVx++eUcddRRDBw4kBdeeAGAu+66i0suuQSA5cuX89nPfpbDDjuMww47jGeeeQaAFStWcOKJJ3LooYfyla98hUq9evmOe8QxcZXPqjKrcNNmLWL8Qy+zdmNye/FFK9cy/qGXATjt0P2a3e/MmTP52c9+xl/+8hcigsMPP5zDDjuM6667jmeeeYYePXrw3nvvAXDZZZcxYsQIHn74Yerq6vjggw/4xz/+0Wj/H374Ic8++yxPP/00F110Ea+88spWy//t3/6Nf//3f+eYY47hnXfeYeTIkbz66qtcc801HHPMMUyYMIFHHnmE228vdNv28ttxEwc4SZhVuBsen7cladRbu7GOGx6f16LE8ec//5nTTz+dnXfeGYAzzjiDmpoaPve5z9GjRw8A9thjDwCeeuop7rnnHgCqqqro1q1bk4njnHPOAeDYY49l9erVrFy5cqvlTz75JH/961+3vF+9ejXvv/8+Tz/9NA899BAAJ598Mrvvvnuzt7E17diJw8wq2uKVazOVF6vQEJCkok9b7dChA5s3b97yPv9X8Pn95L/fvHkzzz33HF27di0YR6XzHIeZVax9u2/7h7Wx8mIde+yxTJs2jTVr1vDhhx/y8MMPM2zYMKZOncqKFSsAtgxVHX/88dx2220A1NXVsXr1avbee2+WLVvGihUrWL9+Pb/5zW+26n/KlClAcmTTrVs3unXbelj8xBNP5JZbbtnyfvbs2VviuvfeewF47LHHmjyyKRcnDjOrWN8ceSBdO1ZtVda1YxXfHHlgi/odOnQoF1xwAcOHD+fwww/ny1/+MkcffTRXXXUVI0aMYPDgwVxxxRUA3Hzzzfz+979n0KBBDBs2jLlz59KxY0cmTJjA4YcfzimnnMJBBx20Vf+
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"n = len(df) // 2\n",
"i = np.arange(len(df))\n",
"np.random.shuffle(i)\n",
"i = i[:n]\n",
"l = light[i]\n",
"o = occupancy[i]\n",
"k1 = kde(l[o == 1])\n",
"k0 = kde(l[o == 0])\n",
"plt.scatter(light, k1.pdf(light), label=\"occupied\")\n",
"plt.scatter(light, k0.pdf(light), label=\"unoccupied\")\n",
"plt.title(\"Distribution of Light by Class\")\n",
"plt.legend()\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "tough-austria",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"31.4725"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"humidity[np.argmin(np.abs(k0.pdf(humidity) - k1.pdf(humidity)))]"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "ruled-musical",
"metadata": {},
"outputs": [],
"source": [
"# test a threshold-based classifier based on light\n",
"light_feature = (light > 0.25)*1\n",
"occupancy = df.Occupancy.values"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "medium-speed",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.metrics import confusion_matrix"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "frank-bennett",
"metadata": {},
"outputs": [],
"source": [
"confuse = confusion_matrix(light_feature, occupancy)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "controlling-johns",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f76fa83ed00>"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAARUAAAD8CAYAAABZ0jAcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAOfklEQVR4nO3dfahkd33H8ffHJEswBlONu4kxPrRdbNfipukSI5GabTU1S2UVLCRIDGJYFIVWaiFUSEv7j1XagvjU1QYjNEpB1yx287BKS7Qh6kaSTVKjbpOlpndxm4fGxqew8u0fc7Yd787snXvvb8/cc3m/4DJnzjm/ub/DYT+cuTNnP6kqJKmVZ817ApLWF0NFUlOGiqSmDBVJTRkqkpoyVCQ1tapQSfK8JPuTfK97/KUp+x1Ocn+Se5McWO54ScOx2iuV64GvVNVm4Cvd82m2V9VFVbVtheMlDUBW8+W3JN8BLq+qI0nOB/6lql4+Yb/DwLaqemwl4yUNx2pD5b+r6pyx509W1QlvYZI8AjwJFPB3VbV7OeO7bbuAXQBnPTu/9Wu/umHF81b/vnvw2fOegpbhp/yIZ+pnWcnY05faIcmXgfMmbHr/Mn7PZVW1kGQjsD/JQ1V15zLG0wXRboBtW8+sb9x+4XKGa85+74UXzXsKWoav11dWPHbJUKmq103bluQHSc4fe/tydMprLHSPR5PsAS4B7gRmGi9pOFb7h9q9wLXd8rXALYt3SHJWkrOPLwNXAA/MOl7SsKw2VD4AvD7J94DXd89J8sIk+7p9NgFfS3If8A3gn6rqtpONlzRcS779OZmqehz43QnrF4Ad3fLDwNbljJc0XH6jVlJThoqkpgwVSU0ZKpKaMlQkNWWoSGrKUJHUlKEiqSlDRVJThoqkpgwVSU0ZKpKaMlQkNWWoSGrKUJHUlKEiqSlDRVJThoqkpk557WmSC5P8c5JvJ3kwyR+ObfvzJP/Z1aHem2THauYjaf76qD09BvxxVf06c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qfVGflwV4t6MMnFY9tOWpkqaVhaXal8mlFJ2DRXApu7n13Ax+EXKlOvBLYAVyfZ0mhOkuagSah05V9PnGSXncBnauRu4Jwk57P8ylRJa1xff1OZVo26nMpUa0+lAegrVKZVo85cmVpVu6tqW1Vt25Azm05OUjtNen9mMK0adcOU9ZIGqq8rlb3A27pPgS4FnqqqI8xYmSppOJpcqST5LHA5cG6SR4E/A86A/2sq3AfsAA4BPwbe3m2bWJnaYk6S5qNV7enVS2wv4N1Ttp1QmSppuPxGraSmDBVJTRkqkpoyVCQ1ZahIaspQkdSUoSKpKUNFUlOGiqSmDBVJTRkqkpoyVCQ1ZahIaspQkdSUoSKpKUNFUlOGiqSmDBVJTfVVe/rWru70YJK7kmwd23Y4yf1J7k1yoMV8JM1PX7WnjwCvrapXAn8J7F60fXtVXVRV2xrNR9KctPqPr+9M8tKTbL9r7OndjPp9JK1D8/ibyjuAW8eeF3BHknuS7JrDfCQ11FdDIQBJtjMKldeMrb6sqhaSbAT2J3moK3xfPHYXsAvgzGc9p5f5Slq+3q5UkrwS+BSws6oeP76+qha6x6PAHuCSSePtUpaGoZdQSfJi4AvANVX13bH1ZyU5+/gycAUw8RMkScPQV+3pDcDzgY8lATjWfdKzCdjTrTsduLmqbmsxJ0nz0Vft6XXAdRPWPwxsPXGEpKHyG7WSmjJUJDVlqEhqylCR1JShIqkpQ0VSU4aKpKYMFUlNGSqSmjJUJDVlqEhqylCR1JShIqkpQ0VSU4aKpKYMFUlNGSqSmjJUJDVlqEhqqq8u5cuTPNX1Jd+b5IaxbW9I8p0kh5Jc32I+kuanry5lgK92fckXVdVfACQ5DfgocCWwBbg6yZZGc5I0B01CpWsUfGIFQy8BDlXVw1X1DPA
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.imshow(confuse)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "referenced-fashion",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.60600375, 0. ],\n",
" [0.02926829, 0.36472795]])"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"confuse/len(occupancy)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "specialized-anchor",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"133"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(df)//20"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "light-helen",
"metadata": {},
"outputs": [],
"source": [
"n = len(df)*6//10\n",
"occupancy = df.Occupancy.values[0:n]\n",
"errors = []\n",
"thresholds = np.linspace(0, 1, 100)\n",
"for thresh in thresholds:\n",
" light_feature = (light[0:n] > thresh)*1\n",
" humidity_feature = (humidity[0:n] > 25.37)*1\n",
"# feature = ((light_feature + humidity_feature) == 2)*1\n",
" light_feature = (light[0:n] > 0.2)*1\n",
" feature = (light_feature + 0.7*humidity_feature > 2*thresh)*1\n",
" confuse = confusion_matrix(feature, occupancy)/n\n",
"# det = np.linalg.det(confuse/np.linalg.norm(confuse))\n",
" errors.append(confuse[0,0] + confuse[1,1] - confuse[0,1] - confuse[1,1])\n",
"# errors = confuse[0,0]\n",
"del confuse, thresh"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "danish-paint",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f76fa7c5220>]"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAR5UlEQVR4nO3dbYxc5XnG8es654ydNksbxG5KZJvYSZxQIhmFLm5akQZaIQxUMqhIcRIFN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bJElF4lAB5AwZuidCHQAyaIp2olAB5AsmqKdCHQAyeI69E4EOoBktWbo3JxLEoEOIGGtpihLLpIIdAAJK2iKdiDQASSryHmmaBmBDiBZraYoM3RJBDqAhNWYoXcg0AEki6Zop0qBbnub7aO2Z23f2+f4p20fbvz3lO2rB18qAHRqNUW5bFFShUC3nUt6SNLNkq6S9EnbV3Wd9pKkj0fEFkn3S9oz6EIBoFvBM0U7VJmhb5U0GxHHIuK0pH2StpdPiIinIuJHjbdPS1o/2DIBoFfO3RY7VAn0dZKOl97PNT5byuckPd7vgO27bc/Ynpmfn69eJQD0YVu13DRFG6oEuvt81vd3z/YNqgf6Pf2OR8SeiJiOiOmpqanqVQLAEoosI9AbigrnzEnaUHq/XtKJ7pNsb5H0sKSbI+LVwZQHAOdWZGanaEOVGfohSZttb7K9RtIOSfvLJ9i+QtIjkj4TEd8bfJkA0F+Rm6Zow7Iz9IhYsL1L0kFJuaS9EXHE9s7G8d2S7pN0maSv2pakhYiYHl7ZAFBX5Bl3W2yosuSiiDgg6UDXZ7tLr++SdNdgSwOA5dUyZuhN7BQFkLT6DJ1Alwh0AIkrcpqiTQQ6gKQVLLm0EOgAkla
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(thresholds, errors)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "lasting-still",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAARUAAAEICAYAAABxpmCnAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAASJ0lEQVR4nO3dfaxkdX3H8fdHYDU8uTwIAqKI4gM07GpXxIAFWkUgksUEG6gBo+CK1dTaqiGhQatNSzXWxCriVgnQgpYoC8QCglYLlIIuFhYQRJ5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0ZKpKaMlQkNWWoSGrKUJHUlKEiqSlDRVJThoqkpgwVSU0ZKpKaMlQkNWWoSGrKUJHUlKEiqalhlT09OMlDXWnTG5KcOuhYSeNlWGVPAa6qqjfOcaykMTGUsqdP01hJC1CLv6Y/WdnTV0/S7zVJbqRXaOz9VXXLLMbSlURdAbBoy8Uc8N53Npi6hmWXq+4c9RQ0C5udMPdoGFbZ0+8CL6iqDUmOAC4E9hpwbG9lX9nTrbff3bKn0gI1lLKnVfVwVW3oli8Btkiy4yBjJY2XYZU9fW66MoRJ9uue9/5BxkoaL8Mqe3o08K4kTwKPAcdUVQGTjp3vnCSNzrDKnn4a+PSgYyWNL8+oldSUoSKpKUNFUlOGiqSmDBVJTRkqkpoyVCQ1ZahIaspQkdSUoSKpKUNFUlOGiqSmDBVJTRkqkpoyVCQ1ZahIaspQkdSUoSKpqWGVPf1AX8nTm5P8Osn2Xds9SW7q2la3mI+k0RlK2dOq+jjw8a7/kcD7quoXfZs5pKrum+9cJI3eKMqeHgt8scHzSlqAWoTKZKVLd5usY5ItgcOAr/StLuDyJNd3pU0nlWR
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.50093809 0. ]\n",
" [0.13433396 0.36472795]]\n"
]
}
],
"source": [
"occupancy = df.Occupancy.values\n",
"thresh = thresholds[np.argmax(errors)]\n",
"# light_feature = (light.values > thresh)*1\n",
"# feature = light_feature\n",
"light_feature = (light > 0.1182)*1\n",
"humidity_feature = (humidity > 25.37)*1\n",
"feature = (light_feature + 0.5*humidity_feature > 2*thresh)*1\n",
"confuse = confusion_matrix(feature, occupancy)/len(occupancy)\n",
"plt.imshow(confuse)\n",
"plt.title(f\"thresh={thresh:.4f}\")\n",
"plt.show()\n",
"print(confuse)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "binding-incident",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iV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PmY2OH3/jdqW0qVvpCrFcbukFRHxw5ZuDwInR8QTkhYCy4BXt7QviIhH+52LmQ1eLWVPI+LmiHiiPL2Fqr6PmU1CdZU9bfVu4LqW5wGslnSHpKWdBrnsqVkzZJTo6Lp0qaQFVKFyUsvqEyNiSNJMYI2k+yJi7U4vGLGM6rSJ+XOnt319Mxu8jCOVbsqeIukVwBeBxRHx2PD6iBgqP7cCy6lOp8ysoWopeyrpCOBqYElE3N+yfoakvYeXgVOBexLmZGYDUlfZ0wuAA4BLJAHsiIj5wCxgeVk3FbgyIlb1OyczG5y6yp6eC5zbZtwDwNyR682suXxFrZmlcqiYWSqHipmlcqiYWSqHipmlcqiYWSqHipmlcqiYWSqHipmlcqiYWSqHipmlcqiYWSqHipmlcqiYWSqHipmlcqiYWSqHipmlcqiYWaq6yp6eImlbKW16l6QLuh1rZs1SV9lTgBsj4i3jHGtmDVFL2dNdNNbMJqCMv6bfruzpq9v0e42k9VSFxj4cERt7GEspiboUYPoee7Ho2AUJU7e6PHjVEYOegvXgub+9edxj6yp7eidwZERsl7QIuAaY3eXYamVL2dMXTn2Ry56aTVC1lD2NiKciYntZXgnsKenAbsaaWbPUVfb0IJUyhJKOL9t9rJuxZtYsdZU9fTvwXkk7gGeB0yMigLZj+52TmQ1OXWVPPwt8ttuxZtZcvqLWzFI5VMwslUPFzFI5VMwslUPFzFI5VMwslUPFzFI5VMwslUPFzFI5VMwslUPFzFI5VMwslUPFzFI5VMwslUPFzFI5VMwslUPFzFI5VMwsVV1lT/+mpeTpPZJ+K2n/0rZZ0t2lbV3GfMxscGo
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.60600375 0. ]\n",
" [0.02926829 0.36472795]]\n"
]
}
],
"source": [
"occupancy = df.Occupancy.values\n",
"thresh = 0.1182\n",
"light_feature = (light > thresh)*1\n",
"feature = light_feature\n",
"confuse = confusion_matrix(feature, occupancy)/len(occupancy)\n",
"plt.imshow(confuse)\n",
"plt.title(f\"thresh={thresh:.4f}\")\n",
"plt.show()\n",
"print(confuse)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "standing-footage",
"metadata": {},
"outputs": [],
"source": [
"humidity_feature = (humidity > 25.37)*1\n",
"occupancy = df.Occupancy.values\n",
"confuse = confusion_matrix(humidity_feature, occupancy)/len(occupancy)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "direct-nirvana",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.51594747, 0.07879925],\n",
" [0.11932458, 0.28592871]])"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"confuse"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "passive-index",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([2, 2, 2, ..., 2, 2, 2])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"light_feature + humidity_feature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0cdc07a-9600-4bc3-8f31-627ac3329da7",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}