{"cells":[{"metadata":{},"cell_type":"markdown","source":"# ASHRAE: interactive data visualization with plotly\n\nInfluecned by this awesome [notebook](https://www.kaggle.com/sudalairajkumar/simple-exploration-notebook-ashrae) by @sudalairajkumar,\nI tried to use plotly for data visualization to understand this ASHRAE competition!\n"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import gc\nimport os\nfrom pathlib import Path\nimport random\nimport sys\n\nimport tqdm\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom IPython.core.display import display, HTML\n\nfrom sklearn import preprocessing\nfrom sklearn.model_selection import KFold\nimport lightgbm as lgb\nimport xgboost as xgb\nimport catboost as cb\n\n# --- plotly ---\nfrom plotly import tools, subplots\nimport plotly.offline as py\npy.init_notebook_mode(connected=True)\nimport plotly.graph_objs as go\nimport plotly.express as px\nimport plotly.figure_factory as ff","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"%%time\nroot = Path('/kaggle/input/ashrae-feather-format-for-fast-loading')\n\n\ntrain_df = pd.read_feather(root/'train.feather')\ntest_df = pd.read_feather(root/'test.feather')\nweather_train_df = pd.read_feather(root/'weather_train.feather')\nweather_test_df = pd.read_feather(root/'weather_test.feather')\nbuilding_meta_df = pd.read_feather(root/'building_metadata.feather')\n#sample_submission = pd.read_feather(root/'sample_submission.feather')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('train_df', train_df.shape)\nprint('test_df', test_df.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"debug = False\nif debug:\n    train_df = train_df.iloc[:10000]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"markdown","source":"# meter"},{"metadata":{"trusted":true},"cell_type":"code","source":"meter_type_list = [\"Electricity\", \"ChilledWater\", \"Steam\", \"HotWater\"]\ncnt_srs = train_df[\"meter\"].value_counts()\ncnt_srs_df = cnt_srs.to_frame()\n\n# cnt_srs_df['meter_type'] = cnt_srs_df.index\ncnt_srs_df['meter_type'] = meter_type_list\ncnt_srs_df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.bar(cnt_srs_df, x='meter_type', y='meter', title='Number of rows for each meter type')\n# fig.update_layout(showlegend=True)\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# meter_reading distribution"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df['meter_reading_log1p'] = np.log1p(train_df['meter_reading'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sampled_train_df = train_df.sample(10000)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# It takes long time for whole train_df, so use...\n\nfig = px.histogram(sampled_train_df, x=\"meter_reading_log1p\", color=\"meter\", cumulative=False, opacity=0.4)\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = ff.create_distplot([sampled_train_df[sampled_train_df['meter'] == i]['meter_reading_log1p'] for i in range(4)],\n                         meter_type_list, bin_size=0.2, histnorm='probability')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# time series"},{"metadata":{},"cell_type":"markdown","source":"## meter_reading over time"},{"metadata":{"trusted":true},"cell_type":"code","source":"# target_building_id = 184\ntarget_building_id = 1298\ntemp_df = train_df[train_df[\"building_id\"]==target_building_id].reset_index(drop=True)\n\nfig = px.line(temp_df, x='timestamp', y='meter_reading_log1p', color='meter')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## weather"},{"metadata":{"trusted":true},"cell_type":"code","source":"weather_train_df.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"temp_weather_train_df = weather_train_df[(weather_train_df['site_id'] == 0) | (weather_train_df['site_id'] == 1) | (weather_train_df['site_id'] == 2)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.line(temp_weather_train_df, x='timestamp', y='air_temperature', color='site_id')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"`cloud_coverage` value ranges from 0 to 9?\n\nThere are many nan values, so how to handle it?\nInterpolating value is an idea that may improve performance."},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.line(temp_weather_train_df, x='timestamp', y='cloud_coverage', color='site_id')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"`dew_temperature`: considered high humid when dew temperature is high."},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.line(temp_weather_train_df, x='timestamp', y='dew_temperature', color='site_id')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.line(temp_weather_train_df, x='timestamp', y='precip_depth_1_hr', color='site_id')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.line(temp_weather_train_df, x='timestamp', y='sea_level_pressure', color='site_id')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig = px.line(temp_weather_train_df, x='timestamp', y='wind_direction', color='site_id')\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"weather_train_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"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}