{"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)\nimport os\nfrom fastai.tabular.all import *\n\n\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\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n\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-09T08:38:56.582437Z","iopub.execute_input":"2023-01-09T08:38:56.582922Z","iopub.status.idle":"2023-01-09T08:38:59.747974Z","shell.execute_reply.started":"2023-01-09T08:38:56.582833Z","shell.execute_reply":"2023-01-09T08:38:59.746798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/train.csv\")\nprint(df)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T08:38:59.750017Z","iopub.execute_input":"2023-01-09T08:38:59.751393Z","iopub.status.idle":"2023-01-09T08:39:08.544858Z","shell.execute_reply.started":"2023-01-09T08:38:59.751339Z","shell.execute_reply":"2023-01-09T08:39:08.543584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-09T08:39:08.546181Z","iopub.execute_input":"2023-01-09T08:39:08.546479Z","iopub.status.idle":"2023-01-09T08:39:08.575881Z","shell.execute_reply.started":"2023-01-09T08:39:08.546454Z","shell.execute_reply":"2023-01-09T08:39:08.574765Z"},"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']\nprocs = [Categorify, FillMissing, Normalize]","metadata":{"execution":{"iopub.status.busy":"2023-01-09T08:39:08.578612Z","iopub.execute_input":"2023-01-09T08:39:08.578957Z","iopub.status.idle":"2023-01-09T08:39:08.585423Z","shell.execute_reply.started":"2023-01-09T08:39:08.578928Z","shell.execute_reply":"2023-01-09T08:39:08.584217Z"},"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-09T08:39:08.586623Z","iopub.execute_input":"2023-01-09T08:39:08.587049Z","iopub.status.idle":"2023-01-09T08:39:12.617988Z","shell.execute_reply.started":"2023-01-09T08:39:08.587019Z","shell.execute_reply":"2023-01-09T08:39:12.617076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls.show_batch()","metadata":{"execution":{"iopub.status.busy":"2023-01-09T08:39:12.619771Z","iopub.execute_input":"2023-01-09T08:39:12.620180Z","iopub.status.idle":"2023-01-09T08:39:13.553071Z","shell.execute_reply.started":"2023-01-09T08:39:12.620138Z","shell.execute_reply":"2023-01-09T08:39:13.552311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = tabular_learner(dls,metrics=accuracy)\nlearn.fit_one_cycle(1)","metadata":{"execution":{"iopub.status.busy":"2023-01-09T08:39:13.554082Z","iopub.execute_input":"2023-01-09T08:39:13.554702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now lets add the column f_27 to our dataframe but with a small adjustment","metadata":{}},{"cell_type":"code","source":"df2 = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/train.csv\")\ndf2.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2['f_27'] = pd.Categorical(df2['f_27'])\ndf2['f_27'] = df2['f_27'].cat.codes\ndf2.head()\n","metadata":{"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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls = TabularDataLoaders.from_df(df2,y_block=CategoryBlock, procs=procs, cat_names=cat_names, cont_names=cont_names, \n                                 y_names=\"target\")\nlearn = tabular_learner(dls)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = tabular_learner(dls,metrics=accuracy)\nlearn.fit_one_cycle(4)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_sample = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/test.csv\")","metadata":{"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":{"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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\npredection = preds.numpy()\npredection = np.argmax(predection, axis=1)","metadata":{"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('submission_v2.csv', index=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}