{"cells":[{"metadata":{},"cell_type":"markdown","source":"# About Competitions\n \nIn this competition , I will develop accurate models of metered building energy usage in the following areas:chilled water,electric, hot water and steam meters. The data comes from over 1000 buidings over three year timeframe.With better estimates of these energy saving investments, large scale investors and financial institutions will more inclined to invest in this area to enable progress in building efficiencies.\n","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"# About The Host\n\nThis competitions is organised by ASHRAE.This is founded in 1894. ASHRAE serves to advance the arts and sciences of heating,ventilation, air conditioning refrigeration and their allied fields. ASHRAE members represent building system design and industrial process professional around the world.With over 54000 members serving in 132 countries.ASHRAE supports research ,standard writing , publishing and continuing education shaping tommorrow's built environment today.","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"# Import Packages","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\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# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nimport datetime\nimport gc\nimport seaborn as sns\n\nimport warnings\nwarnings.filterwarnings('ignore')\nwarnings.simplefilter('ignore')\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"path='/kaggle/input/ashrae-energy-prediction/'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#weather train\nweather_train=pd.read_csv(path+'weather_train.csv')\ndisplay(weather_train.shape)\ndisplay(weather_train.head())\ndisplay(weather_train.columns)\ndisplay(weather_train.dtypes)\n#check index\ndisplay(weather_train['site_id'].is_unique)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#wearher test\nweather_test=pd.read_csv(path+'weather_test.csv')\ndisplay(weather_test.shape)\ndisplay(weather_test.head())\ndisplay(weather_test.columns)\ndisplay(weather_test.dtypes)\n# check for index\ndisplay(weather_test['site_id'].is_unique)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Merge weather_train & Weather_test\nweather_merged=weather_train.append(weather_test)\nweather_merged['timestamp']=pd.to_datetime(weather_merged['timestamp'])\nweather_merged.set_index('timestamp',inplace=True)\ndisplay(weather_merged.shape)\ndisplay(weather_merged.columns)\ndisplay(weather_merged.head())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#extract wind speed from weather data\nwind_speed_pivot=weather_merged.reset_index().pivot_table(index='timestamp',columns='site_id',values='wind_speed')\nwind_speed_pivot.columns='site_'+wind_speed_pivot.columns.astype('str')\nwind_speed_pivot","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#load external wind speed data\nspeed_external = pd.read_csv(\"../input/historical-hourly-weather-data/wind_speed.csv\")\nspeed_external['datetime'] = pd.to_datetime(speed_external['datetime'])\nspeed_external.set_index('datetime', inplace=True)\n\nspeed_external = speed_external.merge(wind_speed_pivot, left_index=True, right_index=True, how='inner')\nspeed_external = speed_external.dropna()\n\nspeed_external","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#calculate correlations between sites\ndf_corr = speed_external.corr(method='spearman')\nlist_site = wind_speed_pivot.columns\ndf_corr = df_corr[list_site]\ndf_corr = df_corr.drop(list_site)\ndf_corr","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#sns heat map\nfig, ax = plt.subplots(figsize=(30,15))   \nsns.heatmap(df_corr, annot=True, cmap=\"YlGnBu\", vmin=0.08, vmax=0.10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Get cities!\ndf_findCity = pd.concat([df_corr.idxmax(),df_corr.max()], axis=1).reset_index().rename(columns={'index':'site',0:'city',1:'corr'})\ndf_findCity","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#compare sites & cities in plot\nfor city, site, corr in zip(df_findCity['city'],df_findCity['site'],df_findCity['corr']):\n    if corr > 0.08:\n        print('City: ' + city)\n        print('Site: ' + site)   \n        speed_external[[city,site]].loc['2016'].plot(figsize=(15,8), alpha=0.5)\n        plt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Similarly for Sea Level pressure and Wind Direction","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"# Wind Direction","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"#extract wind speed from weather data\nwind_direction_pivot=weather_merged.reset_index().pivot_table(index='timestamp',columns='site_id',values='wind_direction')\nwind_direction_pivot.columns='site_'+wind_direction_pivot.columns.astype('str')\nwind_direction_pivot","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#load external wind direction data\ndirection_external = pd.read_csv(\"../input/historical-hourly-weather-data/wind_direction.csv\")\ndirection_external['datetime'] = pd.to_datetime(direction_external['datetime'])\ndirection_external.set_index('datetime', inplace=True)\n\ndirection_external = direction_external.merge(wind_direction_pivot, left_index=True, right_index=True, how='inner')\ndirection_external = direction_external.dropna()\n\ndirection_external","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#calculate correlations between sites\ndf_corr = direction_external.corr(method='spearman')\nlist_site = wind_direction_pivot.columns\ndf_corr = df_corr[list_site]\ndf_corr = df_corr.drop(list_site)\ndf_corr","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#sns heat map\nfig, ax = plt.subplots(figsize=(30,15))   \nsns.heatmap(df_corr, annot=True, cmap=\"YlGnBu\", vmin=0,vmax=0.3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Get cities!\ndf_findCity = pd.concat([df_corr.idxmax(),df_corr.max()], axis=1).reset_index().rename(columns={'index':'site',0:'city',1:'corr'})\ndf_findCity","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#compare sites & cities in plot\nfor city, site, corr in zip(df_findCity['city'],df_findCity['site'],df_findCity['corr']):\n    if corr > 0.08:\n        print('City: ' + city)\n        print('Site: ' + site)   \n        direction_external[[city,site]].loc['2016'].plot(figsize=(15,8), alpha=0.5)\n        plt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Pressure","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"#extract wind speed from weather data\nsea_level_pivot=weather_merged.reset_index().pivot_table(index='timestamp',columns='site_id',values='sea_level_pressure')\nsea_level_pivot.columns='site_' +sea_level_pivot.columns.astype('str')\nsea_level_pivot","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#load external wind direction data\npressure_external = pd.read_csv(\"../input/historical-hourly-weather-data/pressure.csv\")\npressure_external['datetime'] = pd.to_datetime(pressure_external['datetime'])\npressure_external.set_index('datetime', inplace=True)\npressure_external=pressure_external-760\npreesure_external = pressure_external.merge(sea_level_pivot, left_index=True, right_index=True, how='inner')\npressure_external = pressure_external.dropna()\n\npressure_external","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#calculate correlations between sites\ndf_corr = direction_external.corr(method='spearman')\nlist_site = wind_direction_pivot.columns\ndf_corr = df_corr[list_site]\ndf_corr = df_corr.drop(list_site)\ndf_corr","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#sns heat map\nfig, ax = plt.subplots(figsize=(30,15))   \nsns.heatmap(df_corr, annot=True, cmap=\"YlGnBu\", vmin=0,vmax=0.6)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Get cities!\ndf_findCity = pd.concat([df_corr.idxmax(),df_corr.max()], axis=1).reset_index().rename(columns={'index':'site',0:'city',1:'corr'})\ndf_findCity","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}