{"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-08T14:57:50.664369Z","iopub.execute_input":"2023-01-08T14:57:50.665006Z","iopub.status.idle":"2023-01-08T14:57:50.677295Z","shell.execute_reply.started":"2023-01-08T14:57:50.664929Z","shell.execute_reply":"2023-01-08T14:57:50.675727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-01-08T13:46:17.007856Z","iopub.execute_input":"2023-01-08T13:46:17.008328Z","iopub.status.idle":"2023-01-08T13:46:26.491068Z","shell.execute_reply.started":"2023-01-08T13:46:17.008296Z","shell.execute_reply":"2023-01-08T13:46:26.489622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"this code load data in format csv and convert it to dataframe","metadata":{}},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T13:47:10.508931Z","iopub.execute_input":"2023-01-08T13:47:10.509562Z","iopub.status.idle":"2023-01-08T13:47:10.562116Z","shell.execute_reply.started":"2023-01-08T13:47:10.509512Z","shell.execute_reply":"2023-01-08T13:47:10.560864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['f_27'] = pd.Categorical(df['f_27'])\ndf['f_27'] = df['f_27'].cat.codes\ndf.head()\n","metadata":{"execution":{"iopub.status.busy":"2023-01-08T13:47:51.635172Z","iopub.execute_input":"2023-01-08T13:47:51.635604Z","iopub.status.idle":"2023-01-08T13:47:54.057444Z","shell.execute_reply.started":"2023-01-08T13:47:51.635571Z","shell.execute_reply":"2023-01-08T13:47:54.056047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Change the format of column 27 from string to correspending number","metadata":{}},{"cell_type":"code","source":"from fastai.tabular.all import *","metadata":{"execution":{"iopub.status.busy":"2023-01-08T14:57:38.583613Z","iopub.execute_input":"2023-01-08T14:57:38.584119Z","iopub.status.idle":"2023-01-08T14:57:38.590787Z","shell.execute_reply.started":"2023-01-08T14:57:38.584079Z","shell.execute_reply":"2023-01-08T14:57:38.589272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"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']\ncont_names = ['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_27']\nprocs = [Categorify, FillMissing, Normalize]","metadata":{"execution":{"iopub.status.busy":"2023-01-08T13:49:08.913041Z","iopub.execute_input":"2023-01-08T13:49:08.913438Z","iopub.status.idle":"2023-01-08T13:49:08.924207Z","shell.execute_reply.started":"2023-01-08T13:49:08.913407Z","shell.execute_reply":"2023-01-08T13:49:08.923008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls = TabularDataLoaders.from_df(df,y_block=CategoryBlock, procs=procs, cat_names=cat_names, cont_names=cont_names, \n                                 y_names=\"target\")\nlearn = tabular_learner(dls)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T13:49:34.614357Z","iopub.execute_input":"2023-01-08T13:49:34.614836Z","iopub.status.idle":"2023-01-08T13:49:37.02674Z","shell.execute_reply.started":"2023-01-08T13:49:34.614801Z","shell.execute_reply":"2023-01-08T13:49:37.025511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls.show_batch()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T13:49:49.909102Z","iopub.execute_input":"2023-01-08T13:49:49.909635Z","iopub.status.idle":"2023-01-08T13:49:50.895509Z","shell.execute_reply.started":"2023-01-08T13:49:49.90959Z","shell.execute_reply":"2023-01-08T13:49:50.894289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = tabular_learner(dls,metrics=accuracy)\nlearn.fit_one_cycle(10)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T14:32:28.785533Z","iopub.execute_input":"2023-01-08T14:32:28.785938Z","iopub.status.idle":"2023-01-08T14:56:27.333872Z","shell.execute_reply.started":"2023-01-08T14:32:28.785907Z","shell.execute_reply":"2023-01-08T14:56:27.3328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_sample = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-01-08T14:56:37.000027Z","iopub.execute_input":"2023-01-08T14:56:37.000452Z","iopub.status.idle":"2023-01-08T14:56:41.375381Z","shell.execute_reply.started":"2023-01-08T14:56:37.00042Z","shell.execute_reply":"2023-01-08T14:56:41.374124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_sample['f_27'] = pd.Categorical(test_sample['f_27'])\ntest_sample['f_27'] = test_sample['f_27'].cat.codes\ntest_sample.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-08T14:56:45.210333Z","iopub.execute_input":"2023-01-08T14:56:45.210755Z","iopub.status.idle":"2023-01-08T14:56:46.996057Z","shell.execute_reply.started":"2023-01-08T14:56:45.210719Z","shell.execute_reply":"2023-01-08T14:56:46.994709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dl = learn.dls.test_dl(test_sample)\npreds, test_labels = learn.get_preds(dl=test_dl)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T14:57:59.89432Z","iopub.execute_input":"2023-01-08T14:57:59.89489Z","iopub.status.idle":"2023-01-08T14:58:58.596786Z","shell.execute_reply.started":"2023-01-08T14:57:59.894843Z","shell.execute_reply":"2023-01-08T14:58:58.595484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\npredection = preds.numpy()\npredection = np.argmax(predection, axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T14:59:11.275573Z","iopub.execute_input":"2023-01-08T14:59:11.276312Z","iopub.status.idle":"2023-01-08T14:59:11.293689Z","shell.execute_reply.started":"2023-01-08T14:59:11.276254Z","shell.execute_reply":"2023-01-08T14:59:11.291268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = pd.read_csv(os.path.join(\"/kaggle/input/emsi-5iir-ds/\", \"sample_submission.csv\"))\nsubmission_df['target'] = predection\nsubmission_df.to_csv('sub_v02.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-01-08T14:59:24.975074Z","iopub.execute_input":"2023-01-08T14:59:24.975736Z","iopub.status.idle":"2023-01-08T14:59:25.820481Z","shell.execute_reply.started":"2023-01-08T14:59:24.975696Z","shell.execute_reply":"2023-01-08T14:59:25.819267Z"},"trusted":true},"execution_count":null,"outputs":[]}]}