{"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-05T14:05:28.574700Z","iopub.execute_input":"2023-01-05T14:05:28.575753Z","iopub.status.idle":"2023-01-05T14:05:28.608981Z","shell.execute_reply.started":"2023-01-05T14:05:28.575647Z","shell.execute_reply":"2023-01-05T14:05:28.607576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import fastai\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport os\nimport pandas as pd\nimport seaborn as sns\n\nfrom fastai.tabular.all import *","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:15:00.600563Z","iopub.execute_input":"2023-01-05T14:15:00.601103Z","iopub.status.idle":"2023-01-05T14:15:03.509504Z","shell.execute_reply.started":"2023-01-05T14:15:00.601056Z","shell.execute_reply":"2023-01-05T14:15:03.508145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_dir=\"/kaggle/input/emsi-5iir-ds/\"","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:17:13.256093Z","iopub.execute_input":"2023-01-05T14:17:13.256760Z","iopub.status.idle":"2023-01-05T14:17:13.262146Z","shell.execute_reply.started":"2023-01-05T14:17:13.256717Z","shell.execute_reply":"2023-01-05T14:17:13.261032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ted_train = pd.read_csv('/kaggle/input/emsi-5iir-ds/train.csv')\nted_test = pd.read_csv('/kaggle/input/emsi-5iir-ds/test.csv')\n\n","metadata":{"execution":{"iopub.status.busy":"2023-01-05T15:09:22.554411Z","iopub.execute_input":"2023-01-05T15:09:22.554802Z","iopub.status.idle":"2023-01-05T15:09:30.976951Z","shell.execute_reply.started":"2023-01-05T15:09:22.554771Z","shell.execute_reply":"2023-01-05T15:09:30.976017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp2=ted_train.copy()","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:53:14.471805Z","iopub.execute_input":"2023-01-05T14:53:14.472207Z","iopub.status.idle":"2023-01-05T14:53:14.994274Z","shell.execute_reply.started":"2023-01-05T14:53:14.472175Z","shell.execute_reply":"2023-01-05T14:53:14.992988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp2['f_27']=pd.Categorical(temp2['f_27'])\ntemp2['f_27']=temp2['f_27'].cat.codes\ntemp2.drop(columns=[ \"id\",\"test\"])\n","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:59:43.990592Z","iopub.execute_input":"2023-01-05T14:59:43.991023Z","iopub.status.idle":"2023-01-05T14:59:44.720234Z","shell.execute_reply.started":"2023-01-05T14:59:43.990988Z","shell.execute_reply":"2023-01-05T14:59:44.719410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp2.head(10)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:57:23.394636Z","iopub.execute_input":"2023-01-05T14:57:23.395292Z","iopub.status.idle":"2023-01-05T14:57:23.427000Z","shell.execute_reply.started":"2023-01-05T14:57:23.395241Z","shell.execute_reply":"2023-01-05T14:57:23.425768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp.drop(columns=[ \"id\",\"f_27\"])","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:18:43.298550Z","iopub.execute_input":"2023-01-05T14:18:43.298931Z","iopub.status.idle":"2023-01-05T14:18:43.702851Z","shell.execute_reply.started":"2023-01-05T14:18:43.298901Z","shell.execute_reply":"2023-01-05T14:18:43.701684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls = TabularDataLoaders.from_df(temp2, y_names=\"target\",\n    y_block = CategoryBlock,\n    cont_names = ['f_00','f_01','f_02', 'f_03', 'f_04', 'f_05', 'f_06', 'f_19', 'f_20', 'f_21', 'f_22', 'f_23', 'f_24', 'f_25', 'f_26', 'f_28','f_27'],\n    cat_names=['f_07','f_08','f_09','f_10','f_11','f_12','f_13','f_14','f_15','f_16','f_17','f_18','f_29','f_30'],                              \n    procs = [Categorify, FillMissing, Normalize],\n    )","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:09:50.070090Z","iopub.execute_input":"2023-01-05T16:09:50.070494Z","iopub.status.idle":"2023-01-05T16:09:53.324525Z","shell.execute_reply.started":"2023-01-05T16:09:50.070461Z","shell.execute_reply":"2023-01-05T16:09:53.323333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls.show_batch()","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:09:25.862500Z","iopub.execute_input":"2023-01-05T16:09:25.862941Z","iopub.status.idle":"2023-01-05T16:09:27.444906Z","shell.execute_reply.started":"2023-01-05T16:09:25.862906Z","shell.execute_reply":"2023-01-05T16:09:27.444077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = tabular_learner(dls,metrics=accuracy)\nlearn.fit_one_cycle(15)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:09:55.919314Z","iopub.execute_input":"2023-01-05T16:09:55.919761Z","iopub.status.idle":"2023-01-05T16:12:39.113110Z","shell.execute_reply.started":"2023-01-05T16:09:55.919724Z","shell.execute_reply":"2023-01-05T16:12:39.111871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ted_test['f_27']=pd.Categorical(ted_test['f_27'])\nted_test['f_27']=ted_test['f_27'].cat.codes\n\ntest_dl = learn.dls.test_dl(ted_test)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:42.503449Z","iopub.execute_input":"2023-01-05T16:03:42.504809Z","iopub.status.idle":"2023-01-05T16:03:43.368952Z","shell.execute_reply.started":"2023-01-05T16:03:42.504696Z","shell.execute_reply":"2023-01-05T16:03:43.368048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds, test_labels = learn.get_preds(dl=test_dl)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:47.449469Z","iopub.execute_input":"2023-01-05T16:03:47.450586Z","iopub.status.idle":"2023-01-05T16:04:45.326314Z","shell.execute_reply.started":"2023-01-05T16:03:47.450530Z","shell.execute_reply":"2023-01-05T16:04:45.325392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_preds = preds.numpy()\nfinal_preds = np.argmax(final_preds, axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:04:46.750708Z","iopub.execute_input":"2023-01-05T16:04:46.753412Z","iopub.status.idle":"2023-01-05T16:04:46.765481Z","shell.execute_reply.started":"2023-01-05T16:04:46.753361Z","shell.execute_reply":"2023-01-05T16:04:46.763811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = pd.read_csv(os.path.join(data_dir, \"sample_submission.csv\"))\nsubmission_df['target'] = final_preds\nsubmission_df.to_csv('submission3.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:04:55.831102Z","iopub.execute_input":"2023-01-05T16:04:55.831523Z","iopub.status.idle":"2023-01-05T16:04:56.686202Z","shell.execute_reply.started":"2023-01-05T16:04:55.831487Z","shell.execute_reply":"2023-01-05T16:04:56.685256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:05:51.947200Z","iopub.execute_input":"2023-01-05T16:05:51.947625Z","iopub.status.idle":"2023-01-05T16:05:51.958367Z","shell.execute_reply.started":"2023-01-05T16:05:51.947587Z","shell.execute_reply":"2023-01-05T16:05:51.957530Z"},"trusted":true},"execution_count":null,"outputs":[]}]}