{"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":"code","source":"import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt, seaborn as sns\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-04-05T07:33:53.312860Z","iopub.execute_input":"2022-04-05T07:33:53.313250Z","iopub.status.idle":"2022-04-05T07:33:53.324694Z","shell.execute_reply.started":"2022-04-05T07:33:53.313209Z","shell.execute_reply":"2022-04-05T07:33:53.323818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bm = pd.read_csv(\"../input/ashrae-energy-prediction/building_metadata.csv\")\nbm","metadata":{"execution":{"iopub.status.busy":"2022-04-05T07:29:23.770924Z","iopub.execute_input":"2022-04-05T07:29:23.771294Z","iopub.status.idle":"2022-04-05T07:29:23.810365Z","shell.execute_reply.started":"2022-04-05T07:29:23.77126Z","shell.execute_reply":"2022-04-05T07:29:23.809845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"../input/ashrae-energy-prediction/train.csv\")\ntrain","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:22:59.749545Z","iopub.execute_input":"2022-04-05T05:22:59.749831Z","iopub.status.idle":"2022-04-05T05:23:14.736139Z","shell.execute_reply.started":"2022-04-05T05:22:59.7498Z","shell.execute_reply":"2022-04-05T05:23:14.735113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv(\"../input/ashrae-energy-prediction/test.csv\")\ntest","metadata":{"execution":{"iopub.status.busy":"2022-04-05T07:29:30.179539Z","iopub.execute_input":"2022-04-05T07:29:30.180153Z","iopub.status.idle":"2022-04-05T07:30:01.755683Z","shell.execute_reply.started":"2022-04-05T07:29:30.180116Z","shell.execute_reply":"2022-04-05T07:30:01.754852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"w_train = pd.read_csv(\"../input/ashrae-energy-prediction/weather_train.csv\")\nw_train","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:23:28.509461Z","iopub.execute_input":"2022-04-05T05:23:28.509738Z","iopub.status.idle":"2022-04-05T05:23:28.817248Z","shell.execute_reply.started":"2022-04-05T05:23:28.509708Z","shell.execute_reply":"2022-04-05T05:23:28.816265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"w_test = pd.read_csv(\"../input/ashrae-energy-prediction/weather_test.csv\")\nw_test","metadata":{"execution":{"iopub.status.busy":"2022-04-05T07:30:16.371727Z","iopub.execute_input":"2022-04-05T07:30:16.373185Z","iopub.status.idle":"2022-04-05T07:30:16.902731Z","shell.execute_reply.started":"2022-04-05T07:30:16.373129Z","shell.execute_reply":"2022-04-05T07:30:16.901909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_train = bm.merge(train, how = \"left\", on = [\"building_id\"]).merge(w_train, how = \"left\", on = [\"site_id\",\"timestamp\"])\ngb_train","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:23:32.039875Z","iopub.execute_input":"2022-04-05T05:23:32.040247Z","iopub.status.idle":"2022-04-05T05:23:44.438431Z","shell.execute_reply.started":"2022-04-05T05:23:32.040204Z","shell.execute_reply":"2022-04-05T05:23:44.437363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:02:40.185756Z","iopub.execute_input":"2022-04-05T05:02:40.186388Z","iopub.status.idle":"2022-04-05T05:02:51.493434Z","shell.execute_reply.started":"2022-04-05T05:02:40.18635Z","shell.execute_reply":"2022-04-05T05:02:51.49261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_train.info()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:03:11.409782Z","iopub.execute_input":"2022-04-05T05:03:11.410676Z","iopub.status.idle":"2022-04-05T05:03:11.427454Z","shell.execute_reply.started":"2022-04-05T05:03:11.410627Z","shell.execute_reply":"2022-04-05T05:03:11.426354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_train[\"site_id\"] = gb_train[\"site_id\"].astype(\"category\")\ngb_train[\"building_id\"] = gb_train[\"building_id\"].astype(\"category\")\ngb_train[\"primary_use\"] = gb_train[\"primary_use\"].astype(\"category\")\ngb_train[\"meter\"] = gb_train[\"meter\"].astype(\"category\")\ngb_train[\"timestamp\"] = gb_train[\"timestamp\"].astype(\"category\") \ngb_train[\"year_built\"] = gb_train[\"year_built\"].astype(\"category\")\ngb_train.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:23:56.423481Z","iopub.execute_input":"2022-04-05T05:23:56.42379Z","iopub.status.idle":"2022-04-05T05:24:02.464097Z","shell.execute_reply.started":"2022-04-05T05:23:56.423758Z","shell.execute_reply":"2022-04-05T05:24:02.463019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"p = sns.boxplot(x=\"meter_reading\", data=gb_train)","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:03:38.793291Z","iopub.execute_input":"2022-04-05T05:03:38.793598Z","iopub.status.idle":"2022-04-05T05:03:48.701371Z","shell.execute_reply.started":"2022-04-05T05:03:38.793564Z","shell.execute_reply":"2022-04-05T05:03:48.700067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q = sns.boxplot(x=\"air_temperature\", data=gb_train)","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:03:48.702873Z","iopub.execute_input":"2022-04-05T05:03:48.703209Z","iopub.status.idle":"2022-04-05T05:03:50.053148Z","shell.execute_reply.started":"2022-04-05T05:03:48.703164Z","shell.execute_reply":"2022-04-05T05:03:50.052205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_train2 = gb_train[[\"meter\",\"meter_reading\",\"air_temperature\"]]\ngb_train2","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:24:16.113043Z","iopub.execute_input":"2022-04-05T05:24:16.113826Z","iopub.status.idle":"2022-04-05T05:24:17.36198Z","shell.execute_reply.started":"2022-04-05T05:24:16.113777Z","shell.execute_reply":"2022-04-05T05:24:17.360954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_train2.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:24:30.071942Z","iopub.execute_input":"2022-04-05T05:24:30.072382Z","iopub.status.idle":"2022-04-05T05:24:30.198042Z","shell.execute_reply.started":"2022-04-05T05:24:30.07234Z","shell.execute_reply":"2022-04-05T05:24:30.197045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(gb_train2.isnull().sum()/len(gb_train2)*100).to_frame('persentase missing')","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:24:34.384168Z","iopub.execute_input":"2022-04-05T05:24:34.384857Z","iopub.status.idle":"2022-04-05T05:24:34.511385Z","shell.execute_reply.started":"2022-04-05T05:24:34.384798Z","shell.execute_reply":"2022-04-05T05:24:34.510526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(gb_train2.isnull(), cbar=False)\nplt.title('Heatmap Missing Value')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:29:41.265358Z","iopub.execute_input":"2022-04-05T05:29:41.265816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_train2[\"air_temperature\"].fillna(gb_train2[\"air_temperature\"].mean(), inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:29:34.959288Z","iopub.execute_input":"2022-04-05T05:29:34.959878Z","iopub.status.idle":"2022-04-05T05:29:35.029505Z","shell.execute_reply.started":"2022-04-05T05:29:34.959838Z","shell.execute_reply":"2022-04-05T05:29:35.028832Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_train2.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:29:38.537181Z","iopub.execute_input":"2022-04-05T05:29:38.537812Z","iopub.status.idle":"2022-04-05T05:29:38.556295Z","shell.execute_reply.started":"2022-04-05T05:29:38.537772Z","shell.execute_reply":"2022-04-05T05:29:38.555274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(gb_train2.isnull().sum()/len(gb_train2)).to_frame('persentase missing')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(gb_train2.isnull(), cbar=False)\nplt.title('Heatmap Missing Value')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T05:26:31.383163Z","iopub.execute_input":"2022-04-05T05:26:31.383502Z","iopub.status.idle":"2022-04-05T05:27:26.722007Z","shell.execute_reply.started":"2022-04-05T05:26:31.383464Z","shell.execute_reply":"2022-04-05T05:27:26.721362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"p = sns.scatterplot(x=gb_train2[\"meter_reading\"], y=gb_train2[\"air_temp\"], hue = gb_train2[\"meter\"])","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_train2.corr()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr2 = gb_train2.corr() \nplt.figure(figsize=(12, 10))\nsns.heatmap(corr2[(corr2 >= 0.5) | (corr2 <= -0.4)], \n            cmap='viridis', vmax=1.0, vmin=-1.0, linewidths=0.1,\n            annot=True, annot_kws={\"size\": 14}, square=True);","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_test = bm.merge(test, how = \"left\", on = [\"building_id\"]).merge(w_test, how = \"left\", on = [\"site_id\",\"timestamp\"])\ngb_test","metadata":{"execution":{"iopub.status.busy":"2022-04-05T07:30:23.427293Z","iopub.execute_input":"2022-04-05T07:30:23.427623Z","iopub.status.idle":"2022-04-05T07:31:00.851425Z","shell.execute_reply.started":"2022-04-05T07:30:23.427592Z","shell.execute_reply":"2022-04-05T07:31:00.850279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_test.describe()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_test.info()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_test[\"site_id\"] = gb_test[\"site_id\"].astype(\"category\")\ngb_test[\"building_id\"] = gb_test[\"building_id\"].astype(\"category\")\ngb_test[\"primary_use\"] = gb_test[\"primary_use\"].astype(\"category\")\ngb_test[\"meter\"] = gb_test[\"meter\"].astype(\"category\")\ngb_test[\"timestamp\"] = gb_test[\"timestamp\"].astype(\"category\") \ngb_test[\"year_built\"] = gb_test[\"year_built\"].astype(\"category\")\ngb_test.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-04-05T07:31:05.096947Z","iopub.execute_input":"2022-04-05T07:31:05.097681Z","iopub.status.idle":"2022-04-05T07:31:18.069587Z","shell.execute_reply.started":"2022-04-05T07:31:05.097624Z","shell.execute_reply":"2022-04-05T07:31:18.068524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"p = sns.boxplot(x=\"wind_speed\", data=gb_test)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q = sns.boxplot(x=\"air_temperature\", data=gb_test)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_test2 = gb_test[[\"meter\",\"wind_speed\",\"air_temperature\"]]\ngb_test2","metadata":{"execution":{"iopub.status.busy":"2022-04-05T07:32:26.750262Z","iopub.execute_input":"2022-04-05T07:32:26.750849Z","iopub.status.idle":"2022-04-05T07:32:26.776828Z","shell.execute_reply.started":"2022-04-05T07:32:26.750806Z","shell.execute_reply":"2022-04-05T07:32:26.775716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_test2.isnull().sum()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(gb_test2.isnull().sum()/len(gb_test2)*100).to_frame('persentase missing')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(gb_test2.isnull(), cbar=False)\nplt.title('Heatmap Missing Value')\nplt.show()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_test2[\"air_temperature\"].fillna(gb_test2[\"air_temperature\"].mean(), inplace = True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_test2[\"wind_speed\"].fillna(gb_test2[\"wind_speed\"].mean(), inplace = True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_test2.isnull().sum()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(gb_test2.isnull().sum()/len(gb_test2)).to_frame('persentase missing')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(gb_test2.isnull(), cbar=False)\nplt.title('Heatmap Missing Value')\nplt.show()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"p = sns.scatterplot(x=gb_test2[\"wind_speed\"], y=gb_test2[\"air_temp\"], hue = gb_test2[\"meter\"])","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gb_test2.corr()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr2 = gb_test2.corr()\nplt.figure(figsize=(12, 10))\nsns.heatmap(corr2[(corr2 >= 0.5) | (corr2 <= -0.4)], \n            cmap='viridis', vmax=1.0, vmin=-1.0, linewidths=0.1,\n            annot=True, annot_kws={\"size\": 14}, square=True);","metadata":{},"execution_count":null,"outputs":[]}]}