{"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_minor":4,"nbformat":4,"cells":[{"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)\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\ny_test = pd.read_csv('y_test.csv')\ny_train = pd.read_csv('y_train.csv')\nx_test = pd.read_csv('x_test.csv')\nx_train = pd.read_csv('x_train.csv')","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","tags":[],"execution":{"iopub.status.busy":"2022-01-09T21:23:49.945901Z","iopub.execute_input":"2022-01-09T21:23:49.946263Z","iopub.status.idle":"2022-01-09T21:25:25.385865Z","shell.execute_reply.started":"2022-01-09T21:23:49.946156Z","shell.execute_reply":"2022-01-09T21:25:25.384984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Models implementation","metadata":{}},{"cell_type":"markdown","source":"#### We already implemented 3 models in Kaggle notebook (LR, SGD Regressor and LGBM) on new_train and validation (Which are splitted from train to choose the model \"LGBM\"), then we fine tuned LGBM and trained it on all training data","metadata":{}},{"cell_type":"code","source":"from sklearn.metrics import mean_absolute_error\nfrom sklearn.metrics import mean_squared_error\n\ndef performance(ytrue, ypredicted):\n    print(\"MSE: \",np.sqrt(mean_squared_error(ytrue, ypredicted))) \n    print(\"MAE: \", np.sqrt(mean_absolute_error(ytrue, ypredicted))) ","metadata":{"tags":[],"execution":{"iopub.status.busy":"2022-01-09T21:25:25.387926Z","iopub.execute_input":"2022-01-09T21:25:25.388203Z","iopub.status.idle":"2022-01-09T21:25:25.517942Z","shell.execute_reply.started":"2022-01-09T21:25:25.388165Z","shell.execute_reply":"2022-01-09T21:25:25.517157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Light GBM","metadata":{}},{"cell_type":"code","source":"#!pip install lightgbm","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import lightgbm as lgb\nmodel = lgb.LGBMRegressor(objective='regression',num_leaves=5,\n                              learning_rate=0.05, n_estimators=720,\n                              max_bin = 55, bagging_fraction = 0.8,\n                              bagging_freq = 5, feature_fraction = 0.2319,\n                              feature_fraction_seed=9, bagging_seed=9,\n                              min_data_in_leaf =6, min_sum_hessian_in_leaf = 11)\nmodel.fit(x_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-01-09T21:25:25.519351Z","iopub.execute_input":"2022-01-09T21:25:25.520187Z","iopub.status.idle":"2022-01-09T21:34:45.995196Z","shell.execute_reply.started":"2022-01-09T21:25:25.520145Z","shell.execute_reply":"2022-01-09T21:34:45.994588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del y_test;\ndel y_train;\ndel x_test;\ndel x_train;\n\nimport gc;\ngc.collect();","metadata":{"execution":{"iopub.status.busy":"2022-01-09T21:34:45.997768Z","iopub.execute_input":"2022-01-09T21:34:45.998040Z","iopub.status.idle":"2022-01-09T21:34:46.238759Z","shell.execute_reply.started":"2022-01-09T21:34:45.998003Z","shell.execute_reply":"2022-01-09T21:34:46.237917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"weather_test = pd.read_csv('/kaggle/input/ashrae-energy-prediction/weather_test.csv')\ntest = pd.read_csv('/kaggle/input/ashrae-energy-prediction/test.csv')\nbuilding_metadata = pd.read_csv('/kaggle/input/ashrae-energy-prediction/building_metadata.csv')\n\ntest = pd.merge(test,building_metadata,how = 'left') \ntest = pd.merge(test,weather_test, on = ['site_id','timestamp'], how = 'left')","metadata":{"execution":{"iopub.status.busy":"2022-01-09T21:34:50.621688Z","iopub.execute_input":"2022-01-09T21:34:50.622455Z","iopub.status.idle":"2022-01-09T21:35:36.975648Z","shell.execute_reply.started":"2022-01-09T21:34:50.622410Z","shell.execute_reply":"2022-01-09T21:35:36.974797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect();","metadata":{"execution":{"iopub.status.busy":"2022-01-09T21:36:32.501626Z","iopub.execute_input":"2022-01-09T21:36:32.502297Z","iopub.status.idle":"2022-01-09T21:36:32.646832Z","shell.execute_reply.started":"2022-01-09T21:36:32.502254Z","shell.execute_reply":"2022-01-09T21:36:32.645886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### We could not take the test data provided by kaggle, as after we do preprocessing the RAM is full.","metadata":{}},{"cell_type":"code","source":"y_lgbm = model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-01-09T21:35:42.578014Z","iopub.execute_input":"2022-01-09T21:35:42.578327Z","iopub.status.idle":"2022-01-09T21:35:42.751123Z","shell.execute_reply.started":"2022-01-09T21:35:42.578292Z","shell.execute_reply":"2022-01-09T21:35:42.750096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\nsubmission = pd.DataFrame(y_lgbm)","metadata":{"execution":{"iopub.status.busy":"2022-01-09T20:59:58.901826Z","iopub.execute_input":"2022-01-09T20:59:58.902142Z","iopub.status.idle":"2022-01-09T20:59:58.907545Z","shell.execute_reply.started":"2022-01-09T20:59:58.902108Z","shell.execute_reply":"2022-01-09T20:59:58.906498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_2.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-01-09T21:00:18.409307Z","iopub.execute_input":"2022-01-09T21:00:18.410105Z","iopub.status.idle":"2022-01-09T21:00:23.477615Z","shell.execute_reply.started":"2022-01-09T21:00:18.410063Z","shell.execute_reply":"2022-01-09T21:00:23.476806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}