{"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":"# imports:\nimport pandas as pd\nimport numpy as np\nimport datetime\nimport seaborn as sns\n\n\nimport matplotlib\nimport matplotlib.pyplot as plt\nimport gc\n\n\nfrom sklearn.preprocessing import LabelEncoder\n\n\n\nimport plotly.express as px\nimport lightgbm as lgb\nfrom sklearn.model_selection import KFold\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.ensemble import RandomForestRegressor\nfrom xgboost import XGBRegressor\nfrom lightgbm import LGBMRegressor\nfrom sklearn.metrics import mean_squared_error","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-05-31T18:49:29.491546Z","iopub.execute_input":"2023-05-31T18:49:29.491989Z","iopub.status.idle":"2023-05-31T18:49:29.499735Z","shell.execute_reply.started":"2023-05-31T18:49:29.491943Z","shell.execute_reply":"2023-05-31T18:49:29.498808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Here, we start loading the data files and the analysis of each dataset.\nOnly the 1st 50K rows are considered for memory limitations","metadata":{}},{"cell_type":"code","source":"# loading data files:\n#train:\ntrain_dtype={'building_id':'int16','meter':'int8','meter_reading':'float32'}\ntrain_m =pd.read_csv('/kaggle/input/ashrae-energy-prediction/train.csv',dtype=train_dtype,parse_dates=['timestamp'],nrows=50000)\n#We need to drop the 0 values in the meter reading because they do not make sense\ntrain_m = train_m[train_m.meter_reading != 0]\ntrain_m['timestamp'] = pd.to_datetime(train_m['timestamp'])\ntrain_m.sample(3)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:29:48.903610Z","iopub.execute_input":"2023-05-31T18:29:48.904050Z","iopub.status.idle":"2023-05-31T18:29:48.986169Z","shell.execute_reply.started":"2023-05-31T18:29:48.904016Z","shell.execute_reply":"2023-05-31T18:29:48.984768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_m.describe()","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:15.812411Z","iopub.execute_input":"2023-05-31T17:48:15.812899Z","iopub.status.idle":"2023-05-31T17:48:15.859295Z","shell.execute_reply.started":"2023-05-31T17:48:15.812854Z","shell.execute_reply":"2023-05-31T17:48:15.857334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_m.isna().sum()/len(train_m)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:15.863070Z","iopub.execute_input":"2023-05-31T17:48:15.864153Z","iopub.status.idle":"2023-05-31T17:48:15.877576Z","shell.execute_reply.started":"2023-05-31T17:48:15.864101Z","shell.execute_reply":"2023-05-31T17:48:15.876205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"-Note that the 0 value in the meter_reading doesn't make sense because power consumption will never be 0.\n-Also, there are no missing data","metadata":{}},{"cell_type":"code","source":"plt.hist(train_m['meter_reading']);\nplt.title('Target distribution plot');","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:15.879092Z","iopub.execute_input":"2023-05-31T17:48:15.879550Z","iopub.status.idle":"2023-05-31T17:48:16.282603Z","shell.execute_reply.started":"2023-05-31T17:48:15.879509Z","shell.execute_reply":"2023-05-31T17:48:16.281156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"this skewness and the 0 values suggests the log transformation of log(x+1)","metadata":{}},{"cell_type":"code","source":"plt.hist(train_m['timestamp']);\nplt.title('Train data time range');","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:16.284551Z","iopub.execute_input":"2023-05-31T17:48:16.285072Z","iopub.status.idle":"2023-05-31T17:48:16.712234Z","shell.execute_reply.started":"2023-05-31T17:48:16.285021Z","shell.execute_reply":"2023-05-31T17:48:16.710797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test:\ntest_dtype={'row_id':'int8','building_id':'int16','meter':'int8'}\ntest=pd.read_csv('/kaggle/input/ashrae-energy-prediction/test.csv',dtype=test_dtype,parse_dates=['timestamp'],nrows=50000)\ntest['timestamp'] = pd.to_datetime(test['timestamp'])\ntest.sample(3)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:30:23.873765Z","iopub.execute_input":"2023-05-31T18:30:23.874221Z","iopub.status.idle":"2023-05-31T18:30:23.957877Z","shell.execute_reply.started":"2023-05-31T18:30:23.874189Z","shell.execute_reply":"2023-05-31T18:30:23.956632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.describe()","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:16.794872Z","iopub.execute_input":"2023-05-31T17:48:16.795426Z","iopub.status.idle":"2023-05-31T17:48:16.819141Z","shell.execute_reply.started":"2023-05-31T17:48:16.795394Z","shell.execute_reply":"2023-05-31T17:48:16.818098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.isna().sum()/len(test)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:16.820617Z","iopub.execute_input":"2023-05-31T17:48:16.821171Z","iopub.status.idle":"2023-05-31T17:48:16.830035Z","shell.execute_reply.started":"2023-05-31T17:48:16.821138Z","shell.execute_reply":"2023-05-31T17:48:16.829086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"No missing data","metadata":{}},{"cell_type":"code","source":"plt.hist(test['timestamp']);\nplt.title('Test data time range');","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:16.834380Z","iopub.execute_input":"2023-05-31T17:48:16.835008Z","iopub.status.idle":"2023-05-31T17:48:17.253348Z","shell.execute_reply.started":"2023-05-31T17:48:16.834956Z","shell.execute_reply":"2023-05-31T17:48:17.252071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#building\nbuilding_dtype={'site_id':'int8','building_id':'int16','square_feet':'int32','year_built':'float16',\n            'floor_count':'float16'}\nbuilding=pd.read_csv('/kaggle/input/ashrae-energy-prediction/building_metadata.csv',dtype=building_dtype,nrows=50000)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:17.255237Z","iopub.execute_input":"2023-05-31T17:48:17.255698Z","iopub.status.idle":"2023-05-31T17:48:17.269252Z","shell.execute_reply.started":"2023-05-31T17:48:17.255663Z","shell.execute_reply":"2023-05-31T17:48:17.268112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Note that train and test data have different time ranges.","metadata":{}},{"cell_type":"code","source":"plt.xticks(rotation=75)\nsns.histplot(building.primary_use);\nplt.title('primay_use histogram');\n","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:17.271060Z","iopub.execute_input":"2023-05-31T17:48:17.271429Z","iopub.status.idle":"2023-05-31T17:48:17.767539Z","shell.execute_reply.started":"2023-05-31T17:48:17.271398Z","shell.execute_reply":"2023-05-31T17:48:17.766125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"building.describe()","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:17.769033Z","iopub.execute_input":"2023-05-31T17:48:17.769390Z","iopub.status.idle":"2023-05-31T17:48:17.810137Z","shell.execute_reply.started":"2023-05-31T17:48:17.769359Z","shell.execute_reply":"2023-05-31T17:48:17.808776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"building.isna().sum()/len(building)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:17.812035Z","iopub.execute_input":"2023-05-31T17:48:17.812487Z","iopub.status.idle":"2023-05-31T17:48:17.824235Z","shell.execute_reply.started":"2023-05-31T17:48:17.812445Z","shell.execute_reply":"2023-05-31T17:48:17.823325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There is missing data in floor_count and year_built. It's too much that it should be discarded, not filled.","metadata":{}},{"cell_type":"code","source":"plt.xticks(rotation=75)\nsns.histplot(building.primary_use);\nplt.title('Histogram of primay_use feature');","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:17.825477Z","iopub.execute_input":"2023-05-31T17:48:17.826427Z","iopub.status.idle":"2023-05-31T17:48:18.267357Z","shell.execute_reply.started":"2023-05-31T17:48:17.826394Z","shell.execute_reply":"2023-05-31T17:48:18.266235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#weather_test\nwtest_dtype={'site_id':'int8','air_temperature':'float16','cloud_coverage':'float16','dew_temperature':'float16','precip_depth_1_hr':'float16','sea_level_pressure':'float16','wind_direction':'float16',\n    'wind_speed':'float16'}\nweather_test=pd.read_csv('/kaggle/input/ashrae-energy-prediction/weather_test.csv',dtype=wtest_dtype,nrows=50000)\nweather_test['timestamp'] = pd.to_datetime(weather_test['timestamp'])\n#weather_train.drop(['cloud_coverage','precip_depth_1_hr'], axis = 1,inplace=True)\nweather_test.sample(3)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:40:12.957889Z","iopub.execute_input":"2023-05-31T18:40:12.958339Z","iopub.status.idle":"2023-05-31T18:40:13.074509Z","shell.execute_reply.started":"2023-05-31T18:40:12.958300Z","shell.execute_reply":"2023-05-31T18:40:13.073326Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#weather_train:\nwtrain_dtype={'site_id':'int8','air_temperature':'float16','cloud_coverage':'float16','dew_temperature':'float16','precip_depth_1_hr':'float16','sea_level_pressure':'float16','wind_direction':'float16',\n    'wind_speed':'float16'}\nweather_train=pd.read_csv('/kaggle/input/ashrae-energy-prediction/weather_train.csv',dtype=wtrain_dtype,nrows=50000)\nweather_train['timestamp'] = pd.to_datetime(weather_train['timestamp'])\nweather_train.sample(3)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:32:07.674483Z","iopub.execute_input":"2023-05-31T18:32:07.674920Z","iopub.status.idle":"2023-05-31T18:32:07.794020Z","shell.execute_reply.started":"2023-05-31T18:32:07.674886Z","shell.execute_reply":"2023-05-31T18:32:07.792627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"weather_train.describe()","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:18.528369Z","iopub.execute_input":"2023-05-31T17:48:18.528720Z","iopub.status.idle":"2023-05-31T17:48:18.616694Z","shell.execute_reply.started":"2023-05-31T17:48:18.528689Z","shell.execute_reply":"2023-05-31T17:48:18.615554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"weather_train.isna().sum()/len(weather_train)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:32:36.742968Z","iopub.execute_input":"2023-05-31T18:32:36.745789Z","iopub.status.idle":"2023-05-31T18:32:36.759790Z","shell.execute_reply.started":"2023-05-31T18:32:36.745730Z","shell.execute_reply":"2023-05-31T18:32:36.758226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Note that there is missing data in all features except site_id and time stamp. The ratio is fillable.","metadata":{}},{"cell_type":"code","source":"plt.hist(weather_train.air_temperature);\nplt.title('Air temperature histogram');","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:18.647885Z","iopub.execute_input":"2023-05-31T17:48:18.648360Z","iopub.status.idle":"2023-05-31T17:48:18.959311Z","shell.execute_reply.started":"2023-05-31T17:48:18.648318Z","shell.execute_reply":"2023-05-31T17:48:18.958198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.hist(weather_train.dew_temperature);\nplt.title('Dew temperature histogram');","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:18.961080Z","iopub.execute_input":"2023-05-31T17:48:18.961773Z","iopub.status.idle":"2023-05-31T17:48:19.265938Z","shell.execute_reply.started":"2023-05-31T17:48:18.961732Z","shell.execute_reply":"2023-05-31T17:48:19.264364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Note that it is a bit skewed","metadata":{}},{"cell_type":"code","source":"plt.hist(weather_train.sea_level_pressure);\nplt.title('sea_level_pressure histogram');","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:19.268533Z","iopub.execute_input":"2023-05-31T17:48:19.269072Z","iopub.status.idle":"2023-05-31T17:48:19.615846Z","shell.execute_reply.started":"2023-05-31T17:48:19.269027Z","shell.execute_reply":"2023-05-31T17:48:19.614438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.hist(weather_train.wind_direction);\nplt.title('wind_direction histogram');","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:19.617941Z","iopub.execute_input":"2023-05-31T17:48:19.618411Z","iopub.status.idle":"2023-05-31T17:48:19.929360Z","shell.execute_reply.started":"2023-05-31T17:48:19.618369Z","shell.execute_reply":"2023-05-31T17:48:19.927962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"After loading the data and having the insight, we start cleaning the dataset for the models later.","metadata":{}},{"cell_type":"code","source":"#defining a function to handle missing values as found in weather_train\ndef Missing_data_fill(data):\n  for i in data.columns:\n    if data[i].isna().sum()!=0:\n      if data[i].dtype == 'float16':\n        data[i]=data[i].astype('float32')\n      if data[i][0]==np.nan:\n        data[i][0]=data[i].mean()\n      data[i].fillna(method='ffill',inplace=True)\n  return data","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:32:52.232949Z","iopub.execute_input":"2023-05-31T18:32:52.233382Z","iopub.status.idle":"2023-05-31T18:32:52.242658Z","shell.execute_reply.started":"2023-05-31T18:32:52.233348Z","shell.execute_reply":"2023-05-31T18:32:52.240387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Calling the missing data fill function to handle missing data found in weather and building datasets\nweather_train=Missing_data_fill(weather_train)\n#Dropping the missed column values from building:\nbuilding.drop(columns=['year_built','floor_count'],inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:33:28.694299Z","iopub.execute_input":"2023-05-31T18:33:28.694743Z","iopub.status.idle":"2023-05-31T18:33:28.707146Z","shell.execute_reply.started":"2023-05-31T18:33:28.694708Z","shell.execute_reply":"2023-05-31T18:33:28.705184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Encoding string data into numerical values:\nencoder = LabelEncoder()\nbuilding[\"primary_use\"] = encoder.fit_transform(building[\"primary_use\"])\nbuilding.sample(3)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:48:19.979749Z","iopub.execute_input":"2023-05-31T17:48:19.980409Z","iopub.status.idle":"2023-05-31T17:48:19.994627Z","shell.execute_reply.started":"2023-05-31T17:48:19.980376Z","shell.execute_reply":"2023-05-31T17:48:19.993311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Mergingsets with train and test datasets using foreign keys:\ntrain_m = pd.merge(train_m,building, on=\"building_id\", how=\"left\")\ntrain_m = train_m.merge(weather_train, on=[\"site_id\", \"timestamp\"], how=\"left\")","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:44:25.843674Z","iopub.execute_input":"2023-05-31T18:44:25.844435Z","iopub.status.idle":"2023-05-31T18:44:25.881964Z","shell.execute_reply.started":"2023-05-31T18:44:25.844387Z","shell.execute_reply":"2023-05-31T18:44:25.881062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_m.head()\n#del train_m,building,weather_train\n#gc.collect()","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-05-31T19:41:49.505614Z","iopub.execute_input":"2023-05-31T19:41:49.506022Z","iopub.status.idle":"2023-05-31T19:41:49.527515Z","shell.execute_reply.started":"2023-05-31T19:41:49.505967Z","shell.execute_reply":"2023-05-31T19:41:49.526048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Converting from KBTU to kWh\ntrain_m.loc[train_m[train_m['site_id']==0].index,'meter_reading']=train_m[train_m['site_id']==0]['meter_reading']*0.2931","metadata":{"execution":{"iopub.status.busy":"2023-05-31T17:49:01.621219Z","iopub.execute_input":"2023-05-31T17:49:01.621635Z","iopub.status.idle":"2023-05-31T17:49:18.886775Z","shell.execute_reply.started":"2023-05-31T17:49:01.621600Z","shell.execute_reply":"2023-05-31T17:49:18.885526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_m.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:51:11.354730Z","iopub.execute_input":"2023-05-31T18:51:11.355189Z","iopub.status.idle":"2023-05-31T18:51:11.368116Z","shell.execute_reply.started":"2023-05-31T18:51:11.355155Z","shell.execute_reply":"2023-05-31T18:51:11.367187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Null values, so we drop rows with null values","metadata":{}},{"cell_type":"code","source":"train_m = train_m.dropna(how='any',axis=0)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:58:16.030751Z","iopub.execute_input":"2023-05-31T18:58:16.031212Z","iopub.status.idle":"2023-05-31T18:58:16.041898Z","shell.execute_reply.started":"2023-05-31T18:58:16.031181Z","shell.execute_reply":"2023-05-31T18:58:16.040935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_m.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-05-31T18:58:29.309274Z","iopub.execute_input":"2023-05-31T18:58:29.309716Z","iopub.status.idle":"2023-05-31T18:58:29.323681Z","shell.execute_reply.started":"2023-05-31T18:58:29.309682Z","shell.execute_reply":"2023-05-31T18:58:29.321824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Draw the scatter to detect and remove outliers","metadata":{}},{"cell_type":"code","source":"train_sample=train_m.sample(10000)\nsns.scatterplot(x=train_sample.building_id,y=train_sample.meter_reading,hue=train_sample.site_id);\ndel train_sample","metadata":{"execution":{"iopub.status.busy":"2023-05-31T19:04:45.488568Z","iopub.execute_input":"2023-05-31T19:04:45.489050Z","iopub.status.idle":"2023-05-31T19:04:46.947391Z","shell.execute_reply.started":"2023-05-31T19:04:45.489013Z","shell.execute_reply":"2023-05-31T19:04:46.945494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_m = train_m [ train_m['meter_reading']<= 1500 ]","metadata":{"execution":{"iopub.status.busy":"2023-05-31T19:15:42.414076Z","iopub.execute_input":"2023-05-31T19:15:42.414613Z","iopub.status.idle":"2023-05-31T19:15:42.426726Z","shell.execute_reply.started":"2023-05-31T19:15:42.414577Z","shell.execute_reply":"2023-05-31T19:15:42.425151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_sample=train_m.sample(10000)\nsns.scatterplot(x=train_sample.building_id,y=train_sample.meter_reading,hue=train_sample.site_id);\ndel train_sample","metadata":{"execution":{"iopub.status.busy":"2023-05-31T19:16:08.777901Z","iopub.execute_input":"2023-05-31T19:16:08.778352Z","iopub.status.idle":"2023-05-31T19:16:10.265827Z","shell.execute_reply.started":"2023-05-31T19:16:08.778317Z","shell.execute_reply":"2023-05-31T19:16:10.264912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now,feature engineering","metadata":{}},{"cell_type":"code","source":"# This function firstly converts timestamp to date and then breaks down date into 6 new columns: hour, day, dayOfWeek, dayOfYear, month and year\n\ndef breakdown_timestamp(dataframe):\n    \n    dataframe['hour']= np.uint8(dataframe['timestamp'].dt.hour)\n    \n    dataframe['day']= np.uint16(dataframe['timestamp'].dt.day)\n    dataframe['dayofweek']= np.uint8(dataframe['timestamp'].dt.dayofweek)\n    dataframe['dayofyear']= np.uint16(dataframe['timestamp'].dt.dayofyear)\n\n    dataframe['month']= np.uint8(dataframe['timestamp'].dt.month)\n\n    dataframe['year']= np.uint16(dataframe['timestamp'].dt.year)\n    \n    return dataframe","metadata":{"execution":{"iopub.status.busy":"2023-05-31T19:39:17.702049Z","iopub.execute_input":"2023-05-31T19:39:17.702489Z","iopub.status.idle":"2023-05-31T19:39:17.711090Z","shell.execute_reply.started":"2023-05-31T19:39:17.702458Z","shell.execute_reply":"2023-05-31T19:39:17.709684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_m = breakdown_timestamp(train_m)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_m.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-31T19:44:38.237394Z","iopub.execute_input":"2023-05-31T19:44:38.237845Z","iopub.status.idle":"2023-05-31T19:44:38.262253Z","shell.execute_reply.started":"2023-05-31T19:44:38.237798Z","shell.execute_reply":"2023-05-31T19:44:38.260971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Defining input and output target","metadata":{}},{"cell_type":"code","source":"feat_in=['building_id', 'meter','site_id','primary_use', 'square_feet', 'air_temperature','dew_temperature',\n        'sea_level_pressure', 'wind_direction','wind_speed', 'hour', 'day','weekday', 'month']\nfeat_out='meter_reading'","metadata":{"execution":{"iopub.status.busy":"2023-05-31T19:51:43.979653Z","iopub.execute_input":"2023-05-31T19:51:43.980142Z","iopub.status.idle":"2023-05-31T19:51:43.986786Z","shell.execute_reply.started":"2023-05-31T19:51:43.980107Z","shell.execute_reply":"2023-05-31T19:51:43.985373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Train and test data split:","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\ntrainset_df,validset_df =  train_test_split(train_m, \n                                    test_size=0.4, \n                                    random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-05-31T19:52:59.877957Z","iopub.execute_input":"2023-05-31T19:52:59.879205Z","iopub.status.idle":"2023-05-31T19:52:59.889767Z","shell.execute_reply.started":"2023-05-31T19:52:59.879164Z","shell.execute_reply":"2023-05-31T19:52:59.888802Z"},"trusted":true},"execution_count":null,"outputs":[]}]}