{"cells":[{"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 in \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 \"../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# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import pandas as pd\nroot = '../input/ashrae-energy-prediction/'\ntrain_df = pd.read_csv(root + 'train.csv')\ntrain_df[\"timestamp\"] = pd.to_datetime(train_df[\"timestamp\"], format='%Y-%m-%d %H:%M:%S')\n\nweather_train_df = pd.read_csv(root + 'weather_train.csv')\ntest_df = pd.read_csv(root + 'test.csv')\nweather_test_df = pd.read_csv(root + 'weather_test.csv')\nbuilding_meta_df = pd.read_csv(root + 'building_metadata.csv')\nsample_submission = pd.read_csv(root + 'sample_submission.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<H2> Discovering data  roughly"},{"metadata":{"trusted":true},"cell_type":"code","source":"import seaborn as sns","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<H2> NaNs "},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.heatmap(building_meta_df.isnull(), cbar=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.heatmap(weather_train_df.isnull(), cbar=False)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<H2>Which site has how many building ? "},{"metadata":{"trusted":true},"cell_type":"code","source":"sitelist = list(building_meta_df.site_id.unique())\nSitePareto = [len(building_meta_df[building_meta_df.site_id == i].building_id.unique()) for i in sitelist ]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom matplotlib.ticker import PercentFormatter\nfrom matplotlib import rcParams","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"SitePareto = pd.DataFrame(SitePareto)\nSitePareto.columns = [\"BuildingQuantity\"]\nSitePareto.index = ['Site {}'.format(i)  for i in range(16)]\nSitePareto = SitePareto.sort_values(by=\"BuildingQuantity\",ascending=False)\nSitePareto[\"cumpercentage\"] = SitePareto[\"BuildingQuantity\"].cumsum()/SitePareto[\"BuildingQuantity\"].sum()*100","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"rcParams['figure.figsize'] = 15, 5\nfig, ax = plt.subplots()\nax.bar(SitePareto.index, SitePareto[\"BuildingQuantity\"], color=\"C0\")\nax2 = ax.twinx()\nax2.plot(SitePareto.index, SitePareto[\"cumpercentage\"], color=\"C1\", marker=\"D\", ms=7)\nax2.yaxis.set_major_formatter(PercentFormatter())\nax.tick_params(axis=\"y\", colors=\"C0\")\nax2.tick_params(axis=\"y\", colors=\"C1\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<H2> Site 3 has much more buildings than rest. Therefore, i will analyze it first."},{"metadata":{},"cell_type":"markdown","source":"<h2>Corr plot"},{"metadata":{"trusted":true},"cell_type":"code","source":"corr = weather_train_df[weather_train_df.site_id == 13].corr()\nmask = np.zeros_like(corr, dtype=np.bool)\nmask[np.triu_indices_from(mask)] = True\nf, ax = plt.subplots(figsize=(11, 9))\ncmap = sns.diverging_palette(220, 10, as_cmap=True)\nsns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0,square=True, linewidths=.5, cbar_kws={\"shrink\": .5})","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<li> sea level pressure variance increases, when air pressure and evaporation temperature decrease."},{"metadata":{"trusted":true},"cell_type":"code","source":"rcParams['figure.figsize'] = 12, 8\nimport matplotlib.dates as mdates\ndata=weather_train_df[weather_train_df.site_id ==13]\ndata=data.reset_index(drop=True)\nyears = mdates.YearLocator()   \nfig, ax = plt.subplots()\nax.plot('timestamp', 'dew_temperature', data=data,color=\"k\")\nplt.legend()\nax.plot('timestamp', 'air_temperature', data=data,color=\"g\",alpha=0.7)\nplt.legend()\nax2 = ax.twinx()\nax2.plot('timestamp', 'sea_level_pressure', data=data,color=\"r\",alpha=0.3)\nax.xaxis.set_major_locator(years)\nplt.legend()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Visualization Function \ndef polar(a):\n    df = weather_train_df[weather_train_df.site_id ==a]\n    df = df.reset_index(drop=True)\n    N = 360\n    polarDataRad=[(i*np.pi)/180  for i in range (360)]\n    polarDataQua=[len(df[df[\"wind_direction\"]==i])  for i in range (360)]\n    polarDataSpeed=[np.mean(df[df[\"wind_direction\"]==i][\"wind_speed\"])  for i in range (360)]\n    polarDataAirTemp=[np.mean(df[df[\"wind_direction\"]==i][\"air_temperature\"])  for i in range (360)]\n    width = [0.2 for i in range(360)]\n    DataRad = np.array(polarDataRad)\n    DataQua = np.array(polarDataQua)\n    Dataspeed = np.array(polarDataSpeed)\n    DataTemp = np.array(polarDataAirTemp)\n    width = np.array(width)\n    fig, (ax1, ax2, ax3) = plt.subplots(1, 3, subplot_kw=dict(projection='polar'))\n    ax1.bar( DataRad, DataQua, width=width, bottom=0.0,  alpha=0.7 )\n    ax2.bar(DataRad,  Dataspeed, width=width, bottom=0.0,  alpha=0.7,color=\"r\")\n    ax3.bar(DataRad,  DataTemp, width=width, bottom=-0.1 , alpha=0.7,color=\"k\")\n    plt.tight_layout()\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<H2> Wind Direction distribution & Wind Speed vs Wind Direction & Air Temperature vs Wind Direction"},{"metadata":{"trusted":true},"cell_type":"code","source":"polar(3) # will be used for sites geographical orientation","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<H2>  Rainfall (cm**3/m2) comparison  between sites\n"},{"metadata":{},"cell_type":"markdown","source":"<li> first, Site based NaN check "},{"metadata":{"trusted":true},"cell_type":"code","source":"for i in range(16):\n    print(\"Site İd:{} have {}/{} % {} missing vaule for precipitation\".format(i,weather_train_df[weather_train_df.site_id == i].precip_depth_1_hr.isnull().sum(),\n                                                                      len(weather_train_df[weather_train_df.site_id == i].precip_depth_1_hr),\n                                                                      np.round((weather_train_df[weather_train_df.site_id == i].precip_depth_1_hr.isnull().sum()/\n                                                                      len(weather_train_df[weather_train_df.site_id == i].precip_depth_1_hr))*100)                                                                                                                                          \n                                                                     ))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<H3> Site id 1 , 5 , 7 , 11 , 12 , 15 do not have sufficent data for Precipitation. "},{"metadata":{"trusted":true},"cell_type":"code","source":"","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":1}