{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Overview","metadata":{}},{"cell_type":"markdown","source":"1448棟のビルの4種類のメーター（電力、冷水、スチーム、温水）の値を予測するコンペである。\n\n背景としては、エネルギー使用量（4種類のメーターの値）が正確に予測できるようになることで<br>\n省エネ投資を活発化させて、環境問題に貢献したいという狙いがある。\n\nビルの所有者は、ビルのエネルギー効率を改善するような投資を行うことで<br>\nエネルギー効率が改善された分、コストを抑えることができる。","metadata":{}},{"cell_type":"markdown","source":"# Module","metadata":{}},{"cell_type":"code","source":"import gc\nimport sys\nimport optuna\nimport datetime\nimport warnings\nimport matplotlib\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport lightgbm as lgb\nimport matplotlib.pyplot as plt\n\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error\nfrom pandas.api.types import is_datetime64_any_dtype as is_datetime\nfrom pandas.api.types import is_categorical_dtype","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:12.297683Z","iopub.execute_input":"2021-06-21T01:18:12.298387Z","iopub.status.idle":"2021-06-21T01:18:15.365972Z","shell.execute_reply.started":"2021-06-21T01:18:12.298297Z","shell.execute_reply":"2021-06-21T01:18:15.365079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Datasets","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv('../input/ashrae-energy-prediction/train.csv')\n\nprint(train.shape)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:15.367546Z","iopub.execute_input":"2021-06-21T01:18:15.36799Z","iopub.status.idle":"2021-06-21T01:18:29.987217Z","shell.execute_reply.started":"2021-06-21T01:18:15.367946Z","shell.execute_reply":"2021-06-21T01:18:29.98485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"1時間ごとのメータ値を保持するテーブル（学習データ）<br>\n・building_id：ビルのID<br>\n・meter：0は電力、1は冷水、2はスチーム、3は温水<br>\n・timestamp：日付と時刻<br>\n・meter_reading：メーターの使用量（目的変数）<br>","metadata":{"execution":{"iopub.status.busy":"2021-06-04T05:10:36.573045Z","iopub.execute_input":"2021-06-04T05:10:36.573413Z","iopub.status.idle":"2021-06-04T05:10:36.579555Z","shell.execute_reply.started":"2021-06-04T05:10:36.573384Z","shell.execute_reply":"2021-06-04T05:10:36.578197Z"}}},{"cell_type":"code","source":"test = pd.read_csv('../input/ashrae-energy-prediction/test.csv')\n\nprint(test.shape)\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:29.988891Z","iopub.execute_input":"2021-06-21T01:18:29.989169Z","iopub.status.idle":"2021-06-21T01:18:58.43449Z","shell.execute_reply.started":"2021-06-21T01:18:29.989142Z","shell.execute_reply":"2021-06-21T01:18:58.4335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"1時間ごとのメータ値を保持するテーブル（テストデータ）<br>\n・row_id：行のID<br>\n・building_id：ビルのID<br>\n・meter：0は電力、1は冷水、2はスチーム、3は温水<br>\n・timestamp：日付と時刻<br>","metadata":{}},{"cell_type":"code","source":"usecols = {'site_id', 'timestamp', 'air_temperature', 'dew_temperature'}","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:58.438421Z","iopub.execute_input":"2021-06-21T01:18:58.438687Z","iopub.status.idle":"2021-06-21T01:18:58.443054Z","shell.execute_reply.started":"2021-06-21T01:18:58.438662Z","shell.execute_reply":"2021-06-21T01:18:58.442047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"weather_train = pd.read_csv('../input/ashrae-energy-prediction/weather_train.csv', usecols=usecols)\n\nprint(weather_train.shape)\nweather_train.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:58.444002Z","iopub.execute_input":"2021-06-21T01:18:58.444322Z","iopub.status.idle":"2021-06-21T01:18:58.668097Z","shell.execute_reply.started":"2021-06-21T01:18:58.444293Z","shell.execute_reply":"2021-06-21T01:18:58.667108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"気象情報を保持するテーブル（学習データに対応）<br>\n・site_id：ビルの物理的な位置<br>\n・timestamp：日付と時刻<br>\n・air_temperature：気温<br>\n・dew_temperature：湿度<br>\n・precip_depth：降水量<br>\n・sea_level_pressure：海圧<br>\n・wind_direction：風向<br>\n・wind_speed：風速<br>","metadata":{}},{"cell_type":"code","source":"weather_test = pd.read_csv('../input/ashrae-energy-prediction/weather_test.csv', usecols=usecols)\n\nprint(weather_test.shape)\nweather_test.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:58.669185Z","iopub.execute_input":"2021-06-21T01:18:58.669458Z","iopub.status.idle":"2021-06-21T01:18:59.040414Z","shell.execute_reply.started":"2021-06-21T01:18:58.669431Z","shell.execute_reply":"2021-06-21T01:18:59.039636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"気象情報を保持するテーブル（テストデータに対応）<br>\n・site_id：ビルの物理的な位置<br>\n・timestamp：日付と時刻<br>\n・air_temperature：気温<br>\n・dew_temperature：湿度<br>\n・precip_depth：降水量<br>\n・sea_level_pressure：海圧<br>\n・wind_direction：風向<br>\n・wind_speed：風速<br>","metadata":{}},{"cell_type":"code","source":"usecols = {'site_id', 'building_id', 'primary_use', 'square_feet', 'year_built'}","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:59.042815Z","iopub.execute_input":"2021-06-21T01:18:59.043084Z","iopub.status.idle":"2021-06-21T01:18:59.047368Z","shell.execute_reply.started":"2021-06-21T01:18:59.043057Z","shell.execute_reply":"2021-06-21T01:18:59.046336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"building = pd.read_csv('../input/ashrae-energy-prediction/building_metadata.csv', usecols=usecols)\n\nprint(building.shape)\nbuilding.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:59.0493Z","iopub.execute_input":"2021-06-21T01:18:59.049567Z","iopub.status.idle":"2021-06-21T01:18:59.07696Z","shell.execute_reply.started":"2021-06-21T01:18:59.049541Z","shell.execute_reply":"2021-06-21T01:18:59.07627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"ビルの情報を保持するテーブル<br>\n・site_id：ビルの物理的な位置<br>\n・building_id：ビルのID<br>\n・primary_use：使用目的<br>\n・square_feet：面積<br>\n・year_built：施工した年<br>\n・floor_count：階数<br>","metadata":{}},{"cell_type":"markdown","source":"# Lags","metadata":{}},{"cell_type":"code","source":"'''\nlag_cols = ['air_temperature', 'dew_temperature']\n\nfor i in lag_cols:\n    weather_train['DIFF_' + i] = weather_train.groupby(by = ['site_id'])[i].shift(-1)\n    weather_train['PREVIOUS_DIFF_' + i] = np.abs(weather_train[i] - weather_train['DIFF_' + i])\n    weather_train = weather_train.drop(['DIFF_' + i], axis=1)\n    \nweather_train.head()\n'''","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:59.078155Z","iopub.execute_input":"2021-06-21T01:18:59.078678Z","iopub.status.idle":"2021-06-21T01:18:59.083437Z","shell.execute_reply.started":"2021-06-21T01:18:59.078645Z","shell.execute_reply":"2021-06-21T01:18:59.082718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''\nlag_cols = ['air_temperature', 'dew_temperature']\n\nfor i in lag_cols:\n    weather_test['DIFF_' + i] = weather_test.groupby(by = ['site_id'])[i].shift(-1)\n    weather_test['PREVIOUS_DIFF_' + i] = np.abs(weather_test[i] - weather_test['DIFF_' + i])\n    weather_test = weather_test.drop(['DIFF_' + i], axis=1)\n    \nweather_test.head()\n'''","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:59.08464Z","iopub.execute_input":"2021-06-21T01:18:59.085119Z","iopub.status.idle":"2021-06-21T01:18:59.095718Z","shell.execute_reply.started":"2021-06-21T01:18:59.085088Z","shell.execute_reply":"2021-06-21T01:18:59.094973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Join","metadata":{}},{"cell_type":"code","source":"def reduce_mem_usage(df, use_float16=False):\n    \n    start_mem = df.memory_usage().sum() / 1024**2\n    print('Memory usage of dataframe is {:.2f} MB'.format(start_mem))\n    \n    for col in df.columns:\n        if is_datetime(df[col]) or is_categorical_dtype(df[col]):\n            continue\n        col_type = df[col].dtype\n        \n        if col_type != object:\n            c_min = df[col].min()\n            c_max = df[col].max()\n            if str(col_type)[:3] == 'int':\n                if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:\n                    df[col] = df[col].astype(np.int8)\n                elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:\n                    df[col] = df[col].astype(np.int16)\n                elif c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:\n                    df[col] = df[col].astype(np.int32)\n                elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:\n                    df[col] = df[col].astype(np.int64)  \n            else:\n                if use_float16 and c_min > np.finfo(np.float16).min and c_max < np.finfo(np.float16).max:\n                    df[col] = df[col].astype(np.float16)\n                elif c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:\n                    df[col] = df[col].astype(np.float32)\n                else:\n                    df[col] = df[col].astype(np.float64)\n        else:\n            df[col] = df[col].astype('category')\n\n    end_mem = df.memory_usage().sum() / 1024**2\n    print('Memory usage after optimization is: {:.2f} MB'.format(end_mem))\n    print('Decreased by {:.1f}%'.format(100 * (start_mem - end_mem) / start_mem))\n    \n    return df","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:59.096879Z","iopub.execute_input":"2021-06-21T01:18:59.097336Z","iopub.status.idle":"2021-06-21T01:18:59.111552Z","shell.execute_reply.started":"2021-06-21T01:18:59.097295Z","shell.execute_reply":"2021-06-21T01:18:59.110584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train = reduce_mem_usage(train)\n# test = reduce_mem_usage(test)\n\nweather_train = reduce_mem_usage(weather_train)\nweather_test = reduce_mem_usage(weather_test)\n\nbuilding = reduce_mem_usage(building)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:59.112916Z","iopub.execute_input":"2021-06-21T01:18:59.113204Z","iopub.status.idle":"2021-06-21T01:18:59.249411Z","shell.execute_reply.started":"2021-06-21T01:18:59.113176Z","shell.execute_reply":"2021-06-21T01:18:59.248387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.merge(building, on='building_id', how='left')\ntest = test.merge(building, on='building_id', how='left')\n\nprint(train.shape)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:18:59.251193Z","iopub.execute_input":"2021-06-21T01:18:59.251628Z","iopub.status.idle":"2021-06-21T01:19:08.931121Z","shell.execute_reply.started":"2021-06-21T01:18:59.251568Z","shell.execute_reply":"2021-06-21T01:19:08.93007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del building\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:08.932465Z","iopub.execute_input":"2021-06-21T01:19:08.932769Z","iopub.status.idle":"2021-06-21T01:19:09.078184Z","shell.execute_reply.started":"2021-06-21T01:19:08.93274Z","shell.execute_reply":"2021-06-21T01:19:09.076722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.merge(weather_train, on=['site_id', 'timestamp'], how='left')\ntest = test.merge(weather_test, on=['site_id', 'timestamp'], how='left')\n\nprint(train.shape)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:09.079815Z","iopub.execute_input":"2021-06-21T01:19:09.080298Z","iopub.status.idle":"2021-06-21T01:19:27.982481Z","shell.execute_reply.started":"2021-06-21T01:19:09.080243Z","shell.execute_reply":"2021-06-21T01:19:27.98166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del weather_train, weather_test\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:27.985427Z","iopub.execute_input":"2021-06-21T01:19:27.985755Z","iopub.status.idle":"2021-06-21T01:19:28.119275Z","shell.execute_reply.started":"2021-06-21T01:19:27.985724Z","shell.execute_reply":"2021-06-21T01:19:28.118032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train = reduce_mem_usage(train)\n# test = reduce_mem_usage(test)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:28.120853Z","iopub.execute_input":"2021-06-21T01:19:28.121284Z","iopub.status.idle":"2021-06-21T01:19:28.131732Z","shell.execute_reply.started":"2021-06-21T01:19:28.121232Z","shell.execute_reply":"2021-06-21T01:19:28.130439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.reset_index(drop=True)\ntest = test.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:28.133284Z","iopub.execute_input":"2021-06-21T01:19:28.133722Z","iopub.status.idle":"2021-06-21T01:19:29.916421Z","shell.execute_reply.started":"2021-06-21T01:19:28.133678Z","shell.execute_reply":"2021-06-21T01:19:29.91557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(sys.getsizeof(train))\nprint(sys.getsizeof(test))","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:29.917875Z","iopub.execute_input":"2021-06-21T01:19:29.918286Z","iopub.status.idle":"2021-06-21T01:19:40.830286Z","shell.execute_reply.started":"2021-06-21T01:19:29.918244Z","shell.execute_reply":"2021-06-21T01:19:40.829245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.memory_usage()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:40.831363Z","iopub.execute_input":"2021-06-21T01:19:40.831659Z","iopub.status.idle":"2021-06-21T01:19:40.840621Z","shell.execute_reply.started":"2021-06-21T01:19:40.83163Z","shell.execute_reply":"2021-06-21T01:19:40.839609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.memory_usage()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:40.841874Z","iopub.execute_input":"2021-06-21T01:19:40.842159Z","iopub.status.idle":"2021-06-21T01:19:40.856275Z","shell.execute_reply.started":"2021-06-21T01:19:40.842132Z","shell.execute_reply":"2021-06-21T01:19:40.855239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train.shape)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:40.86176Z","iopub.execute_input":"2021-06-21T01:19:40.862036Z","iopub.status.idle":"2021-06-21T01:19:40.880961Z","shell.execute_reply.started":"2021-06-21T01:19:40.86201Z","shell.execute_reply":"2021-06-21T01:19:40.879767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Analytics","metadata":{}},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:40.883662Z","iopub.execute_input":"2021-06-21T01:19:40.883959Z","iopub.status.idle":"2021-06-21T01:19:40.906491Z","shell.execute_reply.started":"2021-06-21T01:19:40.883928Z","shell.execute_reply":"2021-06-21T01:19:40.905534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.nunique()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:40.907443Z","iopub.execute_input":"2021-06-21T01:19:40.907738Z","iopub.status.idle":"2021-06-21T01:19:48.1117Z","shell.execute_reply.started":"2021-06-21T01:19:40.907708Z","shell.execute_reply":"2021-06-21T01:19:48.110374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:48.113165Z","iopub.execute_input":"2021-06-21T01:19:48.11354Z","iopub.status.idle":"2021-06-21T01:19:50.162156Z","shell.execute_reply.started":"2021-06-21T01:19:48.113507Z","shell.execute_reply":"2021-06-21T01:19:50.161108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.corr()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:50.16375Z","iopub.execute_input":"2021-06-21T01:19:50.164158Z","iopub.status.idle":"2021-06-21T01:19:54.580253Z","shell.execute_reply.started":"2021-06-21T01:19:50.164116Z","shell.execute_reply":"2021-06-21T01:19:54.579218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualization","metadata":{"execution":{"iopub.status.busy":"2021-06-09T04:35:08.004275Z","iopub.execute_input":"2021-06-09T04:35:08.004653Z","iopub.status.idle":"2021-06-09T04:35:08.008716Z","shell.execute_reply.started":"2021-06-09T04:35:08.004621Z","shell.execute_reply":"2021-06-09T04:35:08.007602Z"}}},{"cell_type":"code","source":"sns.set()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:54.581795Z","iopub.execute_input":"2021-06-21T01:19:54.582185Z","iopub.status.idle":"2021-06-21T01:19:54.58812Z","shell.execute_reply.started":"2021-06-21T01:19:54.582142Z","shell.execute_reply":"2021-06-21T01:19:54.587068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['timestamp'] = pd.to_datetime(train['timestamp'])\ntest['timestamp'] = pd.to_datetime(test['timestamp'])","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:19:54.589921Z","iopub.execute_input":"2021-06-21T01:19:54.590428Z","iopub.status.idle":"2021-06-21T01:20:07.104508Z","shell.execute_reply.started":"2021-06-21T01:19:54.590325Z","shell.execute_reply":"2021-06-21T01:20:07.103633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axes = plt.subplots(figsize=(8, 4))\ntrain[['timestamp', 'meter_reading']].set_index('timestamp').resample('H').mean()['meter_reading'].plot(ax=axes, label='hour', alpha=0.8).set_ylabel('Meter reading', fontsize=14)\ntrain[['timestamp', 'meter_reading']].set_index('timestamp').resample('D').mean()['meter_reading'].plot(ax=axes, label='day', alpha=0.8).set_ylabel('Meter reading', fontsize=14)\naxes.legend()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:20:07.105982Z","iopub.execute_input":"2021-06-21T01:20:07.106449Z","iopub.status.idle":"2021-06-21T01:20:09.494392Z","shell.execute_reply.started":"2021-06-21T01:20:07.106406Z","shell.execute_reply":"2021-06-21T01:20:09.49348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axes = plt.subplots(figsize=(8, 4))\ntrain[['timestamp', 'meter_reading']].set_index('timestamp').resample('W').mean()['meter_reading'].plot(ax=axes, label='week', alpha=1).set_ylabel('Meter reading', fontsize=14)\ntrain[['timestamp', 'meter_reading']].set_index('timestamp').resample('M').mean()['meter_reading'].plot(ax=axes, label='month', alpha=1).set_ylabel('Meter reading', fontsize=14)\naxes.legend()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:20:09.49571Z","iopub.execute_input":"2021-06-21T01:20:09.496001Z","iopub.status.idle":"2021-06-21T01:20:11.552985Z","shell.execute_reply.started":"2021-06-21T01:20:09.495972Z","shell.execute_reply":"2021-06-21T01:20:11.552023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Outliers","metadata":{}},{"cell_type":"code","source":"def to_season(month_num):\n    season = 'winter'\n    if 3 <= month_num <= 5:\n        season = 'spring'\n    elif 6 <= month_num <= 8:\n        season = 'summer'\n    elif 9 <= month_num <= 11:\n        season = 'autumn'\n    return season","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:20:11.554704Z","iopub.execute_input":"2021-06-21T01:20:11.555124Z","iopub.status.idle":"2021-06-21T01:20:11.561532Z","shell.execute_reply.started":"2021-06-21T01:20:11.555079Z","shell.execute_reply":"2021-06-21T01:20:11.560408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['month'] = train['timestamp'].dt.month\ntrain['season'] = train['month'].apply(lambda x: to_season(x))","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:20:11.562914Z","iopub.execute_input":"2021-06-21T01:20:11.563233Z","iopub.status.idle":"2021-06-21T01:20:24.663726Z","shell.execute_reply.started":"2021-06-21T01:20:11.563203Z","shell.execute_reply":"2021-06-21T01:20:24.662693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.drop(train[(train['meter'] == 0) & (train['meter_reading'] == 0)].index, axis=0)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:20:24.665055Z","iopub.execute_input":"2021-06-21T01:20:24.665372Z","iopub.status.idle":"2021-06-21T01:20:26.989655Z","shell.execute_reply.started":"2021-06-21T01:20:24.665343Z","shell.execute_reply":"2021-06-21T01:20:26.988621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.drop(train[(train['meter'] == 1) & (train['meter_reading'] == 0) & (train['season'] == 'spring')].index, axis=0)\ntrain = train.drop(train[(train['meter'] == 1) & (train['meter_reading'] == 0) & (train['season'] == 'summer')].index, axis=0)\ntrain = train.drop(train[(train['meter'] == 1) & (train['meter_reading'] == 0) & (train['season'] == 'autumn')].index, axis=0)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:20:26.990943Z","iopub.execute_input":"2021-06-21T01:20:26.991276Z","iopub.status.idle":"2021-06-21T01:20:46.566163Z","shell.execute_reply.started":"2021-06-21T01:20:26.991243Z","shell.execute_reply":"2021-06-21T01:20:46.564943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.drop(train[(train['meter'] == 2) & (train['meter_reading'] == 0) & (train['season'] == 'spring')].index, axis=0)\ntrain = train.drop(train[(train['meter'] == 2) & (train['meter_reading'] == 0) & (train['season'] == 'autumn')].index, axis=0)\ntrain = train.drop(train[(train['meter'] == 2) & (train['meter_reading'] == 0) & (train['season'] == 'winter')].index, axis=0)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:20:46.567728Z","iopub.execute_input":"2021-06-21T01:20:46.568138Z","iopub.status.idle":"2021-06-21T01:21:05.474289Z","shell.execute_reply.started":"2021-06-21T01:20:46.568097Z","shell.execute_reply":"2021-06-21T01:21:05.473234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.drop(train[(train['meter'] == 3) & (train['meter_reading'] == 0) & (train['season'] == 'spring')].index, axis=0)\ntrain = train.drop(train[(train['meter'] == 3) & (train['meter_reading'] == 0) & (train['season'] == 'autumn')].index, axis=0)\ntrain = train.drop(train[(train['meter'] == 3) & (train['meter_reading'] == 0) & (train['season'] == 'winter')].index, axis=0)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:05.475795Z","iopub.execute_input":"2021-06-21T01:21:05.476208Z","iopub.status.idle":"2021-06-21T01:21:24.294223Z","shell.execute_reply.started":"2021-06-21T01:21:05.476167Z","shell.execute_reply":"2021-06-21T01:21:24.293061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.drop('season', axis=1).reset_index(drop=True)\ngc.collect()\n\ntrain = reduce_mem_usage(train)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:24.295559Z","iopub.execute_input":"2021-06-21T01:21:24.295883Z","iopub.status.idle":"2021-06-21T01:21:26.820968Z","shell.execute_reply.started":"2021-06-21T01:21:24.295852Z","shell.execute_reply":"2021-06-21T01:21:26.819943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train.shape)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:26.822069Z","iopub.execute_input":"2021-06-21T01:21:26.822343Z","iopub.status.idle":"2021-06-21T01:21:26.841459Z","shell.execute_reply.started":"2021-06-21T01:21:26.822315Z","shell.execute_reply":"2021-06-21T01:21:26.840405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Feature Engineering","metadata":{}},{"cell_type":"code","source":"train['hour'] = train['timestamp'].dt.hour\n#train['day'] = train['timestamp'].dt.day\n#train['weekend'] = train['timestamp'].dt.weekday","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:26.842654Z","iopub.execute_input":"2021-06-21T01:21:26.842945Z","iopub.status.idle":"2021-06-21T01:21:28.58057Z","shell.execute_reply.started":"2021-06-21T01:21:26.84291Z","shell.execute_reply":"2021-06-21T01:21:28.579599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.drop(['timestamp', 'site_id'], axis=1)\ngc.collect()\n\ntrain = reduce_mem_usage(train)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:28.581727Z","iopub.execute_input":"2021-06-21T01:21:28.582007Z","iopub.status.idle":"2021-06-21T01:21:30.53321Z","shell.execute_reply.started":"2021-06-21T01:21:28.581982Z","shell.execute_reply":"2021-06-21T01:21:30.532547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_group = train.groupby('building_id')['meter_reading']\n\nbuilding_mean = df_group.mean()\nbuilding_median = df_group.median()\nbuilding_std = df_group.std()\n\nbuilding_min = df_group.min()\nbuilding_max = df_group.max()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:30.534135Z","iopub.execute_input":"2021-06-21T01:21:30.534501Z","iopub.status.idle":"2021-06-21T01:21:31.966133Z","shell.execute_reply.started":"2021-06-21T01:21:30.534473Z","shell.execute_reply":"2021-06-21T01:21:31.965018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['building_mean'] = train['building_id'].map(building_mean)\ntrain['building_median'] = train['building_id'].map(building_median)\ntrain['building_std'] = train['building_id'].map(building_std)\n\ntrain['building_min'] = train['building_id'].map(building_min)\ntrain['building_max'] = train['building_id'].map(building_max)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:31.967494Z","iopub.execute_input":"2021-06-21T01:21:31.967948Z","iopub.status.idle":"2021-06-21T01:21:33.1558Z","shell.execute_reply.started":"2021-06-21T01:21:31.967907Z","shell.execute_reply":"2021-06-21T01:21:33.154505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del df_group\ngc.collect()\n\ntrain = reduce_mem_usage(train)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:33.157155Z","iopub.execute_input":"2021-06-21T01:21:33.157501Z","iopub.status.idle":"2021-06-21T01:21:35.258377Z","shell.execute_reply.started":"2021-06-21T01:21:33.157468Z","shell.execute_reply":"2021-06-21T01:21:35.257294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train.shape)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:35.259707Z","iopub.execute_input":"2021-06-21T01:21:35.260026Z","iopub.status.idle":"2021-06-21T01:21:35.282601Z","shell.execute_reply.started":"2021-06-21T01:21:35.259993Z","shell.execute_reply":"2021-06-21T01:21:35.281563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Preprocess","metadata":{}},{"cell_type":"code","source":"# drop_col = ['precip_depth_1_hr', 'sea_level_pressure', 'wind_direction', 'wind_speed', 'floor_count']      ","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:35.283946Z","iopub.execute_input":"2021-06-21T01:21:35.284293Z","iopub.status.idle":"2021-06-21T01:21:35.292973Z","shell.execute_reply.started":"2021-06-21T01:21:35.284251Z","shell.execute_reply":"2021-06-21T01:21:35.291818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train = train.drop(drop_col, axis = 1)\n# gc.collect()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:35.294447Z","iopub.execute_input":"2021-06-21T01:21:35.294906Z","iopub.status.idle":"2021-06-21T01:21:35.304952Z","shell.execute_reply.started":"2021-06-21T01:21:35.294873Z","shell.execute_reply":"2021-06-21T01:21:35.304031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['square_feet'] = np.log(train['square_feet'])\ntest['square_feet'] = np.log(test['square_feet'])","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:35.306345Z","iopub.execute_input":"2021-06-21T01:21:35.306752Z","iopub.status.idle":"2021-06-21T01:21:36.980293Z","shell.execute_reply.started":"2021-06-21T01:21:35.306711Z","shell.execute_reply":"2021-06-21T01:21:36.979351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"le = LabelEncoder()\n\ntrain['primary_use'] = le.fit_transform(train['primary_use'])\ntest['primary_use'] = le.fit_transform(test['primary_use'])","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:36.98174Z","iopub.execute_input":"2021-06-21T01:21:36.982033Z","iopub.status.idle":"2021-06-21T01:21:56.596336Z","shell.execute_reply.started":"2021-06-21T01:21:36.982006Z","shell.execute_reply":"2021-06-21T01:21:56.595457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target = np.log1p(train['meter_reading'])\ntrain = train.drop(['meter_reading'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:56.597683Z","iopub.execute_input":"2021-06-21T01:21:56.598101Z","iopub.status.idle":"2021-06-21T01:21:57.979933Z","shell.execute_reply.started":"2021-06-21T01:21:56.598054Z","shell.execute_reply":"2021-06-21T01:21:57.979035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del le\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:57.981224Z","iopub.execute_input":"2021-06-21T01:21:57.981653Z","iopub.status.idle":"2021-06-21T01:21:58.124348Z","shell.execute_reply.started":"2021-06-21T01:21:57.981613Z","shell.execute_reply":"2021-06-21T01:21:58.121821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = reduce_mem_usage(train)\ntest = reduce_mem_usage(test)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:21:58.125507Z","iopub.execute_input":"2021-06-21T01:21:58.126003Z","iopub.status.idle":"2021-06-21T01:22:03.118471Z","shell.execute_reply.started":"2021-06-21T01:21:58.12597Z","shell.execute_reply":"2021-06-21T01:22:03.11742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.reset_index(drop=True)\ntest = test.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:22:03.119985Z","iopub.execute_input":"2021-06-21T01:22:03.120562Z","iopub.status.idle":"2021-06-21T01:22:03.95776Z","shell.execute_reply.started":"2021-06-21T01:22:03.120511Z","shell.execute_reply":"2021-06-21T01:22:03.956461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(sys.getsizeof(train))\nprint(sys.getsizeof(test))","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:22:03.95927Z","iopub.execute_input":"2021-06-21T01:22:03.959599Z","iopub.status.idle":"2021-06-21T01:22:03.969522Z","shell.execute_reply.started":"2021-06-21T01:22:03.959553Z","shell.execute_reply":"2021-06-21T01:22:03.96837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train.shape)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:22:03.971126Z","iopub.execute_input":"2021-06-21T01:22:03.971621Z","iopub.status.idle":"2021-06-21T01:22:03.99721Z","shell.execute_reply.started":"2021-06-21T01:22:03.971561Z","shell.execute_reply":"2021-06-21T01:22:03.996222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Modeling","metadata":{}},{"cell_type":"code","source":"'''\nX_tr, X_val, y_tr, y_val = train_test_split(train, target, test_size=0.2, random_state=666)\n\ndef create_model(trial):\n    num_leaves = trial.suggest_int('num_leaves', 2, 30)\n    n_estimators = trial.suggest_int('n_estimators', 50, 300)\n    learning_rate = trial.suggest_uniform('learning_rate', 0.0001, 0.99)\n    max_depth = trial.suggest_int('max_depth', 2, 10)\n    min_child_samples = trial.suggest_int('min_child_samples', 100, 1200)\n    min_data_in_leaf = trial.suggest_int('min_data_in_leaf', 5, 90)\n    bagging_freq = trial.suggest_int('bagging_freq', 1, 7)\n    bagging_fraction = trial.suggest_uniform('bagging_fraction', 0.0001, 1.0)\n    feature_fraction = trial.suggest_uniform('feature_fraction', 0.0001, 1.0)\n    subsample = trial.suggest_uniform('subsample', 0.1, 1.0)\n    colsample_bytree = trial.suggest_uniform('colsample_bytree', 0.1, 1.0)\n    \n    model = lgb.LGBMRegressor(\n        num_leaves=num_leaves,\n        n_estimators=n_estimators,\n        learning_rate=learning_rate,\n        max_depth=max_depth, \n        min_child_samples=min_child_samples, \n        min_data_in_leaf=min_data_in_leaf,\n        bagging_freq=bagging_freq,\n        bagging_fraction=bagging_fraction,\n        feature_fraction=feature_fraction,\n        subsample=subsample,\n        colsample_bytree=colsample_bytree,\n        metric='rsme',\n        random_state=666)\n    return model\n\ndef objective(trial):\n    model = create_model(trial)\n    model.fit(X_tr, y_tr)\n    y_pred = model.predict(X_val)\n    rsme = np.sqrt(mean_squared_error(y_pred, y_val))\n    return rsme\n\nstudy = optuna.create_study(direction='minimize')\nstudy.optimize(objective, n_trials=40)\nparams = study.best_params\nprint(params)\n'''","metadata":{"execution":{"iopub.status.busy":"2021-06-21T01:22:03.998599Z","iopub.execute_input":"2021-06-21T01:22:03.998943Z","iopub.status.idle":"2021-06-21T02:43:33.702642Z","shell.execute_reply.started":"2021-06-21T01:22:03.998912Z","shell.execute_reply":"2021-06-21T02:43:33.700948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"params = {'num_leaves': 30,\n          'n_estimators': 279,\n          'learning_rate': 0.41293292317272395,\n          'max_depth': 9,\n          'min_child_samples': 118,\n          'min_data_in_leaf': 74,\n          'bagging_freq': 1,\n          'bagging_fraction': 0.34909235383110854,\n          'feature_fraction': 0.7673641507626504,\n          'subsample': 0.7826605676058075,\n          'colsample_bytree': 0.31499443536061944,\n          'random_state': 666}","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:43:33.705842Z","iopub.execute_input":"2021-06-21T02:43:33.706342Z","iopub.status.idle":"2021-06-21T02:43:33.714985Z","shell.execute_reply.started":"2021-06-21T02:43:33.706273Z","shell.execute_reply":"2021-06-21T02:43:33.713436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cls = lgb.LGBMRegressor(**params)\ncls.fit(train, target)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:43:33.717006Z","iopub.execute_input":"2021-06-21T02:43:33.717547Z","iopub.status.idle":"2021-06-21T02:45:26.228682Z","shell.execute_reply.started":"2021-06-21T02:43:33.717504Z","shell.execute_reply":"2021-06-21T02:45:26.227616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del train, target, params\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:26.230501Z","iopub.execute_input":"2021-06-21T02:45:26.230952Z","iopub.status.idle":"2021-06-21T02:45:26.631277Z","shell.execute_reply.started":"2021-06-21T02:45:26.230907Z","shell.execute_reply":"2021-06-21T02:45:26.630174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lgb.plot_importance(cls)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:26.632984Z","iopub.execute_input":"2021-06-21T02:45:26.633432Z","iopub.status.idle":"2021-06-21T02:45:26.939912Z","shell.execute_reply.started":"2021-06-21T02:45:26.633383Z","shell.execute_reply":"2021-06-21T02:45:26.93881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submit","metadata":{}},{"cell_type":"code","source":"row_id = test['row_id']\n\ntest = test.drop(['row_id'], axis = 1)\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:26.941694Z","iopub.execute_input":"2021-06-21T02:45:26.942137Z","iopub.status.idle":"2021-06-21T02:45:28.358467Z","shell.execute_reply.started":"2021-06-21T02:45:26.942071Z","shell.execute_reply":"2021-06-21T02:45:28.357481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['hour'] = test['timestamp'].dt.hour\n# test['day'] = test['timestamp'].dt.day\n# test['weekend'] = test['timestamp'].dt.weekday\ntest['month'] = test['timestamp'].dt.month","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:28.359631Z","iopub.execute_input":"2021-06-21T02:45:28.359888Z","iopub.status.idle":"2021-06-21T02:45:44.242394Z","shell.execute_reply.started":"2021-06-21T02:45:28.359864Z","shell.execute_reply":"2021-06-21T02:45:44.241442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.drop(['timestamp', 'site_id'], axis=1)\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:44.243966Z","iopub.execute_input":"2021-06-21T02:45:44.244268Z","iopub.status.idle":"2021-06-21T02:45:46.351313Z","shell.execute_reply.started":"2021-06-21T02:45:44.244237Z","shell.execute_reply":"2021-06-21T02:45:46.350324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['building_mean'] = test['building_id'].map(building_mean)\ntest['building_median'] = test['building_id'].map(building_median)\ntest['building_std'] = test['building_id'].map(building_std)\n\ntest['building_min'] = test['building_id'].map(building_min)\ntest['building_max'] = test['building_id'].map(building_max)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:46.352566Z","iopub.execute_input":"2021-06-21T02:45:46.352855Z","iopub.status.idle":"2021-06-21T02:45:48.848419Z","shell.execute_reply.started":"2021-06-21T02:45:46.352828Z","shell.execute_reply":"2021-06-21T02:45:48.847453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del building_mean, building_median, building_std\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:48.849714Z","iopub.execute_input":"2021-06-21T02:45:48.850005Z","iopub.status.idle":"2021-06-21T02:45:48.989464Z","shell.execute_reply.started":"2021-06-21T02:45:48.849978Z","shell.execute_reply":"2021-06-21T02:45:48.988771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"row_id = row_id.reset_index(drop=True)\ntest = test.reset_index(drop=True)\n\ntest = reduce_mem_usage(test)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:48.990374Z","iopub.execute_input":"2021-06-21T02:45:48.990672Z","iopub.status.idle":"2021-06-21T02:45:57.160583Z","shell.execute_reply.started":"2021-06-21T02:45:48.99063Z","shell.execute_reply":"2021-06-21T02:45:57.159561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(pd.DataFrame([[i for i in dir()], [sys.getsizeof(eval(i)) for i in dir()]],\n                   index=['name','size']).T.sort_values('size', ascending=False).reset_index(drop=True).head(10))","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2021-06-21T02:45:57.161948Z","iopub.execute_input":"2021-06-21T02:45:57.16226Z","iopub.status.idle":"2021-06-21T02:45:57.211168Z","shell.execute_reply.started":"2021-06-21T02:45:57.16223Z","shell.execute_reply":"2021-06-21T02:45:57.210106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(test.shape)\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:57.218025Z","iopub.execute_input":"2021-06-21T02:45:57.218339Z","iopub.status.idle":"2021-06-21T02:45:57.242179Z","shell.execute_reply.started":"2021-06-21T02:45:57.218308Z","shell.execute_reply":"2021-06-21T02:45:57.24095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target = np.expm1(cls.predict(test))\n\nsubmission = pd.DataFrame(target, index=row_id, columns=['meter_reading'])\nsubmission.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:57.243947Z","iopub.execute_input":"2021-06-21T02:45:57.244354Z","iopub.status.idle":"2021-06-21T02:45:57.421086Z","shell.execute_reply.started":"2021-06-21T02:45:57.2443Z","shell.execute_reply":"2021-06-21T02:45:57.419488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del row_id\ngc.collect()\n\nsubmission = reduce_mem_usage(submission)","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:57.422221Z","iopub.status.idle":"2021-06-21T02:45:57.422686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('ASHRAE_submit.csv')","metadata":{"execution":{"iopub.status.busy":"2021-06-21T02:45:57.423854Z","iopub.status.idle":"2021-06-21T02:45:57.424268Z"},"trusted":true},"execution_count":null,"outputs":[]}]}