{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import 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))\nfrom sklearn.preprocessing import LabelEncoder\nimport lightgbm as lgb\nfrom sklearn import metrics\nimport gc\nimport joblib","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def reduce_memory(df):\n    for c in df.columns:\n        if df[c].dtype=='int64':\n            df[c] = df[c].astype('int32')\n        elif df[c].dtype=='float64':\n            df[c] = df[c].astype('float32')\n    return df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test = pd.read_csv('../input/ashrae-energy-prediction/test.csv')\nsubmission = pd.read_csv('../input/ashrae-energy-prediction/sample_submission.csv')\nbuilding = pd.read_csv('../input/ashrae-energy-prediction/building_metadata.csv')\nweather_test = pd.read_csv('../input/ashrae-energy-prediction/weather_test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test = reduce_memory(test)\nweather_test = reduce_memory(weather_test)\nbuilding = reduce_memory(building)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"building['age'] = building['year_built'].max() - building['year_built'] + 1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"convert = {'Education': 0,\n 'Entertainment/public assembly': 1,\n 'Food sales and service': 2,\n 'Healthcare': 3,\n 'Lodging/residential': 4,\n 'Manufacturing/industrial': 5,\n 'Office': 6,\n 'Other': 7,\n 'Parking': 8,\n 'Public services': 9,\n 'Religious worship': 10,\n 'Retail': 11,\n 'Services': 12,\n 'Technology/science': 13,\n 'Utility': 14,\n 'Warehouse/storage': 15}","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"building['primary_use'] = building['primary_use'].map(convert)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test = pd.merge(test, building, on='building_id', how='left')\ntest = pd.merge(test, weather_test, on=['site_id','timestamp'], how='left')\ntest['timestamp'] = pd.to_datetime(test['timestamp'])\ntest['hour'] = test['timestamp'].dt.hour\ntest['weekday'] = test['timestamp'].dt.weekday\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\nfeatures = ['primary_use', 'square_feet', 'year_built', 'floor_count', 'age',\n       'air_temperature', 'cloud_coverage', 'dew_temperature',\n       'precip_depth_1_hr', 'sea_level_pressure', 'wind_direction',\n       'wind_speed', 'hour', 'weekday']\ntarget = ['meter_reading']\n\nfor meter in [0,1,2,3]:\n    x = test[test['meter']==meter][features]\n    model = joblib.load(f'../input/ashrae-3/model_{meter}.model')\n    pred = model.predict(x)\n    del x\n\n    pred = np.where(pred<0, 0, pred)\n    test.loc[test['meter']==meter, 'meter_reading'] = pred","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test[['row_id','meter_reading']].to_csv('submission.csv', index=False)","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}