{"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":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input/emsi-5iir-ds'):\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-02T21:50:20.163138Z","iopub.execute_input":"2023-01-02T21:50:20.163680Z","iopub.status.idle":"2023-01-02T21:50:20.197706Z","shell.execute_reply.started":"2023-01-02T21:50:20.163578Z","shell.execute_reply":"2023-01-02T21:50:20.196758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" #  **LOAD DATA**","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/train.csv\")\ntest_tf = pd.read_csv(\"/kaggle/input/emsi-5iir-ds/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:20.200582Z","iopub.execute_input":"2023-01-02T21:50:20.200943Z","iopub.status.idle":"2023-01-02T21:50:34.796195Z","shell.execute_reply.started":"2023-01-02T21:50:20.200908Z","shell.execute_reply":"2023-01-02T21:50:34.795505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*  **Data Shape**","metadata":{}},{"cell_type":"code","source":"train.shape, test_tf.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:34.799084Z","iopub.execute_input":"2023-01-02T21:50:34.799374Z","iopub.status.idle":"2023-01-02T21:50:34.807611Z","shell.execute_reply.started":"2023-01-02T21:50:34.799331Z","shell.execute_reply":"2023-01-02T21:50:34.806696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Data VISUALISATION**","metadata":{}},{"cell_type":"markdown","source":"**Describe**","metadata":{}},{"cell_type":"code","source":"train.describe().T","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:34.810135Z","iopub.execute_input":"2023-01-02T21:50:34.811062Z","iopub.status.idle":"2023-01-02T21:50:35.605318Z","shell.execute_reply.started":"2023-01-02T21:50:34.811029Z","shell.execute_reply":"2023-01-02T21:50:35.604421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_tf.describe()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:35.606617Z","iopub.execute_input":"2023-01-02T21:50:35.607803Z","iopub.status.idle":"2023-01-02T21:50:36.201727Z","shell.execute_reply.started":"2023-01-02T21:50:35.607768Z","shell.execute_reply":"2023-01-02T21:50:36.200433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Info**","metadata":{}},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:36.203603Z","iopub.execute_input":"2023-01-02T21:50:36.204039Z","iopub.status.idle":"2023-01-02T21:50:36.283640Z","shell.execute_reply.started":"2023-01-02T21:50:36.203997Z","shell.execute_reply":"2023-01-02T21:50:36.282144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_tf.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:36.285055Z","iopub.execute_input":"2023-01-02T21:50:36.285410Z","iopub.status.idle":"2023-01-02T21:50:36.347473Z","shell.execute_reply.started":"2023-01-02T21:50:36.285376Z","shell.execute_reply":"2023-01-02T21:50:36.346548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Checking for null values**","metadata":{}},{"cell_type":"code","source":"train.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:36.348613Z","iopub.execute_input":"2023-01-02T21:50:36.349999Z","iopub.status.idle":"2023-01-02T21:50:36.413504Z","shell.execute_reply.started":"2023-01-02T21:50:36.349929Z","shell.execute_reply":"2023-01-02T21:50:36.412567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Understanding the relation between the data**","metadata":{}},{"cell_type":"code","source":"und = train.corr()\nund.style.background_gradient(cmap='coolwarm')","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:36.416098Z","iopub.execute_input":"2023-01-02T21:50:36.417207Z","iopub.status.idle":"2023-01-02T21:50:38.307951Z","shell.execute_reply.started":"2023-01-02T21:50:36.417150Z","shell.execute_reply":"2023-01-02T21:50:38.307180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Feature Engineering && Data preprocessing**","metadata":{}},{"cell_type":"markdown","source":"* **After getting infos from our train.csv and understanding the relation f-27 is the only column non numeric**","metadata":{}},{"cell_type":"code","source":"string_f = 'f_27'","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:38.311708Z","iopub.execute_input":"2023-01-02T21:50:38.312059Z","iopub.status.idle":"2023-01-02T21:50:38.316305Z","shell.execute_reply.started":"2023-01-02T21:50:38.312032Z","shell.execute_reply":"2023-01-02T21:50:38.315525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Converting the column into 10 seperate coloumn to understand the relationship**","metadata":{}},{"cell_type":"code","source":"def under_27(data, do_convert = True):\n    if do_convert:\n        for i in range(10):\n            data[f'f_27_{i}'] = data[string_f].str.get(i)\n    data.drop([string_f], axis=1, inplace=True)\n    return data","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:38.317200Z","iopub.execute_input":"2023-01-02T21:50:38.317519Z","iopub.status.idle":"2023-01-02T21:50:38.329000Z","shell.execute_reply.started":"2023-01-02T21:50:38.317486Z","shell.execute_reply":"2023-01-02T21:50:38.327826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Applying the function into train and test data**","metadata":{}},{"cell_type":"code","source":"train = under_27(train, do_convert=True)\ntest_tf = under_27(test_tf, do_convert=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:38.330082Z","iopub.execute_input":"2023-01-02T21:50:38.331501Z","iopub.status.idle":"2023-01-02T21:50:46.115916Z","shell.execute_reply.started":"2023-01-02T21:50:38.331446Z","shell.execute_reply":"2023-01-02T21:50:46.114838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:46.117386Z","iopub.execute_input":"2023-01-02T21:50:46.117899Z","iopub.status.idle":"2023-01-02T21:50:46.567126Z","shell.execute_reply.started":"2023-01-02T21:50:46.117866Z","shell.execute_reply":"2023-01-02T21:50:46.565776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Check the data shape**","metadata":{}},{"cell_type":"code","source":"train.shape , test_tf.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:46.568321Z","iopub.execute_input":"2023-01-02T21:50:46.568654Z","iopub.status.idle":"2023-01-02T21:50:46.576129Z","shell.execute_reply.started":"2023-01-02T21:50:46.568625Z","shell.execute_reply":"2023-01-02T21:50:46.575002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Describe the featured engineered data**","metadata":{}},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:46.577055Z","iopub.execute_input":"2023-01-02T21:50:46.577399Z","iopub.status.idle":"2023-01-02T21:50:46.606854Z","shell.execute_reply.started":"2023-01-02T21:50:46.577348Z","shell.execute_reply":"2023-01-02T21:50:46.605298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Now we split the data into categorical and continous data( cont / cat )**","metadata":{}},{"cell_type":"code","source":"cont_names = [col for col in train if train[col].dtype ==\"float64\"]\ncat_names = [col for col in train if train[col].dtype !=\"float64\"]","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:46.609298Z","iopub.execute_input":"2023-01-02T21:50:46.609751Z","iopub.status.idle":"2023-01-02T21:50:46.620163Z","shell.execute_reply.started":"2023-01-02T21:50:46.609712Z","shell.execute_reply":"2023-01-02T21:50:46.619003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **lets see the splitted data**","metadata":{}},{"cell_type":"code","source":"cont_names","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:46.622141Z","iopub.execute_input":"2023-01-02T21:50:46.622422Z","iopub.status.idle":"2023-01-02T21:50:46.635421Z","shell.execute_reply.started":"2023-01-02T21:50:46.622398Z","shell.execute_reply":"2023-01-02T21:50:46.633973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_names","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:46.637322Z","iopub.execute_input":"2023-01-02T21:50:46.637767Z","iopub.status.idle":"2023-01-02T21:50:46.649995Z","shell.execute_reply.started":"2023-01-02T21:50:46.637730Z","shell.execute_reply":"2023-01-02T21:50:46.648825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Time to clean our data i will remove 'ID' it will not help the model and the 'target' for the prediction**","metadata":{}},{"cell_type":"code","source":"cat_names.remove(\"target\")\ncat_names.remove(\"id\")","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:46.651308Z","iopub.execute_input":"2023-01-02T21:50:46.651710Z","iopub.status.idle":"2023-01-02T21:50:46.657311Z","shell.execute_reply.started":"2023-01-02T21:50:46.651678Z","shell.execute_reply":"2023-01-02T21:50:46.656023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_names","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:46.658533Z","iopub.execute_input":"2023-01-02T21:50:46.658839Z","iopub.status.idle":"2023-01-02T21:50:46.670252Z","shell.execute_reply.started":"2023-01-02T21:50:46.658812Z","shell.execute_reply":"2023-01-02T21:50:46.669287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Splitting the data using RandomSplitter for training and testing or validation**","metadata":{}},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai.basics import *","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:46.671498Z","iopub.execute_input":"2023-01-02T21:50:46.671836Z","iopub.status.idle":"2023-01-02T21:50:48.949229Z","shell.execute_reply.started":"2023-01-02T21:50:46.671802Z","shell.execute_reply":"2023-01-02T21:50:48.948119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"splits = RandomSplitter(valid_pct=0.2)(range_of(train))","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:48.950659Z","iopub.execute_input":"2023-01-02T21:50:48.951330Z","iopub.status.idle":"2023-01-02T21:50:49.051476Z","shell.execute_reply.started":"2023-01-02T21:50:48.951295Z","shell.execute_reply":"2023-01-02T21:50:49.050272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Describe splits**","metadata":{}},{"cell_type":"code","source":"splits","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:49.052784Z","iopub.execute_input":"2023-01-02T21:50:49.053154Z","iopub.status.idle":"2023-01-02T21:50:49.061066Z","shell.execute_reply.started":"2023-01-02T21:50:49.053120Z","shell.execute_reply":"2023-01-02T21:50:49.059988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Preparing data for machine learning models**","metadata":{}},{"cell_type":"markdown","source":"* **Building a datablock for the model**","metadata":{}},{"cell_type":"code","source":"from fastai.tabular.all import TabularPandas\nfrom fastai.tabular.data import Categorify, Normalize\n\ndo = TabularPandas(train,\n                   procs = [Categorify,Normalize],\n                   cat_names = cat_names,\n                   cont_names = cont_names,\n                   y_names='target',\n                   y_block = CategoryBlock,\n                   splits=splits)","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:49.062890Z","iopub.execute_input":"2023-01-02T21:50:49.063963Z","iopub.status.idle":"2023-01-02T21:50:51.133801Z","shell.execute_reply.started":"2023-01-02T21:50:49.063923Z","shell.execute_reply":"2023-01-02T21:50:51.133140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Lets see our trainning dataset**","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"do.xs.iloc[:2]","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:51.135027Z","iopub.execute_input":"2023-01-02T21:50:51.136122Z","iopub.status.idle":"2023-01-02T21:50:51.189933Z","shell.execute_reply.started":"2023-01-02T21:50:51.136089Z","shell.execute_reply":"2023-01-02T21:50:51.188489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Now the shape**","metadata":{}},{"cell_type":"code","source":"do.xs.shape,train.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:51.191154Z","iopub.execute_input":"2023-01-02T21:50:51.191496Z","iopub.status.idle":"2023-01-02T21:50:51.236008Z","shell.execute_reply.started":"2023-01-02T21:50:51.191466Z","shell.execute_reply":"2023-01-02T21:50:51.234729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **lets create a dataloader of a batch size of 2048 (process 2048 samples at a time during training)**","metadata":{}},{"cell_type":"code","source":"dls = do.dataloaders(bs=2048)","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:51.237287Z","iopub.execute_input":"2023-01-02T21:50:51.237745Z","iopub.status.idle":"2023-01-02T21:50:51.259534Z","shell.execute_reply.started":"2023-01-02T21:50:51.237718Z","shell.execute_reply":"2023-01-02T21:50:51.258294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Describe the data loader**","metadata":{}},{"cell_type":"code","source":"dls.show_batch()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:51.264579Z","iopub.execute_input":"2023-01-02T21:50:51.264822Z","iopub.status.idle":"2023-01-02T21:50:52.167526Z","shell.execute_reply.started":"2023-01-02T21:50:51.264800Z","shell.execute_reply":"2023-01-02T21:50:52.166099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Building the tabular learner after creating the dataloader and using the TabularPandas from FastAI**","metadata":{}},{"cell_type":"code","source":"from fastai.tabular.learner import tabular_learner \n\nlearn = tabular_learner(dls, \n                        metrics=accuracy, \n                        layers = [512,256,128,128,64], \n                        wd=0.1)","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:52.169047Z","iopub.execute_input":"2023-01-02T21:50:52.169492Z","iopub.status.idle":"2023-01-02T21:50:52.188890Z","shell.execute_reply.started":"2023-01-02T21:50:52.169449Z","shell.execute_reply":"2023-01-02T21:50:52.187616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Finding the optimale learning rate using lr_finder**","metadata":{}},{"cell_type":"code","source":"lr_valley = learn.lr_find()\n","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:50:52.190299Z","iopub.execute_input":"2023-01-02T21:50:52.190727Z","iopub.status.idle":"2023-01-02T21:51:07.740746Z","shell.execute_reply.started":"2023-01-02T21:50:52.190687Z","shell.execute_reply":"2023-01-02T21:51:07.739414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print({lr_valley})","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:51:07.742138Z","iopub.execute_input":"2023-01-02T21:51:07.742452Z","iopub.status.idle":"2023-01-02T21:51:07.751868Z","shell.execute_reply.started":"2023-01-02T21:51:07.742425Z","shell.execute_reply":"2023-01-02T21:51:07.750415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.fit_one_cycle(30, lr_valley)","metadata":{"execution":{"iopub.status.busy":"2023-01-02T21:51:07.753194Z","iopub.execute_input":"2023-01-02T21:51:07.753942Z","iopub.status.idle":"2023-01-02T22:10:05.049995Z","shell.execute_reply.started":"2023-01-02T21:51:07.753871Z","shell.execute_reply":"2023-01-02T22:10:05.049114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Recorder plot how our  model is performing**","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"learn.recorder.plot_loss()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:05.050875Z","iopub.execute_input":"2023-01-02T22:10:05.051734Z","iopub.status.idle":"2023-01-02T22:10:05.441043Z","shell.execute_reply.started":"2023-01-02T22:10:05.051708Z","shell.execute_reply":"2023-01-02T22:10:05.440169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **look into the result of learner**","metadata":{}},{"cell_type":"code","source":"learn.show_results()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:05.442303Z","iopub.execute_input":"2023-01-02T22:10:05.443766Z","iopub.status.idle":"2023-01-02T22:10:05.741525Z","shell.execute_reply.started":"2023-01-02T22:10:05.443695Z","shell.execute_reply":"2023-01-02T22:10:05.740017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"row, clas, probs = learn.predict(train.iloc[0])","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:05.743449Z","iopub.execute_input":"2023-01-02T22:10:05.744007Z","iopub.status.idle":"2023-01-02T22:10:05.810449Z","shell.execute_reply.started":"2023-01-02T22:10:05.743973Z","shell.execute_reply":"2023-01-02T22:10:05.808875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"row.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:05.812039Z","iopub.execute_input":"2023-01-02T22:10:05.812493Z","iopub.status.idle":"2023-01-02T22:10:05.872934Z","shell.execute_reply.started":"2023-01-02T22:10:05.812453Z","shell.execute_reply":"2023-01-02T22:10:05.872033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"interp = ClassificationInterpretation.from_learner(learn)\ninterp.plot_confusion_matrix()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:05.874033Z","iopub.execute_input":"2023-01-02T22:10:05.874341Z","iopub.status.idle":"2023-01-02T22:10:11.726471Z","shell.execute_reply.started":"2023-01-02T22:10:05.874306Z","shell.execute_reply":"2023-01-02T22:10:11.725764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Setuping the dataset for the prediction**","metadata":{}},{"cell_type":"code","source":"test_tf.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:11.727638Z","iopub.execute_input":"2023-01-02T22:10:11.728075Z","iopub.status.idle":"2023-01-02T22:10:11.750949Z","shell.execute_reply.started":"2023-01-02T22:10:11.728048Z","shell.execute_reply":"2023-01-02T22:10:11.750207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_tf.drop(\"id\", axis=1, inplace= True)","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:11.752250Z","iopub.execute_input":"2023-01-02T22:10:11.752772Z","iopub.status.idle":"2023-01-02T22:10:11.874863Z","shell.execute_reply.started":"2023-01-02T22:10:11.752740Z","shell.execute_reply":"2023-01-02T22:10:11.873405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_tf","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:11.876537Z","iopub.execute_input":"2023-01-02T22:10:11.876992Z","iopub.status.idle":"2023-01-02T22:10:12.247842Z","shell.execute_reply.started":"2023-01-02T22:10:11.876950Z","shell.execute_reply":"2023-01-02T22:10:12.246525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dl = learn.dls.test_dl(test_tf)","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:12.249680Z","iopub.execute_input":"2023-01-02T22:10:12.250664Z","iopub.status.idle":"2023-01-02T22:10:13.138855Z","shell.execute_reply.started":"2023-01-02T22:10:12.250630Z","shell.execute_reply":"2023-01-02T22:10:13.137664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dl","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:13.140056Z","iopub.execute_input":"2023-01-02T22:10:13.140821Z","iopub.status.idle":"2023-01-02T22:10:13.147952Z","shell.execute_reply.started":"2023-01-02T22:10:13.140792Z","shell.execute_reply":"2023-01-02T22:10:13.146828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = learn.get_preds(dl=dl)","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:10:13.149622Z","iopub.execute_input":"2023-01-02T22:10:13.150504Z","iopub.status.idle":"2023-01-02T22:10:23.894919Z","shell.execute_reply.started":"2023-01-02T22:10:13.150435Z","shell.execute_reply":"2023-01-02T22:10:23.893495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:12:49.477039Z","iopub.execute_input":"2023-01-02T22:12:49.477479Z","iopub.status.idle":"2023-01-02T22:12:49.485165Z","shell.execute_reply.started":"2023-01-02T22:12:49.477446Z","shell.execute_reply":"2023-01-02T22:12:49.483785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Converting to submissive form**","metadata":{}},{"cell_type":"code","source":"preds = learn.get_preds(dl=dl)[0].argmax(1).numpy()\npreds[:5]","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:13:33.391595Z","iopub.execute_input":"2023-01-02T22:13:33.391927Z","iopub.status.idle":"2023-01-02T22:13:44.914792Z","shell.execute_reply.started":"2023-01-02T22:13:33.391899Z","shell.execute_reply":"2023-01-02T22:13:44.913732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Checking the sub form**","metadata":{}},{"cell_type":"code","source":"sample = pd.read_csv(\"../input/emsi-5iir-ds/sample_submission.csv\")\nsample","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:14:54.172401Z","iopub.execute_input":"2023-01-02T22:14:54.172751Z","iopub.status.idle":"2023-01-02T22:14:54.369748Z","shell.execute_reply.started":"2023-01-02T22:14:54.172721Z","shell.execute_reply":"2023-01-02T22:14:54.369022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.DataFrame({'id':sample.id, 'target': preds})\nsub.to_csv('submission.csv', index=False)\nsub.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:15:11.272483Z","iopub.execute_input":"2023-01-02T22:15:11.272860Z","iopub.status.idle":"2023-01-02T22:15:11.918933Z","shell.execute_reply.started":"2023-01-02T22:15:11.272829Z","shell.execute_reply":"2023-01-02T22:15:11.917606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Training and validating for bagging and algorithm boosting**","metadata":{}},{"cell_type":"code","source":"X_train, y_train = do.train.xs, do.train.ys.values.ravel()\nX_valid, y_valid = do.valid.xs, do.valid.ys.values.ravel()","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:17:07.795003Z","iopub.execute_input":"2023-01-02T22:17:07.795338Z","iopub.status.idle":"2023-01-02T22:17:07.881150Z","shell.execute_reply.started":"2023-01-02T22:17:07.795311Z","shell.execute_reply":"2023-01-02T22:17:07.879786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:17:17.583808Z","iopub.execute_input":"2023-01-02T22:17:17.584712Z","iopub.status.idle":"2023-01-02T22:17:17.661401Z","shell.execute_reply.started":"2023-01-02T22:17:17.584634Z","shell.execute_reply":"2023-01-02T22:17:17.660029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape, y_train.shape, X_valid.shape, y_valid.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:17:36.688754Z","iopub.execute_input":"2023-01-02T22:17:36.689188Z","iopub.status.idle":"2023-01-02T22:17:36.696422Z","shell.execute_reply.started":"2023-01-02T22:17:36.689152Z","shell.execute_reply":"2023-01-02T22:17:36.695600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nfrom sklearn.ensemble import HistGradientBoostingClassifier\nclf = HistGradientBoostingClassifier().fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:17:48.924062Z","iopub.execute_input":"2023-01-02T22:17:48.924451Z","iopub.status.idle":"2023-01-02T22:18:08.374415Z","shell.execute_reply.started":"2023-01-02T22:17:48.924414Z","shell.execute_reply":"2023-01-02T22:18:08.373351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf.score(X_valid, y_valid)","metadata":{"execution":{"iopub.status.busy":"2023-01-02T22:18:24.788284Z","iopub.execute_input":"2023-01-02T22:18:24.788660Z","iopub.status.idle":"2023-01-02T22:18:25.935869Z","shell.execute_reply.started":"2023-01-02T22:18:24.788622Z","shell.execute_reply":"2023-01-02T22:18:25.934878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}}]}