{"cells":[{"metadata":{},"cell_type":"markdown","source":"## TL; DR\n* Since the target variable is time series data, it's important to visualize as chart plot.\n* It's can be assumed that all the target variables has periodicity (daily, weekly, seasonally), but there must be more or less differences because each building has each operation's rule. The purpose of this notebook is to reveal the difference by plotting each building's target variable.\n* According to this [EDA](https://www.kaggle.com/jaseziv83/a-deep-dive-eda-into-all-variables), the difference mentioned above can be considered that it mainly comes from primary usage, so the charts are categorized by it."},{"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":{"trusted":true},"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/ashrae-energy-prediction/train.csv\")\nweather_train = pd.read_csv(\"/kaggle/input/ashrae-energy-prediction/weather_train.csv\")\nmeta = pd.read_csv(\"/kaggle/input/ashrae-energy-prediction/building_metadata.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train = train.merge(meta, left_on=\"building_id\", right_on=\"building_id\", how=\"left\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train = train.merge(weather_train, left_on=[\"site_id\", \"timestamp\"], right_on=[\"site_id\", \"timestamp\"])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train[\"timestamp\"] = pd.to_datetime(train[\"timestamp\"])\ntrain[\"meter\"] = train[\"meter\"].map({0: \"electricity\", 1: \"chilledwater\", 2: \"steam\", 3: \"hotwater\"})\ntrain[\"meter\"] = train[\"meter\"].astype(\"category\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Primary use"},{"metadata":{"trusted":true},"cell_type":"code","source":"meta[\"primary_use\"].value_counts().sort_values().plot.barh()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom IPython.display import Markdown, display","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# define plot func\ndef plot_train_primary_use(train_primary_use):\n    n_building = len(train_primary_use[\"building_id\"].unique())\n    n_col = 4\n    n_row = int(np.ceil(n_building / n_col))\n    f, ax = plt.subplots(n_row, n_col, squeeze=False, figsize=(20, 5 * n_row))\n\n    color_dict = {\"electricity\": \"y\", \"chilledwater\": \"b\", \"steam\": \"#800000\", \"hotwater\": \"#ff5500\"}\n\n    for i, building_id in enumerate(train_primary_use[\"building_id\"].unique()):\n        df_build = train_primary_use.query(\"building_id == @building_id\").reset_index()\n        df_build_piv = df_build.pivot(index=\"timestamp\", columns=\"meter\", values=\"meter_reading\")\n        df_build_piv.plot(ax=ax[i // n_col, i % n_col], color=[color_dict.get(x, '#000000') for x in df_build_piv.columns], alpha=0.7)\n        ax[i // n_col, i % n_col].set_title(\"building id: {}\".format(building_id))\n    plt.tight_layout()\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for primary_use in train[\"primary_use\"].unique():\n    display(Markdown(\"## {}\".format(primary_use)))\n    train_primary_use = train.query(\"primary_use == @primary_use\")\n    plot_train_primary_use(train_primary_use)","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}