{"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":"markdown","source":"# 1.  Loading the Requiered Libraries","metadata":{}},{"cell_type":"code","source":"%%time\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nfrom sklearn import model_selection\n\nfrom sklearn.linear_model import LogisticRegression\n\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-08T17:52:29.555307Z","iopub.execute_input":"2023-01-08T17:52:29.555697Z","iopub.status.idle":"2023-01-08T17:52:29.563970Z","shell.execute_reply.started":"2023-01-08T17:52:29.555666Z","shell.execute_reply":"2023-01-08T17:52:29.562789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2. Setup the Notebook","metadata":{}},{"cell_type":"code","source":"%%time\n# Notebook Configuration\n\n# Amount of data we want to load into the Model\nDATA_ROWS = None\n\n# Dataframe, the amount of rows and cols to visualize\nNROWS = 50\nNCOLS = 15\n\n# Configure notebook display settings to only use 2 decimal places, tables look nicer.\npd.options.display.float_format = '{:,.5f}'.format\npd.set_option('display.max_columns', NCOLS) \npd.set_option('display.max_rows', NROWS)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:29.592393Z","iopub.execute_input":"2023-01-08T17:52:29.593413Z","iopub.status.idle":"2023-01-08T17:52:29.599449Z","shell.execute_reply.started":"2023-01-08T17:52:29.593377Z","shell.execute_reply":"2023-01-08T17:52:29.598340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3. Loading the (CSV) Into A Dataframe","metadata":{}},{"cell_type":"code","source":"path=Path('/kaggle/input/emsi-5iir-ds')\npath.ls()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:29.621097Z","iopub.execute_input":"2023-01-08T17:52:29.621348Z","iopub.status.idle":"2023-01-08T17:52:29.628693Z","shell.execute_reply.started":"2023-01-08T17:52:29.621325Z","shell.execute_reply":"2023-01-08T17:52:29.627561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n\ndf_train = pd.read_csv(path/'train.csv')\ndf_test = pd.read_csv(path/'test.csv')\nss=pd.read_csv(path/'sample_submission.csv')\n\nprint(df_train.shape, df_test.shape)\nss.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:29.653807Z","iopub.execute_input":"2023-01-08T17:52:29.654072Z","iopub.status.idle":"2023-01-08T17:52:35.692620Z","shell.execute_reply.started":"2023-01-08T17:52:29.654047Z","shell.execute_reply":"2023-01-08T17:52:35.691589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4. Exploring the Dataframes infos","metadata":{}},{"cell_type":"code","source":"%%time\n# Display simple information of the variables in the dataset\ndf_train.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:35.694619Z","iopub.execute_input":"2023-01-08T17:52:35.695421Z","iopub.status.idle":"2023-01-08T17:52:35.785059Z","shell.execute_reply.started":"2023-01-08T17:52:35.695382Z","shell.execute_reply":"2023-01-08T17:52:35.783922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Display the first few rows of the DataFrame\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:35.786742Z","iopub.execute_input":"2023-01-08T17:52:35.787106Z","iopub.status.idle":"2023-01-08T17:52:35.807026Z","shell.execute_reply.started":"2023-01-08T17:52:35.787070Z","shell.execute_reply":"2023-01-08T17:52:35.805886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Generate a simple statistical summary of the DataFrame\ndf_train.describe(include='all')","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:35.810674Z","iopub.execute_input":"2023-01-08T17:52:35.811629Z","iopub.status.idle":"2023-01-08T17:52:37.617884Z","shell.execute_reply.started":"2023-01-08T17:52:35.811588Z","shell.execute_reply":"2023-01-08T17:52:37.616965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Display simple information of the variables in the dataset\ndf_test.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:37.620997Z","iopub.execute_input":"2023-01-08T17:52:37.624615Z","iopub.status.idle":"2023-01-08T17:52:37.729692Z","shell.execute_reply.started":"2023-01-08T17:52:37.624577Z","shell.execute_reply":"2023-01-08T17:52:37.728766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Generate a simple statistical summary of the DataFrame\ndf_test.describe(include='all')","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:37.733893Z","iopub.execute_input":"2023-01-08T17:52:37.734909Z","iopub.status.idle":"2023-01-08T17:52:38.907387Z","shell.execute_reply.started":"2023-01-08T17:52:37.734869Z","shell.execute_reply":"2023-01-08T17:52:38.906473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Drop the unnessary cols from DataFrame\ntarget = df_train['target']\nunnecessary_cols=['id','f_27']\n\ncombi = df_train.drop(['target'], axis=1).append(df_test)\ncombi = combi.drop(unnecessary_cols, axis=1)\ncombi","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:38.909603Z","iopub.execute_input":"2023-01-08T17:52:38.910389Z","iopub.status.idle":"2023-01-08T17:52:39.865978Z","shell.execute_reply.started":"2023-01-08T17:52:38.910342Z","shell.execute_reply":"2023-01-08T17:52:39.864887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Generate a quick correlation matrix to understand the dataset better\ncomb_corr = combi.corr()\ncomb_corr","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:39.867438Z","iopub.execute_input":"2023-01-08T17:52:39.868319Z","iopub.status.idle":"2023-01-08T17:52:43.665154Z","shell.execute_reply.started":"2023-01-08T17:52:39.868278Z","shell.execute_reply":"2023-01-08T17:52:43.663957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 5. Feature Engineering","metadata":{}},{"cell_type":"code","source":"%%time\ny = target\nX = combi[: len(df_train)]\nX_test = combi[len(df_train) :]","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:43.667024Z","iopub.execute_input":"2023-01-08T17:52:43.667450Z","iopub.status.idle":"2023-01-08T17:52:43.674908Z","shell.execute_reply.started":"2023-01-08T17:52:43.667407Z","shell.execute_reply":"2023-01-08T17:52:43.673834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n#Split dataset for training and validation\nX_train, X_val, y_train, y_val = model_selection.train_test_split(X, y, test_size=0.1, random_state=42)\nX_train.shape, X_val.shape, y_train.shape,y_val.shape, X_test.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:43.678722Z","iopub.execute_input":"2023-01-08T17:52:43.679869Z","iopub.status.idle":"2023-01-08T17:52:43.935359Z","shell.execute_reply.started":"2023-01-08T17:52:43.679829Z","shell.execute_reply":"2023-01-08T17:52:43.934241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 5.1 Logistic Regression","metadata":{}},{"cell_type":"code","source":"%%time\n#Select model - Logistic Regression\nmodel = LogisticRegression(max_iter=500,random_state=42).fit(X_train, y_train)\nprint(model.score(X_train, y_train))","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:52:43.936768Z","iopub.execute_input":"2023-01-08T17:52:43.937425Z","iopub.status.idle":"2023-01-08T17:53:17.458198Z","shell.execute_reply.started":"2023-01-08T17:52:43.937384Z","shell.execute_reply":"2023-01-08T17:53:17.457230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n#Predict on validation set\ny_pred = model.predict(X_val)\nprint(model.score(X_val, y_val))","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:53:17.459486Z","iopub.execute_input":"2023-01-08T17:53:17.460429Z","iopub.status.idle":"2023-01-08T17:53:17.502735Z","shell.execute_reply.started":"2023-01-08T17:53:17.460392Z","shell.execute_reply":"2023-01-08T17:53:17.501781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n#Predict on test set\npreds = model.predict(X_test)\npreds = preds.astype(int)\npreds[preds < 0] = 0\npreds","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:53:17.504007Z","iopub.execute_input":"2023-01-08T17:53:17.504940Z","iopub.status.idle":"2023-01-08T17:53:17.652829Z","shell.execute_reply.started":"2023-01-08T17:53:17.504903Z","shell.execute_reply":"2023-01-08T17:53:17.651551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submission","metadata":{}},{"cell_type":"code","source":"%%time\n\nss.target = preds\nss.to_csv('submission.csv', index=False)\nss.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T17:53:17.658756Z","iopub.execute_input":"2023-01-08T17:53:17.661963Z","iopub.status.idle":"2023-01-08T17:53:18.315567Z","shell.execute_reply.started":"2023-01-08T17:53:17.661910Z","shell.execute_reply":"2023-01-08T17:53:18.314580Z"},"trusted":true},"execution_count":null,"outputs":[]}]}