{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install librosa" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " timestamp hum temp door motion illum label dayofweek\n", "0 2021-08-30 00:00:00 78.0 246.0 0.0 0.0 0.0 0.0 0\n", "1 2021-08-30 00:01:00 78.0 246.0 0.0 0.0 0.0 0.0 0\n", "2 2021-08-30 00:02:00 78.0 246.0 0.0 0.0 0.0 0.0 0\n", "3 2021-08-30 00:03:00 78.0 246.0 0.0 0.0 0.0 0.0 0\n", "4 2021-08-30 00:04:00 78.0 246.0 0.0 0.0 0.0 0.0 0\n", "... ... ... ... ... ... ... ... ...\n", "64795 2021-11-26 23:55:00 26.0 191.0 0.0 0.0 1.0 0.0 4\n", "64796 2021-11-26 23:56:00 26.0 191.0 0.0 0.0 1.0 0.0 4\n", "64797 2021-11-26 23:57:00 26.0 191.0 0.0 0.0 1.0 0.0 4\n", "64798 2021-11-26 23:58:00 26.0 191.0 0.0 0.0 1.0 0.0 4\n", "64799 2021-11-26 23:59:00 26.0 191.0 0.0 0.0 1.0 0.0 4\n", "\n", "[64800 rows x 8 columns]\n" ] } ], "source": [ "import pandas as pd\n", "from pycaret.classification import *\n", "\n", "data = pd.read_csv('data/data_all.csv')\n", "print(data)\n", "# data.style" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Delta Feature\n", "$\\Delta_t = \\frac{\\sum_{n=1}^{N} n(c_{t+n} - c_{t-n})}{2\\sum_{n=1}^{N} n^2}$\n", "$n=2, N=2$\n", "\n", "$\\Delta\\Delta_t = \\frac{\\sum_{n=1}^{N} n(\\Delta_{t+n} - \\Delta_{t-n})}{2\\sum_{n=1}^{N} n^2}$\n", "\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['label', 'hum', 'temp', 'door', 'motion', 'illum', 'dayofweek', 'month',\n", " 'day', 'hour', 'minute'],\n", " dtype='object')\n", "Index(['label', 'hum', 'd_hum', 'dd_hum', 'temp', 'd_temp', 'dd_temp', 'door',\n", " 'motion', 'illum', 'dayofweek', 'month', 'day', 'hour', 'minute'],\n", " dtype='object')\n" ] } ], "source": [ "import librosa as fe\n", "\n", "data.timestamp = data.timestamp.apply(lambda x: pd.Timestamp(x))\n", "data['month'] = data.timestamp.dt.month\n", "data['day'] = data.timestamp.dt.day\n", "data['hour'] = data.timestamp.dt.hour\n", "data['minute'] = data.timestamp.dt.minute\n", "data['dayofweek'] = data.timestamp.dt.dayofweek\n", "\n", "def f_e(df, cn='hum'): \n", " # delta feature \n", " df[f'd_{cn}'] = fe.feature.delta(df[f'{cn}'])\n", " df[f'dd_{cn}'] = fe.feature.delta(df[f'd_{cn}'], order=2)\n", " # time expand\n", " for i in range(1,10):df[f'sh{i}_{cn}'] = df[f'{cn}'].shift(-i).fillna(0)\n", " return df\n", "f_e(data, 'hum')\n", "f_e(data, 'temp')\n", "# out = data.drop('timestamp', axis=1)\n", "# list(data.columns)\n", "\n", "# nomal set : not engineering\n", "out = data[['label', 'hum', 'temp', 'door', 'motion', 'illum', 'dayofweek', 'month', 'day', 'hour', 'minute']]\n", "out.to_csv('data/feature_ori.csv', index=False)\n", "# out.to_csv('data/feature_ori_to_aws.csv', index=False, header=False)\n", "print(out.columns)\n", "\n", "# eng set : delta feature\n", "out = data[['label', 'hum', 'd_hum', 'dd_hum', 'temp', 'd_temp', 'dd_temp', 'door', 'motion', 'illum', 'dayofweek', 'month', 'day', 'hour', 'minute']]\n", "out.to_csv('data/feature_delta.csv', index=False)\n", "# out.to_csv('data/feature_delta_to_aws.csv', index=False, header=False)\n", "print(out.columns)\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['timestamp', 'hum', 'temp', 'door', 'motion', 'illum', 'label',\n", " 'dayofweek', 'month', 'hour', 'd_hum', 'dd_hum', 'sh1_hum', 'sh2_hum',\n", " 'sh3_hum', 'sh4_hum', 'sh5_hum', 'sh6_hum', 'sh7_hum', 'sh8_hum',\n", " 'sh9_hum', 'd_temp', 'dd_temp', 'sh1_temp', 'sh2_temp', 'sh3_temp',\n", " 'sh4_temp', 'sh5_temp', 'sh6_temp', 'sh7_temp', 'sh8_temp', 'sh9_temp'],\n", " dtype='object')" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.columns" ] } ], "metadata": { "interpreter": { "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" }, "kernelspec": { "display_name": "Python 3.8.10 64-bit", "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.8.12" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }