{"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":"# **Excellence in Research Award (Phase II)**","metadata":{"id":"2zkBYIcPPe-j"}},{"cell_type":"markdown","source":"This year’s WiDS Datathon, organized by the WiDS Worldwide team, Stanford University, Harvard University IACS, and the WiDS Datathon Committee, will address the multi-faceted impacts of climate change. The WiDS Datathon Committee is partnering with experts from many disciplines at Climate Change AI (CCAI), Lawrence Berkeley National Laboratory (Berkeley Lab), US Environmental Protection Agency (EPA), and MIT Critical Data. Phase I of this year's datathon focused on an important way to mitigate the effects of climate change - improving building energy efficiency through forecasting usage. In the WiDS Datathon Excellence in Research Award (Phase II), we will broaden our focus to examine the impacts of climate change across multiple domains.","metadata":{"id":"aJN3vcAHPfER"}},{"cell_type":"markdown","source":"US Environmental Protection Agency (EPA): weather, air pollutant, and census data\nMIT Critical Data: CDC county level COVID data\nClimate Change AI: Fine grained building energy usage data","metadata":{"id":"BGPkk4lcPfHP"}},{"cell_type":"markdown","source":"# <span style=\"color:#FFC300;\">***Research Award***<span>\n_**<span style=\"color:#009dc7;\">I will be grateful if you rate this analysis</span>**_  🔥\n## <span style=\"color:#FFC300;\">**Plan**<span>\n<a id=\"table-of-contents\"></a>\n- [1. Basic EDA](#1)\n- [2. Energy data](#2)\n- [3. Building stock data](#3)\n- [4. Mixed data](#4) \n- [5. Fill NaN](#5) \n- [6. The importance of features](#6) \n","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt","metadata":{"id":"WesjnSdPPQoA","execution":{"iopub.status.busy":"2022-08-09T08:23:38.907799Z","iopub.execute_input":"2022-08-09T08:23:38.908212Z","iopub.status.idle":"2022-08-09T08:23:39.921296Z","shell.execute_reply.started":"2022-08-09T08:23:38.908124Z","shell.execute_reply":"2022-08-09T08:23:39.920462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv(\"/kaggle/input/phase-ii-widsdatathon2022/ccai/ccai/data.csv\", delimiter=',', encoding='utf8')","metadata":{"id":"LAgvjrpOPQql","execution":{"iopub.status.busy":"2022-08-09T08:23:43.679205Z","iopub.execute_input":"2022-08-09T08:23:43.681035Z","iopub.status.idle":"2022-08-09T08:23:44.474971Z","shell.execute_reply.started":"2022-08-09T08:23:43.680981Z","shell.execute_reply":"2022-08-09T08:23:44.473870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"functions","metadata":{"id":"qpro02uEP7Hm"}},{"cell_type":"code","source":"def nan_zero_info(data):\n    print(f'нулей в датасете найдено\\n:{data.isnull().sum()}\\n')\n    print(f'NaN в датасете:\\n {data.isna().sum()}\\n')\n    print(f\"Типы  в датасете:\\n {data.dtypes}\\n\")","metadata":{"id":"jdJL_bQuP6hb","execution":{"iopub.status.busy":"2022-08-09T05:49:32.013620Z","iopub.execute_input":"2022-08-09T05:49:32.013951Z","iopub.status.idle":"2022-08-09T05:49:32.019666Z","shell.execute_reply.started":"2022-08-09T05:49:32.013927Z","shell.execute_reply":"2022-08-09T05:49:32.018496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The dataset contains ~50K observations, individual building level gas use in 2019, individual\nbuildings footprints and attributes and relevant local weather data. It was created by merging\nthree datasets, see below. Only residential multi-family buildings were selected.\n","metadata":{"id":"CA5De7W8P8x9"}},{"cell_type":"markdown","source":"# **Basic EDA** <a id=\"1\"></a>","metadata":{}},{"cell_type":"code","source":"data","metadata":{"id":"IewMrUItPQyl","outputId":"c8e7d695-3232-404c-88b4-99d54f67a2e1","execution":{"iopub.status.busy":"2022-08-09T05:49:34.593023Z","iopub.execute_input":"2022-08-09T05:49:34.593372Z","iopub.status.idle":"2022-08-09T05:49:34.629044Z","shell.execute_reply.started":"2022-08-09T05:49:34.593348Z","shell.execute_reply":"2022-08-09T05:49:34.628213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.pop('id')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:23:47.384912Z","iopub.execute_input":"2022-08-09T08:23:47.385265Z","iopub.status.idle":"2022-08-09T08:23:47.406329Z","shell.execute_reply.started":"2022-08-09T08:23:47.385239Z","shell.execute_reply":"2022-08-09T08:23:47.405201Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.sample(5)","metadata":{"id":"LIwbD1mEPQ1H","outputId":"e7932405-0a03-4742-c56b-280739eaac01","execution":{"iopub.status.busy":"2022-08-09T05:49:40.905013Z","iopub.execute_input":"2022-08-09T05:49:40.905591Z","iopub.status.idle":"2022-08-09T05:49:40.933884Z","shell.execute_reply.started":"2022-08-09T05:49:40.905558Z","shell.execute_reply":"2022-08-09T05:49:40.933243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nan_zero_info(data)","metadata":{"id":"y57x85tIQMn3","outputId":"ed5e088e-846f-47d8-c728-cc2ed5b9346c","execution":{"iopub.status.busy":"2022-08-09T05:49:50.677727Z","iopub.execute_input":"2022-08-09T05:49:50.678064Z","iopub.status.idle":"2022-08-09T05:49:50.725219Z","shell.execute_reply.started":"2022-08-09T05:49:50.678037Z","shell.execute_reply":"2022-08-09T05:49:50.724333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for name_col in data.columns:\n    if name_col == 'geometry' or name_col == 'qq_dict':\n        continue\n    print(f'The most frequent value in the data ({name_col}): {data[name_col].value_counts().idxmax()}')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T06:07:08.248787Z","iopub.execute_input":"2022-08-09T06:07:08.249083Z","iopub.status.idle":"2022-08-09T06:07:08.290822Z","shell.execute_reply.started":"2022-08-09T06:07:08.249060Z","shell.execute_reply":"2022-08-09T06:07:08.289720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.describe()","metadata":{"id":"dIxubphwQBQg","outputId":"f0676c01-6e41-4f92-f643-b39f4275d1c7","execution":{"iopub.status.busy":"2022-08-08T13:55:59.107845Z","iopub.execute_input":"2022-08-08T13:55:59.108334Z","iopub.status.idle":"2022-08-08T13:55:59.201662Z","shell.execute_reply.started":"2022-08-08T13:55:59.108280Z","shell.execute_reply":"2022-08-08T13:55:59.199971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"1 consumption\t\n\nThe spread is too large.The average consumption value was 52.3, while the maximum value was 199(200)\n\n\n2 delivery_points\n\nThe average value of apartments is 15.The maximum network of apartments was 297\n\n3 height\t\n\nHeight 0? Emissions! the average height is 17.5 m .The maximum height of the building is 115.6\n\n4 floors\t\n\nThe average number of floors is only 6","metadata":{}},{"cell_type":"code","source":"data.corr().style.background_gradient(cmap='coolwarm').set_precision(2)","metadata":{"id":"ybjfUYRIQBTN","outputId":"da27c759-6723-4244-b2f2-34eaee0741d7","execution":{"iopub.status.busy":"2022-07-25T12:20:38.872328Z","iopub.execute_input":"2022-07-25T12:20:38.873200Z","iopub.status.idle":"2022-07-25T12:20:38.968067Z","shell.execute_reply.started":"2022-07-25T12:20:38.873150Z","shell.execute_reply":"2022-07-25T12:20:38.966731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"1 height and floors strongly correlate, which is logical.\n\n\n2 roof_mate and wall_mart also correlate strongly\n\n\n3 height and alt_prec do not correlate.This is strange.We don't have an exact height match","metadata":{}},{"cell_type":"code","source":"cat_cols, num_cols = data.dtypes[data.dtypes == 'object'].keys(), data.dtypes[data.dtypes != 'object'].keys()\n\nnum_data = data.select_dtypes(np.number)\ncat_data = data.select_dtypes('object')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:27:00.798814Z","iopub.execute_input":"2022-08-09T08:27:00.799174Z","iopub.status.idle":"2022-08-09T08:27:00.815044Z","shell.execute_reply.started":"2022-08-09T08:27:00.799147Z","shell.execute_reply":"2022-08-09T08:27:00.813463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_data","metadata":{"execution":{"iopub.status.busy":"2022-08-09T05:56:25.820724Z","iopub.execute_input":"2022-08-09T05:56:25.821046Z","iopub.status.idle":"2022-08-09T05:56:25.837819Z","shell.execute_reply.started":"2022-08-09T05:56:25.821022Z","shell.execute_reply":"2022-08-09T05:56:25.836886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_data","metadata":{"execution":{"iopub.status.busy":"2022-08-09T05:56:42.020446Z","iopub.execute_input":"2022-08-09T05:56:42.020751Z","iopub.status.idle":"2022-08-09T05:56:42.034838Z","shell.execute_reply.started":"2022-08-09T05:56:42.020728Z","shell.execute_reply":"2022-08-09T05:56:42.034019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"data.index.is_unique, data.index.is_monotonic","metadata":{"execution":{"iopub.status.busy":"2022-08-09T06:10:43.187743Z","iopub.execute_input":"2022-08-09T06:10:43.188057Z","iopub.status.idle":"2022-08-09T06:10:43.193802Z","shell.execute_reply.started":"2022-08-09T06:10:43.188033Z","shell.execute_reply":"2022-08-09T06:10:43.192820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Energy data** <a id=\"2\"></a>","metadata":{"id":"qwwqgsOHi8Nj"}},{"cell_type":"markdown","source":"consumption Yearly gas consumption in MWh \n\n\ndelivery_points Number of flats connected to the gas network ","metadata":{"id":"sfLz6iuJjnw9"}},{"cell_type":"code","source":"print(f'The city with the highest gas consumption:{data[\"city_name\"].value_counts().idxmax()}')\nprint(f'The largest annual gas consumption in MWh:',data['consumption'].value_counts().idxmax())\nprint(f'The most common type:',data['type'].value_counts().idxmax())\nprint(f'The largest number of apartments connected to the network:',data['delivery_points'].value_counts().idxmax())","metadata":{"id":"zGilSdwao8mb","outputId":"44baf2a1-365b-4265-f32e-2b93c8037a2a","execution":{"iopub.status.busy":"2022-08-08T13:56:17.202958Z","iopub.execute_input":"2022-08-08T13:56:17.203829Z","iopub.status.idle":"2022-08-08T13:56:17.230236Z","shell.execute_reply.started":"2022-08-08T13:56:17.203783Z","shell.execute_reply":"2022-08-08T13:56:17.229366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"id":"GgMUu9qgp0HC"}},{"cell_type":"code","source":"data.loc[data[\"city_name\"] == 'TOULOUSE']","metadata":{"id":"TksE-sHUqNp-","outputId":"335f454d-b4fd-4959-97bb-0c2dd08daf9a","execution":{"iopub.status.busy":"2022-07-25T12:20:39.069463Z","iopub.execute_input":"2022-07-25T12:20:39.070303Z","iopub.status.idle":"2022-07-25T12:20:39.114818Z","shell.execute_reply.started":"2022-07-25T12:20:39.070252Z","shell.execute_reply":"2022-07-25T12:20:39.113677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"data.loc[data['consumption'] == 48.2193]","metadata":{"id":"9MkWLjwiqXl4","outputId":"bffa8683-6194-4e63-eee2-6a03e99c9935","execution":{"iopub.status.busy":"2022-07-25T12:20:39.116554Z","iopub.execute_input":"2022-07-25T12:20:39.117257Z","iopub.status.idle":"2022-07-25T12:20:39.146821Z","shell.execute_reply.started":"2022-07-25T12:20:39.117214Z","shell.execute_reply":"2022-07-25T12:20:39.145691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Basically it is the city of METZ with deliv. points = 10","metadata":{}},{"cell_type":"code","source":"data.loc[data['type'] == 'Résidentiel']","metadata":{"id":"OrmLOoyHqXos","outputId":"cba3bf71-45cb-415f-881b-b66fb36b916f","execution":{"iopub.status.busy":"2022-07-25T12:20:39.148325Z","iopub.execute_input":"2022-07-25T12:20:39.149358Z","iopub.status.idle":"2022-07-25T12:20:39.186403Z","shell.execute_reply.started":"2022-07-25T12:20:39.149314Z","shell.execute_reply":"2022-07-25T12:20:39.185571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"data.loc[data['delivery_points'] == 10]","metadata":{"id":"RnXRMNXkqXtp","outputId":"6a45cf5a-1fa6-4c60-f231-cc6bf6d16aad","execution":{"iopub.status.busy":"2022-07-25T12:20:39.187948Z","iopub.execute_input":"2022-07-25T12:20:39.188640Z","iopub.status.idle":"2022-07-25T12:20:39.216914Z","shell.execute_reply.started":"2022-07-25T12:20:39.188594Z","shell.execute_reply":"2022-07-25T12:20:39.215894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"So small delivery_points for Résidentiel","metadata":{}},{"cell_type":"code","source":"data['consumption'].value_counts().sort_values(ascending=False)","metadata":{"id":"ipbLIlj8jA2p","outputId":"40fd5423-376b-4937-c40d-118eec356874","execution":{"iopub.status.busy":"2022-07-25T12:20:39.218470Z","iopub.execute_input":"2022-07-25T12:20:39.218919Z","iopub.status.idle":"2022-07-25T12:20:39.239219Z","shell.execute_reply.started":"2022-07-25T12:20:39.218876Z","shell.execute_reply":"2022-07-25T12:20:39.237843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (12,6))\nsns.histplot(data=data, x = 'consumption')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T06:05:00.457046Z","iopub.execute_input":"2022-08-09T06:05:00.457380Z","iopub.status.idle":"2022-08-09T06:05:00.669225Z","shell.execute_reply.started":"2022-08-09T06:05:00.457357Z","shell.execute_reply":"2022-08-09T06:05:00.668165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"data['type'].value_counts().sort_values(ascending=False)","metadata":{"id":"o4TaazsojA5B","outputId":"d91f2067-fe28-442c-9167-5974bf1ba4fe","execution":{"iopub.status.busy":"2022-07-25T12:20:39.240791Z","iopub.execute_input":"2022-07-25T12:20:39.241427Z","iopub.status.idle":"2022-07-25T12:20:39.253797Z","shell.execute_reply.started":"2022-07-25T12:20:39.241394Z","shell.execute_reply":"2022-07-25T12:20:39.252620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (12,6))\nsns.countplot(data=data, x = 'type')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T05:58:44.854353Z","iopub.execute_input":"2022-08-09T05:58:44.854658Z","iopub.status.idle":"2022-08-09T05:58:45.018911Z","shell.execute_reply.started":"2022-08-09T05:58:44.854635Z","shell.execute_reply":"2022-08-09T05:58:45.017845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['city_name'].value_counts().sort_values(ascending=False).loc[lambda x: x>500]","metadata":{"id":"CHdVNpZWjA7c","outputId":"c6308be7-4b14-4820-ab94-86aae7e0f46e","execution":{"iopub.status.busy":"2022-07-25T12:20:39.255158Z","iopub.execute_input":"2022-07-25T12:20:39.255556Z","iopub.status.idle":"2022-07-25T12:20:39.268357Z","shell.execute_reply.started":"2022-07-25T12:20:39.255528Z","shell.execute_reply":"2022-07-25T12:20:39.267319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"id":"DN33T6LSp0vQ"}},{"cell_type":"code","source":"ax = plt.figure(figsize = (25,10))\nsns.countplot(data=data, x = 'delivery_points')","metadata":{"id":"VKnmHeI1jA95","outputId":"38b7f4ca-536e-45fc-81c4-775d70a3e841","execution":{"iopub.status.busy":"2022-07-25T12:20:39.269716Z","iopub.execute_input":"2022-07-25T12:20:39.270211Z","iopub.status.idle":"2022-07-25T12:20:40.661706Z","shell.execute_reply.started":"2022-07-25T12:20:39.270174Z","shell.execute_reply":"2022-07-25T12:20:40.660643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We see a smooth decline from 10 to 200\n","metadata":{"id":"nL9paeK7p1aK"}},{"cell_type":"code","source":"ax1,ax2 = plt.figure(figsize = (12,8)).subplots(1,2)\nsns.histplot(data=data, x = 'consumption',ax=ax1)\nsns.boxplot(data=data,x='consumption',ax=ax2) ","metadata":{"id":"Du_JujQrLpCU","outputId":"d7d41e8a-1a3e-4411-c5cd-662adea2bb7c","execution":{"iopub.status.busy":"2022-07-25T12:20:40.663550Z","iopub.execute_input":"2022-07-25T12:20:40.664039Z","iopub.status.idle":"2022-07-25T12:20:41.054591Z","shell.execute_reply.started":"2022-07-25T12:20:40.663994Z","shell.execute_reply":"2022-07-25T12:20:41.053789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Distribution without emissions and small std.The distributions of the graph are two-humped peaks at 10 and 100 consumptions.What clearly divides the rich (spend a lot) and the poor (spend very little","metadata":{"id":"aykAoxnCp13G"}},{"cell_type":"code","source":"sns.lineplot(data = data, x = 'delivery_points', y = 'consumption' )","metadata":{"execution":{"iopub.status.busy":"2022-08-09T06:48:21.391380Z","iopub.execute_input":"2022-08-09T06:48:21.391709Z","iopub.status.idle":"2022-08-09T06:48:24.001302Z","shell.execute_reply.started":"2022-08-09T06:48:21.391686Z","shell.execute_reply":"2022-08-09T06:48:23.999505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"id":"IqhNREKNp2VM"}},{"cell_type":"code","source":"stats_by_city_consumption = data.groupby(\"city_name\")[\"consumption\"].agg([\"mean\", \"median\", \"min\", \"max\", \"count\"])\nstats_by_city_delivery_points = data.groupby(\"city_name\")[\"delivery_points\"].agg([\"mean\", \"median\", \"min\", \"max\", \"count\"])\nstats_by_type_consumption = data.groupby(\"type\")[\"consumption\"].agg([\"mean\", \"median\", \"min\", \"max\", \"count\"])\nstats_by_type_delivery_points = data.groupby(\"type\")[\"delivery_points\"].agg([\"mean\", \"median\", \"min\", \"max\", \"count\"])\nstats_by_city_consumption","metadata":{"id":"gzbHX8comrzI","outputId":"8c4e1912-ea96-45d3-c254-654f654085c0","execution":{"iopub.status.busy":"2022-07-25T12:23:03.287737Z","iopub.execute_input":"2022-07-25T12:23:03.288275Z","iopub.status.idle":"2022-07-25T12:23:03.353062Z","shell.execute_reply.started":"2022-07-25T12:23:03.288231Z","shell.execute_reply":"2022-07-25T12:23:03.351939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"ABLON-SUR-SEINE spends the most gas on average.the city of ERAGNY practically does not use gas.Most likely there are few people there or everything is on electricity","metadata":{"id":"O14MabtKp2we"}},{"cell_type":"code","source":"stats_by_city_delivery_points","metadata":{"id":"ehIWnzeEnlfR","outputId":"1718b9b0-3c45-4155-fd1e-15d9e5680955","execution":{"iopub.status.busy":"2022-07-25T12:23:03.354167Z","iopub.execute_input":"2022-07-25T12:23:03.354461Z","iopub.status.idle":"2022-07-25T12:23:03.369616Z","shell.execute_reply.started":"2022-07-25T12:23:03.354436Z","shell.execute_reply":"2022-07-25T12:23:03.368014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In ERAGNY, only 12 houses use gas, which is very little","metadata":{"id":"HKQGGiwtp3JY"}},{"cell_type":"code","source":"stats_by_type_consumption","metadata":{"id":"KSEC01gPnlhq","outputId":"d2e2d010-6166-4b3c-e41f-50e2480e0f6f","execution":{"iopub.status.busy":"2022-07-25T12:23:03.371182Z","iopub.execute_input":"2022-07-25T12:23:03.371522Z","iopub.status.idle":"2022-07-25T12:23:03.389204Z","shell.execute_reply.started":"2022-07-25T12:23:03.371490Z","shell.execute_reply":"2022-07-25T12:23:03.388067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Religieux contains the most gas costs.The minimum costs go to the Sportif type","metadata":{"id":"3UghhFyLp3hQ"}},{"cell_type":"code","source":"stats_by_type_delivery_points","metadata":{"id":"39k1okEnoYwY","outputId":"f8cb0924-38bd-4d21-cb19-0094ba72d956","execution":{"iopub.status.busy":"2022-07-25T12:23:03.390678Z","iopub.execute_input":"2022-07-25T12:23:03.391022Z","iopub.status.idle":"2022-07-25T12:23:03.408796Z","shell.execute_reply.started":"2022-07-25T12:23:03.390989Z","shell.execute_reply":"2022-07-25T12:23:03.407569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"ax1,ax2,ax3,ax4 = plt.figure(figsize = (16,5)).subplots(1,4)\nsns.lineplot(data=data, x=\"height\", y=\"consumption\", ax=ax1)\nsns.lineplot(data=data, x=\"floors\",y=\"consumption\", ax=ax2)\nsns.lineplot(data=data, x=\"alt_prec\", y=\"consumption\", ax=ax3)\nsns.lineplot(data=data, x=\"roof_mat\", y=\"consumption\", ax=ax4)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-09T07:08:22.021525Z","iopub.execute_input":"2022-08-09T07:08:22.021832Z","iopub.status.idle":"2022-08-09T07:08:35.138368Z","shell.execute_reply.started":"2022-08-09T07:08:22.021808Z","shell.execute_reply":"2022-08-09T07:08:35.137309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"id":"ZAAGf0bNp38q"}},{"cell_type":"code","source":"data.groupby(by='city_name',dropna=True).sum().sort_values(by='consumption',ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T06:40:39.954215Z","iopub.execute_input":"2022-08-09T06:40:39.954911Z","iopub.status.idle":"2022-08-09T06:40:39.986505Z","shell.execute_reply.started":"2022-08-09T06:40:39.954886Z","shell.execute_reply":"2022-08-09T06:40:39.985587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Building stock data** <a id=\"3\"></a>","metadata":{"id":"zPSqVIKqj1iT"}},{"cell_type":"markdown","source":"height Building height (ground to lowest roof point)\n\n\nage Building age \n\n\nfloors Number of floors of the building \n\n\nalt_prec Altimetric precision of the building height \n\n\nwall_mat Materials of the wall \n\n\nroof_mat Materials of the roof \n","metadata":{"id":"HV_EAvGfj1ru"}},{"cell_type":"code","source":"print(f'The most frequent height of buildings:{data[\"height\"].value_counts().idxmax()}')\nprint(f'The most frequent age of buildings:',data['age'].value_counts().idxmax())\nprint(f'The most frequent floors of buildings:',data['floors'].value_counts().idxmax())\nprint(f'The most frequent alt_prec of buildings:',data['alt_prec'].value_counts().idxmax())\nprint(f'More frequent walls material in buildings:',data['wall_mat'].value_counts().idxmax())\nprint(f'More frequent roofs material in buildings:',data['roof_mat'].value_counts().idxmax())","metadata":{"id":"RuMPr2IMssYe","outputId":"0df38378-545f-4c3f-b920-d2ca4c802763","execution":{"iopub.status.busy":"2022-07-25T12:23:03.523432Z","iopub.execute_input":"2022-07-25T12:23:03.524161Z","iopub.status.idle":"2022-07-25T12:23:03.542232Z","shell.execute_reply.started":"2022-07-25T12:23:03.524115Z","shell.execute_reply":"2022-07-25T12:23:03.541240Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"id":"sRfItBKg19Lb"}},{"cell_type":"code","source":"data['height'].value_counts().loc[lambda x: x > 450]","metadata":{"id":"icMmtftAssbT","outputId":"4a414a9f-2643-4f33-9995-f4001e52e3f7","execution":{"iopub.status.busy":"2022-07-25T12:23:03.543155Z","iopub.execute_input":"2022-07-25T12:23:03.543456Z","iopub.status.idle":"2022-07-25T12:23:03.555146Z","shell.execute_reply.started":"2022-07-25T12:23:03.543430Z","shell.execute_reply":"2022-07-25T12:23:03.553937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data = data, x ='height')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T07:09:23.863007Z","iopub.execute_input":"2022-08-09T07:09:23.863353Z","iopub.status.idle":"2022-08-09T07:09:24.330203Z","shell.execute_reply.started":"2022-08-09T07:09:23.863316Z","shell.execute_reply":"2022-08-09T07:09:24.327584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['floors'].value_counts().loc[lambda x: x > 4500]","metadata":{"id":"WzWXiJ5syyYQ","outputId":"b92bf5da-eab3-4a34-9cf7-e2869ee19f9d","execution":{"iopub.status.busy":"2022-07-25T12:23:03.556517Z","iopub.execute_input":"2022-07-25T12:23:03.557082Z","iopub.status.idle":"2022-07-25T12:23:03.567606Z","shell.execute_reply.started":"2022-07-25T12:23:03.557037Z","shell.execute_reply":"2022-07-25T12:23:03.566641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data = data, x ='floors')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T07:09:32.492886Z","iopub.execute_input":"2022-08-09T07:09:32.493215Z","iopub.status.idle":"2022-08-09T07:09:33.055057Z","shell.execute_reply.started":"2022-08-09T07:09:32.493191Z","shell.execute_reply":"2022-08-09T07:09:33.054335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['alt_prec'].value_counts().loc[lambda x: x > 4500]","metadata":{"id":"P6toD3hKyybW","outputId":"4104c41d-5013-4059-e5db-cc554e77e73c","execution":{"iopub.status.busy":"2022-07-25T12:23:03.568933Z","iopub.execute_input":"2022-07-25T12:23:03.569430Z","iopub.status.idle":"2022-07-25T12:23:03.704715Z","shell.execute_reply.started":"2022-07-25T12:23:03.569394Z","shell.execute_reply":"2022-07-25T12:23:03.703569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I believe that a height equal to 0 is an outlier.Buildings with 5 floors are most often described","metadata":{"id":"UqGStDAw18c6"}},{"cell_type":"code","source":"sns.lineplot(data=data,x='height', y = 'alt_prec')","metadata":{"id":"t-2_LcPN08_t","outputId":"cb1bee65-fc91-4cfc-c94a-20fcfb4f511d","execution":{"iopub.status.busy":"2022-07-25T12:23:03.706400Z","iopub.execute_input":"2022-07-25T12:23:03.706719Z","iopub.status.idle":"2022-07-25T12:23:14.741586Z","shell.execute_reply.started":"2022-07-25T12:23:03.706689Z","shell.execute_reply":"2022-07-25T12:23:14.740404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"after 20 meters, the size data match.Before that, there are many discrepancies.Especially at a height of 0 m","metadata":{"id":"nFHINpTY17y1"}},{"cell_type":"code","source":"data.loc[data['height'] == 0.0]['floors']","metadata":{"id":"LeaU_4aE09DQ","outputId":"7b74c719-66dc-4a2a-b3a6-13a8fda28824","execution":{"iopub.status.busy":"2022-07-25T12:23:14.743199Z","iopub.execute_input":"2022-07-25T12:23:14.743589Z","iopub.status.idle":"2022-07-25T12:23:14.753197Z","shell.execute_reply.started":"2022-07-25T12:23:14.743555Z","shell.execute_reply":"2022-07-25T12:23:14.752404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":":)","metadata":{"id":"7r0pAhNG17Ln"}},{"cell_type":"code","source":"ax1,ax2,ax3 = plt.figure(figsize = (25,10)).subplots(1,3)\nsns.lineplot(data = data, x = 'age', y = 'height',ax = ax1)\nsns.lineplot(data = data, x = 'height', y = 'floors', ax=ax2)\nsns.lineplot(data = data, x = 'age', y = 'floors', ax=ax3)","metadata":{"id":"L6Q4CfvZtZVz","outputId":"87ff0e29-d2f7-4ab9-a8c7-ed068811d476","execution":{"iopub.status.busy":"2022-07-25T12:23:14.754391Z","iopub.execute_input":"2022-07-25T12:23:14.754836Z","iopub.status.idle":"2022-07-25T12:23:38.980264Z","shell.execute_reply.started":"2022-07-25T12:23:14.754808Z","shell.execute_reply":"2022-07-25T12:23:38.979097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"1 The graph is kept stable at the level of 15-20 meters in height with the growth of age.The old houses are very tall\n\n\n2 The graph is linear it is logical\n\n\n3 The graph is kept stable like the height","metadata":{"id":"4ijzBcwF199G"}},{"cell_type":"code","source":"ax1,ax2 = plt.figure(figsize = (15,10)).subplots(1,2)\nsns.lineplot(data = data, x = 'age', y = 'roof_mat',ax=ax1)\nsns.lineplot(data = data, x = 'age', y = 'wall_mat', ax=ax2)","metadata":{"id":"caidZPLttZX_","outputId":"0fdac2da-90ba-44b0-aa3d-548d95b66052","execution":{"iopub.status.busy":"2022-07-25T12:23:38.981525Z","iopub.execute_input":"2022-07-25T12:23:38.981966Z","iopub.status.idle":"2022-07-25T12:23:52.565507Z","shell.execute_reply.started":"2022-07-25T12:23:38.981919Z","shell.execute_reply":"2022-07-25T12:23:52.564348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The older the house, the more emissions up the material","metadata":{"id":"LfGk0Xn91-Xj"}},{"cell_type":"code","source":"sns.displot(\n    data, x=\"age\",row=\"floors\",\n    binwidth=3, height=3, facet_kws=dict(margin_titles=True),\n)","metadata":{"id":"eWfNKtzxssgH","outputId":"af52c766-1e74-40f1-8417-eb6a4fd551b5","execution":{"iopub.status.busy":"2022-07-25T12:23:52.567003Z","iopub.execute_input":"2022-07-25T12:23:52.567800Z","iopub.status.idle":"2022-07-25T12:24:21.392085Z","shell.execute_reply.started":"2022-07-25T12:23:52.567767Z","shell.execute_reply":"2022-07-25T12:24:21.390647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{"id":"PJ5hY7Dm1_UR"}},{"cell_type":"code","source":"sns.displot(data=data, x = 'age')","metadata":{"id":"rwpnMqb7ssic","outputId":"9fe87b4d-d464-4129-f46e-acea904662bd","execution":{"iopub.status.busy":"2022-07-25T12:24:21.393886Z","iopub.execute_input":"2022-07-25T12:24:21.394809Z","iopub.status.idle":"2022-07-25T12:24:25.241940Z","shell.execute_reply.started":"2022-07-25T12:24:21.394761Z","shell.execute_reply":"2022-07-25T12:24:25.240748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of the houses using gas are new","metadata":{"id":"lGCZ__011_8M"}},{"cell_type":"code","source":"ax1,ax2 = plt.figure(figsize = (12,8)).subplots(1,2)\nsns.histplot(data=data, x = 'floors',ax=ax1)\nsns.boxplot(data=data,x='floors',ax=ax2)","metadata":{"id":"mxrl9Mq7jXcq","outputId":"80f27108-1f3d-4e59-d85d-17d8641f424c","execution":{"iopub.status.busy":"2022-07-25T12:24:25.243215Z","iopub.execute_input":"2022-07-25T12:24:25.243516Z","iopub.status.idle":"2022-07-25T12:24:25.973996Z","shell.execute_reply.started":"2022-07-25T12:24:25.243489Z","shell.execute_reply":"2022-07-25T12:24:25.972796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We have emissions.","metadata":{"id":"5ODufDRN2BMt"}},{"cell_type":"code","source":"ax1,ax2 = plt.figure(figsize = (12,8)).subplots(1,2)\nsns.histplot(data=data, x = 'height',ax=ax1)\nsns.boxplot(data=data,x='height',ax=ax2)","metadata":{"id":"npdO6lvSkD5x","outputId":"897967cd-400e-473b-ebbe-5760c2e61669","execution":{"iopub.status.busy":"2022-07-25T12:24:25.975420Z","iopub.execute_input":"2022-07-25T12:24:25.976452Z","iopub.status.idle":"2022-07-25T12:24:26.559297Z","shell.execute_reply.started":"2022-07-25T12:24:25.976413Z","shell.execute_reply":"2022-07-25T12:24:26.558174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The distribution is almost normal.We have outliers at zero.We have so where are the outliers that we see on boxplots","metadata":{"id":"LNE6M5Ok2Bzh"}},{"cell_type":"markdown","source":"# **Mixed data** <a id=\"4\"></a>","metadata":{"id":"HbXtmjPz22E4"}},{"cell_type":"code","source":"ax1,ax2 = plt.figure(figsize = (15,10)).subplots(1,2)\nsns.lineplot(data = data, x = 'age', y = 'consumption',ax=ax1)\nsns.lineplot(data = data, x = 'height', y = 'consumption', ax=ax2)","metadata":{"id":"q0W_vJV1kEEi","outputId":"d44e0be3-176f-4549-e6ed-50a3076a50cf","execution":{"iopub.status.busy":"2022-07-25T12:24:26.561781Z","iopub.execute_input":"2022-07-25T12:24:26.562822Z","iopub.status.idle":"2022-07-25T12:24:44.380376Z","shell.execute_reply.started":"2022-07-25T12:24:26.562776Z","shell.execute_reply":"2022-07-25T12:24:44.379114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The older the house, the more gas costs\n\nHouses 40-60 m high spend more gas than others","metadata":{"id":"ODEO4Zsl3UfV"}},{"cell_type":"code","source":"ax1,ax2 = plt.figure(figsize = (15,10)).subplots(1,2)\nsns.lineplot(data = data, x = 'age', y = 'delivery_points',ax=ax1)\nsns.lineplot(data = data, x = 'height', y = 'delivery_points', ax=ax2)","metadata":{"id":"Rk1zl2Dr203q","outputId":"b0495701-c110-4095-c34a-5d08fa00e74c","execution":{"iopub.status.busy":"2022-07-25T12:24:44.381755Z","iopub.execute_input":"2022-07-25T12:24:44.382348Z","iopub.status.idle":"2022-07-25T12:25:02.046552Z","shell.execute_reply.started":"2022-07-25T12:24:44.382312Z","shell.execute_reply":"2022-07-25T12:25:02.045203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stats_by_city_height = data.groupby(\"city_name\")[\"height\"].agg([\"mean\", \"median\", \"min\", \"max\", \"count\"])\nstats_by_age_consumption = data.groupby(\"age\")[\"consumption\"].agg([\"mean\", \"median\", \"min\", \"max\", \"count\"])\nstats_by_city_height","metadata":{"id":"SXvJR1TK209i","outputId":"c1f6c079-52ff-445d-f8af-e544fca386b9","execution":{"iopub.status.busy":"2022-07-25T12:25:02.048295Z","iopub.execute_input":"2022-07-25T12:25:02.048903Z","iopub.status.idle":"2022-07-25T12:25:02.085449Z","shell.execute_reply.started":"2022-07-25T12:25:02.048839Z","shell.execute_reply":"2022-07-25T12:25:02.084306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stats_by_age_consumption","metadata":{"id":"CO_5sVFM21AU","outputId":"6a7310a3-5829-4c4d-ab66-d8c682fe6291","execution":{"iopub.status.busy":"2022-07-25T12:25:02.086929Z","iopub.execute_input":"2022-07-25T12:25:02.087224Z","iopub.status.idle":"2022-07-25T12:25:02.104240Z","shell.execute_reply.started":"2022-07-25T12:25:02.087197Z","shell.execute_reply":"2022-07-25T12:25:02.102950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Fill NaN** <a id=\"5\"></a>","metadata":{}},{"cell_type":"code","source":"from sklearn.impute import KNNImputer","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:23:51.527089Z","iopub.execute_input":"2022-08-09T08:23:51.527454Z","iopub.status.idle":"2022-08-09T08:23:51.813426Z","shell.execute_reply.started":"2022-08-09T08:23:51.527428Z","shell.execute_reply":"2022-08-09T08:23:51.812500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nan_zero_info(data)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T07:11:33.630394Z","iopub.execute_input":"2022-08-09T07:11:33.630694Z","iopub.status.idle":"2022-08-09T07:11:33.676328Z","shell.execute_reply.started":"2022-08-09T07:11:33.630671Z","shell.execute_reply":"2022-08-09T07:11:33.675415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.isna().sum().sort_values().plot(kind='barh', figsize=(10,8))","metadata":{"execution":{"iopub.status.busy":"2022-08-09T07:13:04.967193Z","iopub.execute_input":"2022-08-09T07:13:04.967540Z","iopub.status.idle":"2022-08-09T07:13:05.168466Z","shell.execute_reply.started":"2022-08-09T07:13:04.967515Z","shell.execute_reply":"2022-08-09T07:13:05.167695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**KNNImputer**","metadata":{}},{"cell_type":"code","source":"imputer = KNNImputer(n_neighbors=2)\nclear_data = imputer.fit_transform(data['roof_mat'].values.reshape(-1, 1))\ndata['roof_mat'] = clear_data","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:23:55.214188Z","iopub.execute_input":"2022-08-09T08:23:55.214555Z","iopub.status.idle":"2022-08-09T08:24:15.401489Z","shell.execute_reply.started":"2022-08-09T08:23:55.214529Z","shell.execute_reply":"2022-08-09T08:24:15.400430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**fillna**","metadata":{}},{"cell_type":"code","source":"data['wall_mat'] = data['wall_mat'].fillna(data['wall_mat'].median())\ndata['floors'] = data['floors'].fillna(data['floors'].mean())\ndata['height'] = data['height'].fillna(data['height'].median())","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:24:15.405445Z","iopub.execute_input":"2022-08-09T08:24:15.405772Z","iopub.status.idle":"2022-08-09T08:24:15.423011Z","shell.execute_reply.started":"2022-08-09T08:24:15.405747Z","shell.execute_reply":"2022-08-09T08:24:15.420732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Replacing with the most frequent value**","metadata":{}},{"cell_type":"code","source":"data['age'] = data['age'].fillna(data['age'].value_counts().idxmax()) ","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:24:15.424332Z","iopub.execute_input":"2022-08-09T08:24:15.424615Z","iopub.status.idle":"2022-08-09T08:24:15.441147Z","shell.execute_reply.started":"2022-08-09T08:24:15.424590Z","shell.execute_reply":"2022-08-09T08:24:15.439710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **The importance of features** <a id=\"6\"></a>","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nfrom sklearn.tree import DecisionTreeClassifier\n\nfrom sklearn.tree import DecisionTreeRegressor","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:24:15.444060Z","iopub.execute_input":"2022-08-09T08:24:15.444796Z","iopub.status.idle":"2022-08-09T08:24:15.479870Z","shell.execute_reply.started":"2022-08-09T08:24:15.444752Z","shell.execute_reply":"2022-08-09T08:24:15.479176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-08-09T07:57:31.786806Z","iopub.execute_input":"2022-08-09T07:57:31.787513Z","iopub.status.idle":"2022-08-09T07:57:31.814012Z","shell.execute_reply.started":"2022-08-09T07:57:31.787476Z","shell.execute_reply":"2022-08-09T07:57:31.813351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nan_zero_info(data)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T07:57:31.815206Z","iopub.execute_input":"2022-08-09T07:57:31.815644Z","iopub.status.idle":"2022-08-09T07:57:31.868476Z","shell.execute_reply.started":"2022-08-09T07:57:31.815619Z","shell.execute_reply":"2022-08-09T07:57:31.867448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for idx in range(len(data['age'])):\n    tmp = str(data['age'][idx]).replace('-','0')\n    data['age'][idx] = int(tmp)","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:24:15.480748Z","iopub.execute_input":"2022-08-09T08:24:15.481165Z","iopub.status.idle":"2022-08-09T08:24:38.157597Z","shell.execute_reply.started":"2022-08-09T08:24:15.481140Z","shell.execute_reply":"2022-08-09T08:24:38.156616Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.pop('geometry')\ndata.pop('qq_dict')\ndata.pop('coords_eobs')\ndata.pop('address')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:24:38.159021Z","iopub.execute_input":"2022-08-09T08:24:38.159288Z","iopub.status.idle":"2022-08-09T08:24:38.168909Z","shell.execute_reply.started":"2022-08-09T08:24:38.159246Z","shell.execute_reply":"2022-08-09T08:24:38.167843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:24:38.170363Z","iopub.execute_input":"2022-08-09T08:24:38.171713Z","iopub.status.idle":"2022-08-09T08:24:38.199630Z","shell.execute_reply.started":"2022-08-09T08:24:38.171671Z","shell.execute_reply":"2022-08-09T08:24:38.198483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for num_label in num_data.columns:\n    print(f'======= START TRAIN {num_label} =======\\n')\n    train_data = data.copy(deep=True)\n    train_data = pd.get_dummies(train_data)\n    \n    model = DecisionTreeRegressor()\n    label = train_data.pop('consumption')\n    \n    X_train, X_test, y_train, y_test = train_test_split(train_data,label, test_size = 0.3)\n    model.fit(X_train,y_train)\n    \n    print(f'score for {num_label} : {model.score(X_test,y_test)}\\n')\n    feature_importance = pd.DataFrame({'feature':train_data.columns, 'importance': model.feature_importances_}).sort_values('importance')\n    print(feature_importance)\n    print('\\n')","metadata":{"execution":{"iopub.status.busy":"2022-08-09T08:27:38.591959Z","iopub.execute_input":"2022-08-09T08:27:38.592396Z","iopub.status.idle":"2022-08-09T08:28:19.798868Z","shell.execute_reply.started":"2022-08-09T08:27:38.592366Z","shell.execute_reply":"2022-08-09T08:28:19.797559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}}]}