{"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":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":1.03161,"end_time":"2023-01-08T10:26:54.385152","exception":false,"start_time":"2023-01-08T10:26:53.353542","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-01-08T14:13:21.481475Z","iopub.execute_input":"2023-01-08T14:13:21.481955Z","iopub.status.idle":"2023-01-08T14:13:22.537421Z","shell.execute_reply.started":"2023-01-08T14:13:21.481856Z","shell.execute_reply":"2023-01-08T14:13:22.535605Z"},"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.execute_input":"2023-01-08T10:26:54.404924Z","iopub.status.busy":"2023-01-08T10:26:54.402749Z","iopub.status.idle":"2023-01-08T10:27:09.734888Z","shell.execute_reply":"2023-01-08T10:27:09.732873Z"},"papermill":{"duration":15.345576,"end_time":"2023-01-08T10:27:09.738320","exception":false,"start_time":"2023-01-08T10:26:54.392744","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(train.head())\ndisplay(test.head())","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:27:09.753508Z","iopub.status.busy":"2023-01-08T10:27:09.752625Z","iopub.status.idle":"2023-01-08T10:27:09.808334Z","shell.execute_reply":"2023-01-08T10:27:09.807176Z"},"papermill":{"duration":0.065901,"end_time":"2023-01-08T10:27:09.811107","exception":false,"start_time":"2023-01-08T10:27:09.745206","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()\ntrain.info()","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:27:09.827453Z","iopub.status.busy":"2023-01-08T10:27:09.826711Z","iopub.status.idle":"2023-01-08T10:27:10.047439Z","shell.execute_reply":"2023-01-08T10:27:10.045970Z"},"papermill":{"duration":0.234437,"end_time":"2023-01-08T10:27:10.052720","exception":false,"start_time":"2023-01-08T10:27:09.818283","status":"completed"},"tags":[]},"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.execute_input":"2023-01-08T10:27:10.083966Z","iopub.status.busy":"2023-01-08T10:27:10.082940Z","iopub.status.idle":"2023-01-08T10:27:10.092891Z","shell.execute_reply":"2023-01-08T10:27:10.091693Z"},"papermill":{"duration":0.0318,"end_time":"2023-01-08T10:27:10.095501","exception":false,"start_time":"2023-01-08T10:27:10.063701","status":"completed"},"tags":[]},"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.execute_input":"2023-01-08T10:27:10.112730Z","iopub.status.busy":"2023-01-08T10:27:10.112182Z","iopub.status.idle":"2023-01-08T10:27:24.968279Z","shell.execute_reply":"2023-01-08T10:27:24.967052Z"},"papermill":{"duration":14.867898,"end_time":"2023-01-08T10:27:24.971164","exception":false,"start_time":"2023-01-08T10:27:10.103266","status":"completed"},"tags":[]},"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.execute_input":"2023-01-08T10:27:24.987491Z","iopub.status.busy":"2023-01-08T10:27:24.986785Z","iopub.status.idle":"2023-01-08T10:27:25.439278Z","shell.execute_reply":"2023-01-08T10:27:25.437943Z"},"papermill":{"duration":0.463195,"end_time":"2023-01-08T10:27:25.441754","exception":false,"start_time":"2023-01-08T10:27:24.978559","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(data=train, x='f_27i')","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:27:25.459830Z","iopub.status.busy":"2023-01-08T10:27:25.459439Z","iopub.status.idle":"2023-01-08T10:27:26.579882Z","shell.execute_reply":"2023-01-08T10:27:26.578813Z"},"papermill":{"duration":1.133263,"end_time":"2023-01-08T10:27:26.582434","exception":false,"start_time":"2023-01-08T10:27:25.449171","status":"completed"},"tags":[]},"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.execute_input":"2023-01-08T10:27:26.598777Z","iopub.status.busy":"2023-01-08T10:27:26.598397Z","iopub.status.idle":"2023-01-08T10:27:34.739479Z","shell.execute_reply":"2023-01-08T10:27:34.738349Z"},"papermill":{"duration":8.155059,"end_time":"2023-01-08T10:27:34.744911","exception":false,"start_time":"2023-01-08T10:27:26.589852","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(train['target'])","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:27:34.769732Z","iopub.status.busy":"2023-01-08T10:27:34.769256Z","iopub.status.idle":"2023-01-08T10:27:35.028720Z","shell.execute_reply":"2023-01-08T10:27:35.027879Z"},"papermill":{"duration":0.27437,"end_time":"2023-01-08T10:27:35.030943","exception":false,"start_time":"2023-01-08T10:27:34.756573","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Train shape: \", train.shape, \", and Test shape:\", test.shape, \".\")","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:27:35.056588Z","iopub.status.busy":"2023-01-08T10:27:35.055889Z","iopub.status.idle":"2023-01-08T10:27:35.061244Z","shell.execute_reply":"2023-01-08T10:27:35.060212Z"},"papermill":{"duration":0.021308,"end_time":"2023-01-08T10:27:35.064161","exception":false,"start_time":"2023-01-08T10:27:35.042853","status":"completed"},"tags":[]},"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.execute_input":"2023-01-08T10:27:35.090233Z","iopub.status.busy":"2023-01-08T10:27:35.089107Z","iopub.status.idle":"2023-01-08T10:27:35.354532Z","shell.execute_reply":"2023-01-08T10:27:35.353684Z"},"papermill":{"duration":0.281445,"end_time":"2023-01-08T10:27:35.357411","exception":false,"start_time":"2023-01-08T10:27:35.075966","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train.drop(columns='target')\ny = train['target']","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:27:35.383751Z","iopub.status.busy":"2023-01-08T10:27:35.382548Z","iopub.status.idle":"2023-01-08T10:27:35.468235Z","shell.execute_reply":"2023-01-08T10:27:35.467091Z"},"papermill":{"duration":0.101342,"end_time":"2023-01-08T10:27:35.471061","exception":false,"start_time":"2023-01-08T10:27:35.369719","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mms = MinMaxScaler()\n\nX_scaled = mms.fit_transform(X)","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:27:35.496562Z","iopub.status.busy":"2023-01-08T10:27:35.495730Z","iopub.status.idle":"2023-01-08T10:27:35.971598Z","shell.execute_reply":"2023-01-08T10:27:35.970671Z"},"papermill":{"duration":0.491591,"end_time":"2023-01-08T10:27:35.974332","exception":false,"start_time":"2023-01-08T10:27:35.482741","status":"completed"},"tags":[]},"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.execute_input":"2023-01-08T10:27:36.000120Z","iopub.status.busy":"2023-01-08T10:27:35.999359Z","iopub.status.idle":"2023-01-08T10:27:36.453457Z","shell.execute_reply":"2023-01-08T10:27:36.452396Z"},"papermill":{"duration":0.469764,"end_time":"2023-01-08T10:27:36.456240","exception":false,"start_time":"2023-01-08T10:27:35.986476","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgc = XGBClassifier(objective='binary:logistic')","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:27:36.482212Z","iopub.status.busy":"2023-01-08T10:27:36.481838Z","iopub.status.idle":"2023-01-08T10:27:36.486969Z","shell.execute_reply":"2023-01-08T10:27:36.485695Z"},"papermill":{"duration":0.020795,"end_time":"2023-01-08T10:27:36.489207","exception":false,"start_time":"2023-01-08T10:27:36.468412","status":"completed"},"tags":[]},"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.execute_input":"2023-01-08T10:27:36.514614Z","iopub.status.busy":"2023-01-08T10:27:36.513570Z","iopub.status.idle":"2023-01-08T10:30:44.357947Z","shell.execute_reply":"2023-01-08T10:30:44.357103Z"},"papermill":{"duration":187.871343,"end_time":"2023-01-08T10:30:44.372271","exception":false,"start_time":"2023-01-08T10:27:36.500928","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(confusion_matrix(y_valid, xgcpreds))","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:30:44.398836Z","iopub.status.busy":"2023-01-08T10:30:44.398412Z","iopub.status.idle":"2023-01-08T10:30:44.444659Z","shell.execute_reply":"2023-01-08T10:30:44.443394Z"},"papermill":{"duration":0.062606,"end_time":"2023-01-08T10:30:44.447052","exception":false,"start_time":"2023-01-08T10:30:44.384446","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test_scaled = mms.fit_transform(test)","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:30:44.473905Z","iopub.status.busy":"2023-01-08T10:30:44.473485Z","iopub.status.idle":"2023-01-08T10:30:44.819940Z","shell.execute_reply":"2023-01-08T10:30:44.818912Z"},"papermill":{"duration":0.362809,"end_time":"2023-01-08T10:30:44.822615","exception":false,"start_time":"2023-01-08T10:30:44.459806","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output = xgc.predict(X_test_scaled)","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:30:44.849138Z","iopub.status.busy":"2023-01-08T10:30:44.848347Z","iopub.status.idle":"2023-01-08T10:30:45.642520Z","shell.execute_reply":"2023-01-08T10:30:45.641544Z"},"papermill":{"duration":0.810751,"end_time":"2023-01-08T10:30:45.645583","exception":false,"start_time":"2023-01-08T10:30:44.834832","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subb = pd.read_csv('/kaggle/input/emsi-5iir-ds/sample_submission.csv')","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:30:45.671476Z","iopub.status.busy":"2023-01-08T10:30:45.671093Z","iopub.status.idle":"2023-01-08T10:30:45.876663Z","shell.execute_reply":"2023-01-08T10:30:45.875806Z"},"papermill":{"duration":0.221471,"end_time":"2023-01-08T10:30:45.879296","exception":false,"start_time":"2023-01-08T10:30:45.657825","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subb.head()","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:30:45.905315Z","iopub.status.busy":"2023-01-08T10:30:45.904933Z","iopub.status.idle":"2023-01-08T10:30:45.915086Z","shell.execute_reply":"2023-01-08T10:30:45.914028Z"},"papermill":{"duration":0.026189,"end_time":"2023-01-08T10:30:45.917756","exception":false,"start_time":"2023-01-08T10:30:45.891567","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subb['target'] = output\nsubb.head()","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:30:45.944835Z","iopub.status.busy":"2023-01-08T10:30:45.943682Z","iopub.status.idle":"2023-01-08T10:30:45.956115Z","shell.execute_reply":"2023-01-08T10:30:45.955096Z"},"papermill":{"duration":0.028369,"end_time":"2023-01-08T10:30:45.958404","exception":false,"start_time":"2023-01-08T10:30:45.930035","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subb['target'].value_counts()","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:30:45.985556Z","iopub.status.busy":"2023-01-08T10:30:45.984760Z","iopub.status.idle":"2023-01-08T10:30:45.999732Z","shell.execute_reply":"2023-01-08T10:30:45.998679Z"},"papermill":{"duration":0.031283,"end_time":"2023-01-08T10:30:46.002081","exception":false,"start_time":"2023-01-08T10:30:45.970798","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subb.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.execute_input":"2023-01-08T10:30:46.029403Z","iopub.status.busy":"2023-01-08T10:30:46.028508Z","iopub.status.idle":"2023-01-08T10:30:46.733641Z","shell.execute_reply":"2023-01-08T10:30:46.732158Z"},"papermill":{"duration":0.721982,"end_time":"2023-01-08T10:30:46.736532","exception":false,"start_time":"2023-01-08T10:30:46.014550","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]}]}