{"cells":[{"metadata":{},"cell_type":"markdown","source":"# About This Notebook\n\nIn this competition we are to create a model to predict an energy usage. We understand that energy consumption depends on the season. e.g Energy consumed in Hot Water should be more in winter than summer.\n\nLet's see how energy consumption raises or lower during the year based on training data.\n"},{"metadata":{},"cell_type":"markdown","source":"## Load Libraries"},{"metadata":{"trusted":true},"cell_type":"code","source":"import os\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Load Data"},{"metadata":{"trusted":true},"cell_type":"code","source":"DATA_PATH = '../input/ashrae-energy-prediction/'\n\ntrain_df = pd.read_csv(DATA_PATH + 'train.csv',index_col='timestamp', parse_dates=True)\ntrain_df['meter'] = pd.Categorical(train_df['meter']).rename_categories({0: 'electricity', 1: 'chilledwater', 2: 'steam', 3: 'hotwater'})","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Utility Functions"},{"metadata":{"trusted":true},"cell_type":"code","source":"def seasonal_consumption(df,seasons):\n    chart_rows = len(seasons)\n    size = (16,chart_rows * 5)\n    fig,ax = plt.subplots(chart_rows,1,figsize=size)\n    for i,season in enumerate(seasons):\n        season_name, season_months = season\n        month_meters = df.loc[season_months].groupby('meter').mean()\n        plt.subplot(chart_rows,1,i+1)\n        plt.title('Energy Consumption in ' + str.capitalize(season_name))\n        plt.bar(month_meters.index, month_meters)\n        #plt.ylim(0,1e10)\n        plt.ylabel('Energy Consumption (kWh)')\n        plt.xlabel('Meter Type')\n    \n    fig.subplots_adjust(hspace=.3)\n    plt.show()\n\ndef months_consumption(df,months):\n    months_title = ['January','February','March','April','May','June','July','August','September','October','November','December']\n    chart_rows = int(len(months)/2)\n    size = (16,chart_rows * 5)\n    fig,ax = plt.subplots(chart_rows,2,figsize=size)\n\n    for month in months:\n        month_meters = df.loc[month]\n        plt.subplot(chart_rows,2,month)\n        plt.title('Energy Consumption in '+ months_title[month-1])\n        plt.bar(month_meters.index, month_meters)\n        #plt.ylim(0,1e10)\n        plt.ylabel('Energy Consumption (kWh)')\n        plt.xlabel('Meter Type')\n    \n    fig.subplots_adjust(hspace=.3)\n    plt.show()\n\ndef meter_type_consumption(df,meter_types):\n    months_title = ['January','February','March','April','May','June','July','August','September','October','November','December']\n    chart_rows = len(meter_types)\n    size = (16,chart_rows * 5)\n    fig,ax = plt.subplots(chart_rows,1,figsize=size)\n\n    for i,meter in enumerate(meter_types):\n        month_meters = df.loc[:,meter]\n        plt.subplot(chart_rows,1,i+1)\n        plt.title('Energy Consumption by '+ str.capitalize(meter))\n        plt.bar(month_meters.index, month_meters)\n        plt.ylabel('Energy Consumption (kWh)')\n        plt.xlabel('Months')\n        plt.xticks(np.arange(1,13),months_title, rotation=20)\n    \n    fig.subplots_adjust(hspace=.4)\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"months_df = train_df.copy()\nmonths_df['month'] = train_df.index\nmonths_df['month'] = months_df['month'].dt.month\nmonths_reading = months_df.groupby(['month','meter'])['meter_reading'].mean()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Season Wise Energy Consumption"},{"metadata":{"trusted":true},"cell_type":"code","source":"spring= ('spring',[3,4,5])\nsummer= ('summer',[6,7,8])\nfall= ('fall',[9,10,11])\nwinter= ('winter',[1,2,12])\n\nseasonal_consumption(months_reading,[spring,summer,fall,winter])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Month Wise Energy Consumption"},{"metadata":{"trusted":true},"cell_type":"code","source":"months_consumption(months_reading,[1,2,3,4,5,6,7,8,9,10,11,12])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Meter Type Wise Energy Consumption During The Year"},{"metadata":{"trusted":true},"cell_type":"code","source":"meter_type_consumption(months_reading,['electricity','chilledwater','steam','hotwater'])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Day of the Month Energy Consumption"},{"metadata":{"trusted":true},"cell_type":"code","source":"days_df = train_df.copy()\ndays_df['day'] = days_df.index\ndays_df['day'] = days_df['day'].dt.day\ndays_reading = days_df.groupby('day')['meter_reading'].mean()\nplt.figure(figsize=(16,5))\nplt.title('Day of the Month Observation')\nplt.ylabel('Energy Consumption (kWh)')\nplt.xlabel('Day')\nplt.plot(days_reading)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Day of the Week Energy Consumption"},{"metadata":{"trusted":true},"cell_type":"code","source":"weekday_df = train_df.copy()\nweekday_df['weekday'] = weekday_df.index\nweekday_df['weekday'] = weekday_df['weekday'].dt.weekday\nweekday_reading = weekday_df.groupby('weekday')['meter_reading'].mean()\nplt.figure(figsize=(15,5))\nplt.title('Day of the Week Observation')\nplt.ylabel('Energy Consumption (kWh)')\nplt.xlabel('Day')\nplt.plot(weekday_reading)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Hour of the Day Energy Consumption"},{"metadata":{"trusted":true},"cell_type":"code","source":"hour_df =train_df.copy()\nhour_df['hour'] = hour_df.index\nhour_df['hour'] = hour_df['hour'].dt.hour\nhour_reading = hour_df.groupby('hour')['meter_reading'].mean()\nplt.figure(figsize=(15,5))\nplt.title('Hour of the Day Observation')\nplt.ylabel('Energy Consumption (kWh)')\nplt.xlabel('Hour')\nplt.plot(hour_reading)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Now I need your help. What is your conclusion by looking at these plots? and plz correct me if I'm wrong somewhere."}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.3"}},"nbformat":4,"nbformat_minor":1}