{"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)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline\nsns.set_style('darkgrid')\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":"2023-01-08T10:16:43.970354Z","iopub.execute_input":"2023-01-08T10:16:43.970766Z","iopub.status.idle":"2023-01-08T10:16:44.773283Z","shell.execute_reply.started":"2023-01-08T10:16:43.970691Z","shell.execute_reply":"2023-01-08T10:16:44.772435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/test.csv\")\nprint(\"Train Set:\", train.shape, \"Test Set:\", test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:17:01.541872Z","iopub.execute_input":"2023-01-08T10:17:01.542240Z","iopub.status.idle":"2023-01-08T10:17:15.524092Z","shell.execute_reply.started":"2023-01-08T10:17:01.542212Z","shell.execute_reply":"2023-01-08T10:17:15.523276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(train.head())\ndisplay(test.head())","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:17:31.629596Z","iopub.execute_input":"2023-01-08T10:17:31.629904Z","iopub.status.idle":"2023-01-08T10:17:31.774046Z","shell.execute_reply.started":"2023-01-08T10:17:31.629879Z","shell.execute_reply":"2023-01-08T10:17:31.773117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"float_columns = [x for x in test.columns if test[x].dtypes == 'float64']\nint_columns = [x for x in test.columns if test[x].dtypes == 'int64']","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:17:48.376328Z","iopub.execute_input":"2023-01-08T10:17:48.376736Z","iopub.status.idle":"2023-01-08T10:17:48.383326Z","shell.execute_reply.started":"2023-01-08T10:17:48.376707Z","shell.execute_reply":"2023-01-08T10:17:48.382249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(1,11):\n    train[f'ch{i}'] = train.f_27.str.get(i-1).apply(ord) - ord('A')\n    test[f'ch{i}'] = train.f_27.str.get(i-1).apply(ord) - ord('A')","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:17:58.514235Z","iopub.execute_input":"2023-01-08T10:17:58.514580Z","iopub.status.idle":"2023-01-08T10:18:10.194540Z","shell.execute_reply.started":"2023-01-08T10:17:58.514554Z","shell.execute_reply":"2023-01-08T10:18:10.193547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['f_27i'] = train['ch1']+train['ch2']+train['ch3']+train['ch4']+train['ch5']+train['ch6']+train['ch7']+train['ch8']+train['ch9']+train['ch10']\ntest['f_27i'] = test['ch1']+test['ch2']+test['ch3']+test['ch4']+test['ch5']+test['ch6']+test['ch7']+test['ch8']+test['ch9']+test['ch10']\n\ntrain = train.drop(['f_27', 'ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7', 'ch8', 'ch9', 'ch10'], axis=1)\ntest = test.drop(['f_27', 'ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'ch7', 'ch8', 'ch9', 'ch10'], axis=1)\nprint(\"Train Set:\", train.shape, \"Test Set:\", test.shape)\nint_columns.append('f_27i')","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:18:10.196300Z","iopub.execute_input":"2023-01-08T10:18:10.196594Z","iopub.status.idle":"2023-01-08T10:18:10.391994Z","shell.execute_reply.started":"2023-01-08T10:18:10.196569Z","shell.execute_reply":"2023-01-08T10:18:10.390937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(data=train, x='f_27i')","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:18:19.301906Z","iopub.execute_input":"2023-01-08T10:18:19.302228Z","iopub.status.idle":"2023-01-08T10:18:20.128495Z","shell.execute_reply.started":"2023-01-08T10:18:19.302202Z","shell.execute_reply":"2023-01-08T10:18:20.127776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(20,20))\nsns.heatmap(train.corr(), annot=True, fmt='.2f')","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:18:29.175506Z","iopub.execute_input":"2023-01-08T10:18:29.175825Z","iopub.status.idle":"2023-01-08T10:18:34.729579Z","shell.execute_reply.started":"2023-01-08T10:18:29.175800Z","shell.execute_reply":"2023-01-08T10:18:34.728918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(train['target'])","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:18:40.483270Z","iopub.execute_input":"2023-01-08T10:18:40.483628Z","iopub.status.idle":"2023-01-08T10:18:40.657122Z","shell.execute_reply.started":"2023-01-08T10:18:40.483602Z","shell.execute_reply":"2023-01-08T10:18:40.655911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Train shape: \", train.shape, \", and Test shape:\", test.shape, \".\")","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:18:50.449723Z","iopub.execute_input":"2023-01-08T10:18:50.450049Z","iopub.status.idle":"2023-01-08T10:18:50.455334Z","shell.execute_reply.started":"2023-01-08T10:18:50.450024Z","shell.execute_reply":"2023-01-08T10:18:50.454312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import MinMaxScaler\nfrom sklearn.model_selection import train_test_split\n\nfrom xgboost import XGBClassifier\n\nfrom sklearn.metrics import confusion_matrix, accuracy_score","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:19:00.283434Z","iopub.execute_input":"2023-01-08T10:19:00.283753Z","iopub.status.idle":"2023-01-08T10:19:00.436315Z","shell.execute_reply.started":"2023-01-08T10:19:00.283729Z","shell.execute_reply":"2023-01-08T10:19:00.435239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train.drop(columns='target')\ny = train['target']","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:19:08.165074Z","iopub.execute_input":"2023-01-08T10:19:08.165441Z","iopub.status.idle":"2023-01-08T10:19:08.206191Z","shell.execute_reply.started":"2023-01-08T10:19:08.165389Z","shell.execute_reply":"2023-01-08T10:19:08.205068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mms = MinMaxScaler()\n\nX_scaled = mms.fit_transform(X)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:19:16.412379Z","iopub.execute_input":"2023-01-08T10:19:16.412753Z","iopub.status.idle":"2023-01-08T10:19:16.621433Z","shell.execute_reply.started":"2023-01-08T10:19:16.412726Z","shell.execute_reply":"2023-01-08T10:19:16.620560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_valid, y_train, y_valid = train_test_split(X_scaled, y, test_size=0.2, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:19:25.910208Z","iopub.execute_input":"2023-01-08T10:19:25.910552Z","iopub.status.idle":"2023-01-08T10:19:26.150536Z","shell.execute_reply.started":"2023-01-08T10:19:25.910523Z","shell.execute_reply":"2023-01-08T10:19:26.149634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgc = XGBClassifier(objective='binary:logistic')","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:19:34.254007Z","iopub.execute_input":"2023-01-08T10:19:34.254315Z","iopub.status.idle":"2023-01-08T10:19:34.259598Z","shell.execute_reply.started":"2023-01-08T10:19:34.254292Z","shell.execute_reply":"2023-01-08T10:19:34.258349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgc.fit(X_train, y_train)\n\nxgcpreds = xgc.predict(X_valid)\n\nprint(\"XGC ACCURACY SCORE:\", accuracy_score(y_valid, xgcpreds))","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:19:44.844703Z","iopub.execute_input":"2023-01-08T10:19:44.845033Z","iopub.status.idle":"2023-01-08T10:21:43.532522Z","shell.execute_reply.started":"2023-01-08T10:19:44.845009Z","shell.execute_reply":"2023-01-08T10:21:43.531498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(confusion_matrix(y_valid, xgcpreds))","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:21:43.533889Z","iopub.execute_input":"2023-01-08T10:21:43.534367Z","iopub.status.idle":"2023-01-08T10:21:43.566146Z","shell.execute_reply.started":"2023-01-08T10:21:43.534339Z","shell.execute_reply":"2023-01-08T10:21:43.565155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test_scaled = mms.fit_transform(test)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:24:36.487901Z","iopub.execute_input":"2023-01-08T10:24:36.488235Z","iopub.status.idle":"2023-01-08T10:24:36.649008Z","shell.execute_reply.started":"2023-01-08T10:24:36.488210Z","shell.execute_reply":"2023-01-08T10:24:36.648182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output = xgc.predict(X_test_scaled)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:24:46.872763Z","iopub.execute_input":"2023-01-08T10:24:46.873118Z","iopub.status.idle":"2023-01-08T10:24:47.561020Z","shell.execute_reply.started":"2023-01-08T10:24:46.873090Z","shell.execute_reply":"2023-01-08T10:24:47.560328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subb = pd.read_csv('/kaggle/input/emsi-5iir-ds/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:25:11.943830Z","iopub.execute_input":"2023-01-08T10:25:11.944160Z","iopub.status.idle":"2023-01-08T10:25:12.156305Z","shell.execute_reply.started":"2023-01-08T10:25:11.944135Z","shell.execute_reply":"2023-01-08T10:25:12.155447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subb.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:25:19.169041Z","iopub.execute_input":"2023-01-08T10:25:19.169376Z","iopub.status.idle":"2023-01-08T10:25:19.181893Z","shell.execute_reply.started":"2023-01-08T10:25:19.169350Z","shell.execute_reply":"2023-01-08T10:25:19.181258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subb['target'] = output\nsubb.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:25:28.608193Z","iopub.execute_input":"2023-01-08T10:25:28.608612Z","iopub.status.idle":"2023-01-08T10:25:28.619179Z","shell.execute_reply.started":"2023-01-08T10:25:28.608578Z","shell.execute_reply":"2023-01-08T10:25:28.618160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subb['target'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:25:39.041802Z","iopub.execute_input":"2023-01-08T10:25:39.042397Z","iopub.status.idle":"2023-01-08T10:25:39.055099Z","shell.execute_reply.started":"2023-01-08T10:25:39.042362Z","shell.execute_reply":"2023-01-08T10:25:39.054340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subb.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T10:25:48.607489Z","iopub.execute_input":"2023-01-08T10:25:48.607828Z","iopub.status.idle":"2023-01-08T10:25:49.186844Z","shell.execute_reply.started":"2023-01-08T10:25:48.607802Z","shell.execute_reply":"2023-01-08T10:25:49.185936Z"},"trusted":true},"execution_count":null,"outputs":[]}]}