{"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)\n\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-06T11:12:39.862696Z","iopub.execute_input":"2023-01-06T11:12:39.863242Z","iopub.status.idle":"2023-01-06T11:12:39.873819Z","shell.execute_reply.started":"2023-01-06T11:12:39.863194Z","shell.execute_reply":"2023-01-06T11:12:39.872647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Load Data ","metadata":{}},{"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')\nsubmission_df = pd.read_csv('/kaggle/input/emsi-5iir-ds/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:39.876482Z","iopub.execute_input":"2023-01-06T11:12:39.876987Z","iopub.status.idle":"2023-01-06T11:12:48.758765Z","shell.execute_reply.started":"2023-01-06T11:12:39.876943Z","shell.execute_reply":"2023-01-06T11:12:48.757544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Train Data Shape","metadata":{}},{"cell_type":"code","source":"print(\"shape of training data : \")\ntrain_df.shape\n","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:48.760244Z","iopub.execute_input":"2023-01-06T11:12:48.760668Z","iopub.status.idle":"2023-01-06T11:12:48.771530Z","shell.execute_reply.started":"2023-01-06T11:12:48.760623Z","shell.execute_reply":"2023-01-06T11:12:48.770327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Test Data Shape","metadata":{}},{"cell_type":"code","source":"print(\"shape of testing  data : \")\ntest_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:48.774450Z","iopub.execute_input":"2023-01-06T11:12:48.774843Z","iopub.status.idle":"2023-01-06T11:12:48.786507Z","shell.execute_reply.started":"2023-01-06T11:12:48.774809Z","shell.execute_reply":"2023-01-06T11:12:48.785348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Visualizing Data","metadata":{}},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:48.788248Z","iopub.execute_input":"2023-01-06T11:12:48.788642Z","iopub.status.idle":"2023-01-06T11:12:48.828602Z","shell.execute_reply.started":"2023-01-06T11:12:48.788611Z","shell.execute_reply":"2023-01-06T11:12:48.827724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:48.829822Z","iopub.execute_input":"2023-01-06T11:12:48.830588Z","iopub.status.idle":"2023-01-06T11:12:48.858639Z","shell.execute_reply.started":"2023-01-06T11:12:48.830551Z","shell.execute_reply":"2023-01-06T11:12:48.857364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"##### describe","metadata":{}},{"cell_type":"code","source":"train_df.describe()","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:48.860040Z","iopub.execute_input":"2023-01-06T11:12:48.861192Z","iopub.status.idle":"2023-01-06T11:12:50.083094Z","shell.execute_reply.started":"2023-01-06T11:12:48.861146Z","shell.execute_reply":"2023-01-06T11:12:50.081943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.describe()","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:50.084515Z","iopub.execute_input":"2023-01-06T11:12:50.085039Z","iopub.status.idle":"2023-01-06T11:12:51.010900Z","shell.execute_reply.started":"2023-01-06T11:12:50.085003Z","shell.execute_reply":"2023-01-06T11:12:51.009619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"##### info","metadata":{}},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:51.012216Z","iopub.execute_input":"2023-01-06T11:12:51.012653Z","iopub.status.idle":"2023-01-06T11:12:51.121514Z","shell.execute_reply.started":"2023-01-06T11:12:51.012624Z","shell.execute_reply":"2023-01-06T11:12:51.120253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:51.125186Z","iopub.execute_input":"2023-01-06T11:12:51.125606Z","iopub.status.idle":"2023-01-06T11:12:51.211573Z","shell.execute_reply.started":"2023-01-06T11:12:51.125567Z","shell.execute_reply":"2023-01-06T11:12:51.210206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### checking for missing values","metadata":{}},{"cell_type":"code","source":"train_df.isna().sum().any()\n","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:51.213067Z","iopub.execute_input":"2023-01-06T11:12:51.213397Z","iopub.status.idle":"2023-01-06T11:12:51.307434Z","shell.execute_reply.started":"2023-01-06T11:12:51.213369Z","shell.execute_reply":"2023-01-06T11:12:51.306558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.isna().sum().any()","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:51.309406Z","iopub.execute_input":"2023-01-06T11:12:51.309878Z","iopub.status.idle":"2023-01-06T11:12:51.384080Z","shell.execute_reply.started":"2023-01-06T11:12:51.309838Z","shell.execute_reply":"2023-01-06T11:12:51.382865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Split Data","metadata":{}},{"cell_type":"code","source":"y = train_df[\"target\"]\nX = train_df.drop(columns=[\"id\",\"f_27\", \"target\"])\n\ntest_df = test_df.drop(columns=[\"id\",\"f_27\"])\n\nX.shape, test_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:12:51.385790Z","iopub.execute_input":"2023-01-06T11:12:51.386254Z","iopub.status.idle":"2023-01-06T11:12:51.526975Z","shell.execute_reply.started":"2023-01-06T11:12:51.386211Z","shell.execute_reply":"2023-01-06T11:12:51.525938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## train and test split","metadata":{}},{"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, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:13:53.011912Z","iopub.execute_input":"2023-01-06T11:13:53.012363Z","iopub.status.idle":"2023-01-06T11:13:53.420358Z","shell.execute_reply.started":"2023-01-06T11:13:53.012327Z","shell.execute_reply":"2023-01-06T11:13:53.419191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Modeling","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nst_x= StandardScaler()\nx_train_df= st_x.fit_transform(x_train)\nx_test_df= st_x.transform(x_test)","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:13:55.882890Z","iopub.execute_input":"2023-01-06T11:13:55.883335Z","iopub.status.idle":"2023-01-06T11:13:56.377225Z","shell.execute_reply.started":"2023-01-06T11:13:55.883299Z","shell.execute_reply":"2023-01-06T11:13:56.376095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## LGBMClassifier","metadata":{}},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\nfrom lightgbm import LGBMClassifier\n\nmodel = LGBMClassifier()\nmodel.fit(x_train, y_train)\n\n# predict the results\ny_pred=model.predict(x_test)\n# view accuracy\naccuracy=accuracy_score(y_pred, y_test)\nprint('LightGBM Model accuracy score: {0:0.4f}'.format(accuracy_score(y_test, y_pred)))","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:13:58.988329Z","iopub.execute_input":"2023-01-06T11:13:58.988776Z","iopub.status.idle":"2023-01-06T11:14:12.075180Z","shell.execute_reply.started":"2023-01-06T11:13:58.988741Z","shell.execute_reply":"2023-01-06T11:14:12.074168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print the scores on training and test set\n\nprint('Training set score: {:.4f}'.format(model.score(x_train, y_train)))\n\nprint('Test set score: {:.4f}'.format(model.score(x_test, y_test)))","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:14:16.890833Z","iopub.execute_input":"2023-01-06T11:14:16.892174Z","iopub.status.idle":"2023-01-06T11:14:20.033292Z","shell.execute_reply.started":"2023-01-06T11:14:16.892134Z","shell.execute_reply":"2023-01-06T11:14:20.031904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Random Forest","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nclf = RandomForestClassifier() \n \n# Training the model on the training dataset\n# fit function is used to train the model using the training sets as parameters\nclf.fit(x_train, y_train)\n \n# performing predictions on the test dataset\ny_pred = clf.predict(x_test)\n \n\n# using metrics module for accuracy calculation\nprint(\"ACCURACY OF THE MODEL: \",accuracy_score(y_test, y_pred))","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:14:29.482820Z","iopub.execute_input":"2023-01-06T11:14:29.483221Z","iopub.status.idle":"2023-01-06T11:26:24.192818Z","shell.execute_reply.started":"2023-01-06T11:14:29.483189Z","shell.execute_reply":"2023-01-06T11:26:24.191532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print the scores on training and test set\n\nprint('Training set score: {:.4f}'.format(clf.score(x_train, y_train)))\n\nprint('Test set score: {:.4f}'.format(clf.score(x_test, y_test)))","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:26:35.283392Z","iopub.execute_input":"2023-01-06T11:26:35.283841Z","iopub.status.idle":"2023-01-06T11:27:26.423830Z","shell.execute_reply.started":"2023-01-06T11:26:35.283804Z","shell.execute_reply":"2023-01-06T11:27:26.422574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Submission","metadata":{}},{"cell_type":"code","source":"submission_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:27:30.629714Z","iopub.execute_input":"2023-01-06T11:27:30.630915Z","iopub.status.idle":"2023-01-06T11:27:30.637072Z","shell.execute_reply.started":"2023-01-06T11:27:30.630877Z","shell.execute_reply":"2023-01-06T11:27:30.636045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"modelRF = RandomForestClassifier()\n\nmodelRF.fit(X, y)\ny_predict = []\ny_predict.append(modelRF.predict_proba(test_df)[:,1])","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:28:33.795313Z","iopub.execute_input":"2023-01-06T11:28:33.795742Z","iopub.status.idle":"2023-01-06T11:43:57.357660Z","shell.execute_reply.started":"2023-01-06T11:28:33.795707Z","shell.execute_reply":"2023-01-06T11:43:57.356425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.array(y_predict).mean(axis=0)","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:44:02.125286Z","iopub.execute_input":"2023-01-06T11:44:02.125728Z","iopub.status.idle":"2023-01-06T11:44:02.136672Z","shell.execute_reply.started":"2023-01-06T11:44:02.125692Z","shell.execute_reply":"2023-01-06T11:44:02.135469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df['target'] = np.array(y_predict).mean(axis=0)\nsubmission_df.to_csv('submission.csv', index=False)\nsubmission_df","metadata":{"execution":{"iopub.status.busy":"2023-01-06T11:44:15.644259Z","iopub.execute_input":"2023-01-06T11:44:15.644708Z","iopub.status.idle":"2023-01-06T11:44:16.696859Z","shell.execute_reply.started":"2023-01-06T11:44:15.644675Z","shell.execute_reply":"2023-01-06T11:44:16.695718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}