{"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 pandas as pd\nimport numpy as np \nimport matplotlib.pyplot as plt \nimport seaborn as sns \nfrom sklearn import preprocessing","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:08:21.466501Z","iopub.execute_input":"2022-07-07T08:08:21.466970Z","iopub.status.idle":"2022-07-07T08:08:22.766599Z","shell.execute_reply.started":"2022-07-07T08:08:21.466875Z","shell.execute_reply":"2022-07-07T08:08:22.765150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train= pd.read_csv('../input/tabular-playground-series-aug-2021/train.csv')\ntest= pd.read_csv('../input/tabular-playground-series-aug-2021/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:08:22.769361Z","iopub.execute_input":"2022-07-07T08:08:22.770173Z","iopub.status.idle":"2022-07-07T08:08:33.564898Z","shell.execute_reply.started":"2022-07-07T08:08:22.770124Z","shell.execute_reply":"2022-07-07T08:08:33.563793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:08:33.566551Z","iopub.execute_input":"2022-07-07T08:08:33.567070Z","iopub.status.idle":"2022-07-07T08:08:33.608137Z","shell.execute_reply.started":"2022-07-07T08:08:33.567003Z","shell.execute_reply":"2022-07-07T08:08:33.606689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:08:33.611068Z","iopub.execute_input":"2022-07-07T08:08:33.611424Z","iopub.status.idle":"2022-07-07T08:08:33.619258Z","shell.execute_reply.started":"2022-07-07T08:08:33.611392Z","shell.execute_reply":"2022-07-07T08:08:33.617862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:08:33.620921Z","iopub.execute_input":"2022-07-07T08:08:33.621735Z","iopub.status.idle":"2022-07-07T08:08:33.634310Z","shell.execute_reply.started":"2022-07-07T08:08:33.621687Z","shell.execute_reply":"2022-07-07T08:08:33.632678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:08:33.636811Z","iopub.execute_input":"2022-07-07T08:08:33.637320Z","iopub.status.idle":"2022-07-07T08:08:33.703685Z","shell.execute_reply.started":"2022-07-07T08:08:33.637273Z","shell.execute_reply":"2022-07-07T08:08:33.702805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntest.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:08:33.705167Z","iopub.execute_input":"2022-07-07T08:08:33.705484Z","iopub.status.idle":"2022-07-07T08:08:33.748665Z","shell.execute_reply.started":"2022-07-07T08:08:33.705454Z","shell.execute_reply":"2022-07-07T08:08:33.747789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(1,99):\n    sns.distplot(train.iloc[:,i])\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:08:33.750500Z","iopub.execute_input":"2022-07-07T08:08:33.751361Z","iopub.status.idle":"2022-07-07T08:09:07.755314Z","shell.execute_reply.started":"2022-07-07T08:08:33.751320Z","shell.execute_reply":"2022-07-07T08:09:07.750935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.756237Z","iopub.status.idle":"2022-07-07T08:09:07.756658Z","shell.execute_reply.started":"2022-07-07T08:09:07.756451Z","shell.execute_reply":"2022-07-07T08:09:07.756472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(1,99):\n    sns.boxplot(train.iloc[:,i])\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.758593Z","iopub.status.idle":"2022-07-07T08:09:07.759279Z","shell.execute_reply.started":"2022-07-07T08:09:07.758933Z","shell.execute_reply":"2022-07-07T08:09:07.758963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Remove outliers with standard devi","metadata":{}},{"cell_type":"code","source":"from scipy import stats\nz_scores = stats.zscore(train)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.761731Z","iopub.status.idle":"2022-07-07T08:09:07.762421Z","shell.execute_reply.started":"2022-07-07T08:09:07.762070Z","shell.execute_reply":"2022-07-07T08:09:07.762101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"abs_z_scores = np.abs(z_scores)\nfiltered_entries = (abs_z_scores < 3).all(axis=1)\nnew_df = train[filtered_entries]","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.764385Z","iopub.status.idle":"2022-07-07T08:09:07.765033Z","shell.execute_reply.started":"2022-07-07T08:09:07.764690Z","shell.execute_reply":"2022-07-07T08:09:07.764721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.767930Z","iopub.status.idle":"2022-07-07T08:09:07.768383Z","shell.execute_reply.started":"2022-07-07T08:09:07.768169Z","shell.execute_reply":"2022-07-07T08:09:07.768191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nscaler = StandardScaler()\nmodel = scaler.fit(new_df)\nscaled_data = model.transform(new_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:15.643176Z","iopub.execute_input":"2022-07-07T08:09:15.643558Z","iopub.status.idle":"2022-07-07T08:09:15.663729Z","shell.execute_reply.started":"2022-07-07T08:09:15.643526Z","shell.execute_reply":"2022-07-07T08:09:15.661625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaled_data","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.772553Z","iopub.status.idle":"2022-07-07T08:09:07.773557Z","shell.execute_reply.started":"2022-07-07T08:09:07.773332Z","shell.execute_reply":"2022-07-07T08:09:07.773353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"standardscal=pd.DataFrame(scaled_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.774913Z","iopub.status.idle":"2022-07-07T08:09:07.775630Z","shell.execute_reply.started":"2022-07-07T08:09:07.775411Z","shell.execute_reply":"2022-07-07T08:09:07.775432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"standardscal","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.776984Z","iopub.status.idle":"2022-07-07T08:09:07.777900Z","shell.execute_reply.started":"2022-07-07T08:09:07.777645Z","shell.execute_reply":"2022-07-07T08:09:07.777669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import MinMaxScaler\nscaler1 = MinMaxScaler()\nminmax=scaler1.fit(new_df)\nscaled=minmax.transform(new_df)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.779204Z","iopub.status.idle":"2022-07-07T08:09:07.779922Z","shell.execute_reply.started":"2022-07-07T08:09:07.779671Z","shell.execute_reply":"2022-07-07T08:09:07.779693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaled","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.781224Z","iopub.status.idle":"2022-07-07T08:09:07.781956Z","shell.execute_reply.started":"2022-07-07T08:09:07.781697Z","shell.execute_reply":"2022-07-07T08:09:07.781719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.DataFrame(scaled)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.783512Z","iopub.status.idle":"2022-07-07T08:09:07.783977Z","shell.execute_reply.started":"2022-07-07T08:09:07.783727Z","shell.execute_reply":"2022-07-07T08:09:07.783749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.785450Z","iopub.status.idle":"2022-07-07T08:09:07.785920Z","shell.execute_reply.started":"2022-07-07T08:09:07.785666Z","shell.execute_reply":"2022-07-07T08:09:07.785688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = train.drop(labels= 'loss', axis=1).values\ny = train.loss","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:25.639686Z","iopub.execute_input":"2022-07-07T08:09:25.640093Z","iopub.status.idle":"2022-07-07T08:09:25.828281Z","shell.execute_reply.started":"2022-07-07T08:09:25.640059Z","shell.execute_reply":"2022-07-07T08:09:25.826731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train, x_test, y_train, y_test = train_test_split(x, y , test_size=0.20)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:28.872021Z","iopub.execute_input":"2022-07-07T08:09:28.872422Z","iopub.status.idle":"2022-07-07T08:09:29.296121Z","shell.execute_reply.started":"2022-07-07T08:09:28.872389Z","shell.execute_reply":"2022-07-07T08:09:29.294991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(x_train.shape)\nprint(x_test.shape)\nprint(y_train.shape)\nprint(y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:31.110371Z","iopub.execute_input":"2022-07-07T08:09:31.110753Z","iopub.status.idle":"2022-07-07T08:09:31.117933Z","shell.execute_reply.started":"2022-07-07T08:09:31.110720Z","shell.execute_reply":"2022-07-07T08:09:31.116528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"XGboost","metadata":{}},{"cell_type":"code","source":"from xgboost import XGBRegressor","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:37.736044Z","iopub.execute_input":"2022-07-07T08:09:37.736418Z","iopub.status.idle":"2022-07-07T08:09:37.877402Z","shell.execute_reply.started":"2022-07-07T08:09:37.736386Z","shell.execute_reply":"2022-07-07T08:09:37.876295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = XGBRegressor()\nmodel.fit(x_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:40.705846Z","iopub.execute_input":"2022-07-07T08:09:40.706208Z","iopub.status.idle":"2022-07-07T08:13:05.017806Z","shell.execute_reply.started":"2022-07-07T08:09:40.706177Z","shell.execute_reply":"2022-07-07T08:13:05.016407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" y_pred = model.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:15:48.057734Z","iopub.execute_input":"2022-07-07T08:15:48.058137Z","iopub.status.idle":"2022-07-07T08:15:48.148105Z","shell.execute_reply.started":"2022-07-07T08:15:48.058105Z","shell.execute_reply":"2022-07-07T08:15:48.146858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Test","metadata":{}},{"cell_type":"code","source":"\nz_scores = stats.zscore(test)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.803613Z","iopub.status.idle":"2022-07-07T08:09:07.804294Z","shell.execute_reply.started":"2022-07-07T08:09:07.803958Z","shell.execute_reply":"2022-07-07T08:09:07.803990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"z_score = np.abs(z_scores)\nfiltered_entries = (z_score < 3).all(axis=1)\nnew_test = test[filtered_entries]","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:09:07.806140Z","iopub.status.idle":"2022-07-07T08:09:07.806793Z","shell.execute_reply.started":"2022-07-07T08:09:07.806439Z","shell.execute_reply":"2022-07-07T08:09:07.806469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:15:54.770583Z","iopub.execute_input":"2022-07-07T08:15:54.771016Z","iopub.status.idle":"2022-07-07T08:15:54.779152Z","shell.execute_reply.started":"2022-07-07T08:15:54.770983Z","shell.execute_reply":"2022-07-07T08:15:54.777540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:15:57.762210Z","iopub.execute_input":"2022-07-07T08:15:57.763471Z","iopub.status.idle":"2022-07-07T08:15:57.772264Z","shell.execute_reply.started":"2022-07-07T08:15:57.763420Z","shell.execute_reply":"2022-07-07T08:15:57.770852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_test =model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:16:00.660971Z","iopub.execute_input":"2022-07-07T08:16:00.661358Z","iopub.status.idle":"2022-07-07T08:16:00.976284Z","shell.execute_reply.started":"2022-07-07T08:16:00.661325Z","shell.execute_reply":"2022-07-07T08:16:00.975272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_test","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:16:03.125169Z","iopub.execute_input":"2022-07-07T08:16:03.125537Z","iopub.status.idle":"2022-07-07T08:16:03.132685Z","shell.execute_reply.started":"2022-07-07T08:16:03.125506Z","shell.execute_reply":"2022-07-07T08:16:03.131698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"c= y_pred_test","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:16:05.559188Z","iopub.execute_input":"2022-07-07T08:16:05.560084Z","iopub.status.idle":"2022-07-07T08:16:05.565266Z","shell.execute_reply.started":"2022-07-07T08:16:05.560047Z","shell.execute_reply":"2022-07-07T08:16:05.564086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"c","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:16:08.910101Z","iopub.execute_input":"2022-07-07T08:16:08.910987Z","iopub.status.idle":"2022-07-07T08:16:08.919514Z","shell.execute_reply.started":"2022-07-07T08:16:08.910948Z","shell.execute_reply":"2022-07-07T08:16:08.918214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import mean_squared_error\nfrom math import sqrt\n# calculate rmse on the training set \ny_train_hat = model.predict(x_train)\nrmse_train = sqrt(mean_squared_error(y_train_hat, y_train)) \nprint(f'training score = {rmse_train}')\n\n# calculate rmse on the valid set \ny_valid_hat = model.predict(x_test)\nrmse_vaild = sqrt(mean_squared_error(y_valid_hat, y_test)) \nprint(f'validation score = {rmse_vaild}')","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:16:11.001318Z","iopub.execute_input":"2022-07-07T08:16:11.002390Z","iopub.status.idle":"2022-07-07T08:16:11.413709Z","shell.execute_reply.started":"2022-07-07T08:16:11.002340Z","shell.execute_reply":"2022-07-07T08:16:11.412471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.index.name = 'id'","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:16:23.202652Z","iopub.execute_input":"2022-07-07T08:16:23.203070Z","iopub.status.idle":"2022-07-07T08:16:23.208792Z","shell.execute_reply.started":"2022-07-07T08:16:23.203038Z","shell.execute_reply":"2022-07-07T08:16:23.207456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.DataFrame(\n    {'id':test[\"id\"] ,\n     'loss': c},columns=['id', 'loss'])","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:16:28.863871Z","iopub.execute_input":"2022-07-07T08:16:28.864237Z","iopub.status.idle":"2022-07-07T08:16:28.878416Z","shell.execute_reply.started":"2022-07-07T08:16:28.864206Z","shell.execute_reply":"2022-07-07T08:16:28.877074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:16:32.435224Z","iopub.execute_input":"2022-07-07T08:16:32.436111Z","iopub.status.idle":"2022-07-07T08:16:32.450461Z","shell.execute_reply.started":"2022-07-07T08:16:32.436059Z","shell.execute_reply":"2022-07-07T08:16:32.449358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index=False)\nsubmission.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-07-07T08:16:35.560887Z","iopub.execute_input":"2022-07-07T08:16:35.561559Z","iopub.status.idle":"2022-07-07T08:16:35.949853Z","shell.execute_reply.started":"2022-07-07T08:16:35.561526Z","shell.execute_reply":"2022-07-07T08:16:35.948335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}