{"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":"# 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\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 read-only \"../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# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-07T09:04:19.948416Z","iopub.execute_input":"2022-08-07T09:04:19.948799Z","iopub.status.idle":"2022-08-07T09:04:19.958726Z","shell.execute_reply.started":"2022-08-07T09:04:19.948768Z","shell.execute_reply":"2022-08-07T09:04:19.957771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/train.csv')\ntest = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-07T09:04:20.317343Z","iopub.execute_input":"2022-08-07T09:04:20.318096Z","iopub.status.idle":"2022-08-07T09:04:23.361541Z","shell.execute_reply.started":"2022-08-07T09:04:20.318059Z","shell.execute_reply":"2022-08-07T09:04:23.360461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-07T09:04:23.363341Z","iopub.execute_input":"2022-08-07T09:04:23.363718Z","iopub.status.idle":"2022-08-07T09:04:23.432725Z","shell.execute_reply.started":"2022-08-07T09:04:23.363685Z","shell.execute_reply":"2022-08-07T09:04:23.431566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T09:04:23.434231Z","iopub.execute_input":"2022-08-07T09:04:23.434569Z","iopub.status.idle":"2022-08-07T09:04:23.467469Z","shell.execute_reply.started":"2022-08-07T09:04:23.434538Z","shell.execute_reply":"2022-08-07T09:04:23.466331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop(\"id\", axis = 1, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T09:04:23.469974Z","iopub.execute_input":"2022-08-07T09:04:23.470321Z","iopub.status.idle":"2022-08-07T09:04:23.500715Z","shell.execute_reply.started":"2022-08-07T09:04:23.470286Z","shell.execute_reply":"2022-08-07T09:04:23.499469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor\n\nforest_reg = RandomForestRegressor(max_depth = 2, n_estimators = 100,random_state = 42)\nforest_reg.fit(train.drop(\"target\", axis = 1), train.target)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T09:04:23.569541Z","iopub.execute_input":"2022-08-07T09:04:23.569935Z","iopub.status.idle":"2022-08-07T09:06:03.371959Z","shell.execute_reply.started":"2022-08-07T09:04:23.569903Z","shell.execute_reply":"2022-08-07T09:06:03.370723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import mean_squared_error\ntrain_pred = forest_reg.predict(train.drop(\"target\", axis = 1))\nmean_squared_error(train_pred, train['target'])","metadata":{"execution":{"iopub.status.busy":"2022-08-07T09:06:03.374194Z","iopub.execute_input":"2022-08-07T09:06:03.374579Z","iopub.status.idle":"2022-08-07T09:06:04.042872Z","shell.execute_reply.started":"2022-08-07T09:06:03.374547Z","shell.execute_reply":"2022-08-07T09:06:04.041684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = forest_reg.predict(test.drop('id', axis = 1))\noutput = pd.DataFrame({'id':test['id'],'target':pred})\noutput.set_index('id',inplace=True)\noutput.to_csv('output.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-07T09:06:04.044368Z","iopub.execute_input":"2022-08-07T09:06:04.045118Z","iopub.status.idle":"2022-08-07T09:06:04.957187Z","shell.execute_reply.started":"2022-08-07T09:06:04.045087Z","shell.execute_reply":"2022-08-07T09:06:04.956061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-07T09:06:04.960332Z","iopub.execute_input":"2022-08-07T09:06:04.960800Z","iopub.status.idle":"2022-08-07T09:06:04.972034Z","shell.execute_reply.started":"2022-08-07T09:06:04.960755Z","shell.execute_reply":"2022-08-07T09:06:04.970798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub['target']=pred\nsub.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-07T09:07:07.122446Z","iopub.execute_input":"2022-08-07T09:07:07.122842Z","iopub.status.idle":"2022-08-07T09:07:07.557986Z","shell.execute_reply.started":"2022-08-07T09:07:07.122813Z","shell.execute_reply":"2022-08-07T09:07:07.556833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This is not the end of this notebook. \n\nFurther we will be trying out more regressors and create an ensemble to get best model for prediction.","metadata":{}}]}