{"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 \nimport pandas as pd \nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-07T21:10:01.053386Z","iopub.execute_input":"2023-01-07T21:10:01.053823Z","iopub.status.idle":"2023-01-07T21:10:01.063804Z","shell.execute_reply.started":"2023-01-07T21:10:01.053790Z","shell.execute_reply":"2023-01-07T21:10:01.062587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/train.csv\")\ntest_df = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:10:09.019167Z","iopub.execute_input":"2023-01-07T21:10:09.019555Z","iopub.status.idle":"2023-01-07T21:10:17.107178Z","shell.execute_reply.started":"2023-01-07T21:10:09.019524Z","shell.execute_reply":"2023-01-07T21:10:17.106034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Size of the train_df :\",train_df.shape[0])\nprint(\"Size of the test_df: \",test_df.shape[0])","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:10:35.643047Z","iopub.execute_input":"2023-01-07T21:10:35.643476Z","iopub.status.idle":"2023-01-07T21:10:35.649960Z","shell.execute_reply.started":"2023-01-07T21:10:35.643440Z","shell.execute_reply":"2023-01-07T21:10:35.648741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## check null values\ntrain_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:10:42.478245Z","iopub.execute_input":"2023-01-07T21:10:42.479297Z","iopub.status.idle":"2023-01-07T21:10:42.573288Z","shell.execute_reply.started":"2023-01-07T21:10:42.479260Z","shell.execute_reply":"2023-01-07T21:10:42.571809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Total columns are \",train_df.shape[1])\nnum_cols = train_df.select_dtypes([\"int\",\"float\"])\nprint(\"Number of numerical columns are : \",num_cols.shape[1])\ncat_cols = train_df.select_dtypes([\"object\"])\nprint(\"Number of categorical columns are : \",cat_cols.shape[1])","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:10:49.608223Z","iopub.execute_input":"2023-01-07T21:10:49.608634Z","iopub.status.idle":"2023-01-07T21:10:49.712033Z","shell.execute_reply.started":"2023-01-07T21:10:49.608597Z","shell.execute_reply":"2023-01-07T21:10:49.710760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n\ntarget = train_df.target\nsns.countplot(x=target.value_counts())\nplt.show() ## data seems balanced","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:10:56.134147Z","iopub.execute_input":"2023-01-07T21:10:56.134518Z","iopub.status.idle":"2023-01-07T21:10:56.290454Z","shell.execute_reply.started":"2023-01-07T21:10:56.134488Z","shell.execute_reply":"2023-01-07T21:10:56.289029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection  import train_test_split\nfrom sklearn.linear_model import LogisticRegression","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:11:04.520839Z","iopub.execute_input":"2023-01-07T21:11:04.521993Z","iopub.status.idle":"2023-01-07T21:11:04.526192Z","shell.execute_reply.started":"2023-01-07T21:11:04.521934Z","shell.execute_reply":"2023-01-07T21:11:04.525152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_x, cv_x, y_train, y_cv  = train_test_split(num_cols,train_df.target,stratify=train_df.target)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:11:17.829951Z","iopub.execute_input":"2023-01-07T21:11:17.830945Z","iopub.status.idle":"2023-01-07T21:11:18.499413Z","shell.execute_reply.started":"2023-01-07T21:11:17.830904Z","shell.execute_reply":"2023-01-07T21:11:18.498383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_x.drop(['target',\"id\"],axis=1,inplace=True)\n#train_x.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:11:24.724451Z","iopub.execute_input":"2023-01-07T21:11:24.724936Z","iopub.status.idle":"2023-01-07T21:11:24.817330Z","shell.execute_reply.started":"2023-01-07T21:11:24.724883Z","shell.execute_reply":"2023-01-07T21:11:24.815788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" cv_x.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:11:38.624921Z","iopub.execute_input":"2023-01-07T21:11:38.626090Z","iopub.status.idle":"2023-01-07T21:11:38.651490Z","shell.execute_reply.started":"2023-01-07T21:11:38.626034Z","shell.execute_reply":"2023-01-07T21:11:38.650356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cv_x.drop(['target',\"id\"],axis=1,inplace=True)\ncv_x.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:11:47.885299Z","iopub.execute_input":"2023-01-07T21:11:47.885884Z","iopub.status.idle":"2023-01-07T21:11:47.925428Z","shell.execute_reply.started":"2023-01-07T21:11:47.885834Z","shell.execute_reply":"2023-01-07T21:11:47.924126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score","metadata":{"execution":{"iopub.status.busy":"2023-01-07T20:16:34.424847Z","iopub.execute_input":"2023-01-07T20:16:34.425511Z","iopub.status.idle":"2023-01-07T20:16:34.431792Z","shell.execute_reply.started":"2023-01-07T20:16:34.425476Z","shell.execute_reply":"2023-01-07T20:16:34.430080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr = LogisticRegression(max_iter=500)\nlr.fit(train_x.values, y_train.values)\npred = lr.predict(train_x.values)\nprint(\"The train accuracy : \",accuracy_score(y_train.values,pred))\npred  = lr.predict(cv_x.values)\nprint(\"The cv accuracy : \",accuracy_score(y_cv.values, pred))","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:12:04.049158Z","iopub.execute_input":"2023-01-07T21:12:04.049543Z","iopub.status.idle":"2023-01-07T21:12:35.927915Z","shell.execute_reply.started":"2023-01-07T21:12:04.049511Z","shell.execute_reply":"2023-01-07T21:12:35.925939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## submission\ntest_x = test_df.select_dtypes([\"int\",\"float\"])\ntest_x.shape\ntest_id = test_x.id.values\ntest_x.drop(\"id\",axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:12:42.653164Z","iopub.execute_input":"2023-01-07T21:12:42.653556Z","iopub.status.idle":"2023-01-07T21:12:42.812254Z","shell.execute_reply.started":"2023-01-07T21:12:42.653524Z","shell.execute_reply":"2023-01-07T21:12:42.810787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = lr.predict(test_x.values)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:12:52.043642Z","iopub.execute_input":"2023-01-07T21:12:52.044067Z","iopub.status.idle":"2023-01-07T21:12:52.147886Z","shell.execute_reply.started":"2023-01-07T21:12:52.044029Z","shell.execute_reply":"2023-01-07T21:12:52.146367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/sample_submission.csv\")\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:13:02.888852Z","iopub.execute_input":"2023-01-07T21:13:02.889346Z","iopub.status.idle":"2023-01-07T21:13:03.285223Z","shell.execute_reply.started":"2023-01-07T21:13:02.889302Z","shell.execute_reply":"2023-01-07T21:13:03.284264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = pd.DataFrame({\n    \"id\" : test_id,\n    \"target\": pred\n})","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:13:24.163202Z","iopub.execute_input":"2023-01-07T21:13:24.164474Z","iopub.status.idle":"2023-01-07T21:13:24.171766Z","shell.execute_reply.started":"2023-01-07T21:13:24.164430Z","shell.execute_reply":"2023-01-07T21:13:24.170718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:13:36.961544Z","iopub.execute_input":"2023-01-07T21:13:36.962281Z","iopub.status.idle":"2023-01-07T21:13:36.971752Z","shell.execute_reply.started":"2023-01-07T21:13:36.962239Z","shell.execute_reply":"2023-01-07T21:13:36.970721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv(\"submission.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:13:40.642804Z","iopub.execute_input":"2023-01-07T21:13:40.643374Z","iopub.status.idle":"2023-01-07T21:13:41.397883Z","shell.execute_reply.started":"2023-01-07T21:13:40.643325Z","shell.execute_reply":"2023-01-07T21:13:41.396682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-07T21:13:49.410401Z","iopub.execute_input":"2023-01-07T21:13:49.411744Z","iopub.status.idle":"2023-01-07T21:13:49.423393Z","shell.execute_reply.started":"2023-01-07T21:13:49.411687Z","shell.execute_reply":"2023-01-07T21:13:49.422027Z"},"trusted":true},"execution_count":null,"outputs":[]}]}