{"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":"markdown","source":"# hotel-id-2021-fgvc8","metadata":{}},{"cell_type":"code","source":"import os\nimport sys\nimport fastai\nimport numpy as np \n\n\nfrom fastai.imports import *\nfrom fastai.vision import *\nfrom fastai.vision.all import *\nfrom torchvision.models import vgg16_bn\nfrom tqdm import tqdm\nfrom sklearn import preprocessing","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-06-09T12:16:49.839071Z","iopub.execute_input":"2021-06-09T12:16:49.839623Z","iopub.status.idle":"2021-06-09T12:16:50.793775Z","shell.execute_reply.started":"2021-06-09T12:16:49.839563Z","shell.execute_reply":"2021-06-09T12:16:50.792958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Defining Directories\nwork_dir = Path('/kaggle/working/')\npath = Path('../input/hotel-id-2021-fgvc8')\n\nsample_sub = path / 'sample_submission.csv'\nlabels = path / 'train.csv'","metadata":{"execution":{"iopub.status.busy":"2021-06-09T12:16:50.798957Z","iopub.execute_input":"2021-06-09T12:16:50.799530Z","iopub.status.idle":"2021-06-09T12:16:50.804850Z","shell.execute_reply.started":"2021-06-09T12:16:50.799484Z","shell.execute_reply":"2021-06-09T12:16:50.803585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Reading csv\ntrain_data = pd.read_csv(labels)\ndf_sample = pd.read_csv(sample_sub)\n","metadata":{"execution":{"iopub.status.busy":"2021-06-09T12:16:50.806700Z","iopub.execute_input":"2021-06-09T12:16:50.807196Z","iopub.status.idle":"2021-06-09T12:16:50.961006Z","shell.execute_reply.started":"2021-06-09T12:16:50.807150Z","shell.execute_reply":"2021-06-09T12:16:50.959656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head(5)","metadata":{"execution":{"iopub.status.busy":"2021-06-09T12:16:50.962141Z","iopub.execute_input":"2021-06-09T12:16:50.962449Z","iopub.status.idle":"2021-06-09T12:16:50.979842Z","shell.execute_reply.started":"2021-06-09T12:16:50.962421Z","shell.execute_reply":"2021-06-09T12:16:50.978502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['image_path']= train_data['chain'].astype(str)  + '/' + train_data['image'].astype(str)\ntrain_data[:3]","metadata":{"execution":{"iopub.status.busy":"2021-06-09T12:25:58.939373Z","iopub.execute_input":"2021-06-09T12:25:58.939776Z","iopub.status.idle":"2021-06-09T12:25:59.116725Z","shell.execute_reply.started":"2021-06-09T12:25:58.939742Z","shell.execute_reply":"2021-06-09T12:25:59.115718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len_data = len(train_data.value_counts())\n\nprint(\"data Length:\", len_data)\nprint(\"Hotel Chains:\",train_data['chain'].unique())\nchain_len = len(train_data['chain'].unique())-1\nchain_len","metadata":{"execution":{"iopub.status.busy":"2021-06-09T12:16:50.981210Z","iopub.execute_input":"2021-06-09T12:16:50.981514Z","iopub.status.idle":"2021-06-09T12:16:51.190446Z","shell.execute_reply.started":"2021-06-09T12:16:50.981485Z","shell.execute_reply":"2021-06-09T12:16:51.188996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Hotels per Chain","metadata":{}},{"cell_type":"code","source":"hotel_per_chain={}\nchains = train_data['chain'].unique()\nfor chain_id in chains:\n    hotel_per_chain[chain_id] = train_data[train_data['chain']==chain_id]['hotel_id'].nunique()\n\nbar = plt.bar(x=hotel_per_chain.keys(),height=hotel_per_chain.values())\nplt.xlabel(\"Chain ID\")\nplt.ylabel(\"Count\")\nplt.title(\"Hotels per Chain\")","metadata":{"execution":{"iopub.status.busy":"2021-06-09T12:16:51.193346Z","iopub.execute_input":"2021-06-09T12:16:51.193670Z","iopub.status.idle":"2021-06-09T12:16:51.787746Z","shell.execute_reply.started":"2021-06-09T12:16:51.193640Z","shell.execute_reply":"2021-06-09T12:16:51.786698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Images per Hotel","metadata":{}},{"cell_type":"code","source":"image_per_hotel=[]\nhotels_id = train_data['hotel_id'].unique()\nfor hotel_id in hotels_id:\n    image_per_hotel.append(train_data[train_data['hotel_id']==hotel_id]['image'].nunique())\n\n    \nhotel_image_df = pd.DataFrame({\"hotel_id\":map(str,hotels_id),\"image_count\":image_per_hotel})\nhotel_image_df.sort_values(by=\"image_count\",ascending=False,inplace=True)  \n\nplt.figure(figsize=[15,15])\n\nplt.bar(x=hotel_image_df[\"hotel_id\"],height=hotel_image_df[\"image_count\"])\nplt.xlabel(\"Hotel ID\")\n# \nplt.ylabel(\"Image Count\")\nplt.title(\"Hotels and their image count\")","metadata":{"execution":{"iopub.status.busy":"2021-06-09T12:18:15.735378Z","iopub.execute_input":"2021-06-09T12:18:15.736072Z","iopub.status.idle":"2021-06-09T12:20:07.879421Z","shell.execute_reply.started":"2021-06-09T12:18:15.736016Z","shell.execute_reply":"2021-06-09T12:20:07.878282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Dataset samples\n","metadata":{}},{"cell_type":"code","source":"train_dir = '../input/hotel-id-2021-fgvc8/train_images'\ndataset = ImageDataLoaders.from_df(df = train_data[['image_path', 'chain']],\n                                   path = train_dir,\n                                   folder = '.',\n                                   item_tfms=Resize(128, method='pad', pad_mode='reflection'),\n                                   valid_pct=0.2,\n                                   bs=32)","metadata":{"execution":{"iopub.status.busy":"2021-06-09T12:30:31.969255Z","iopub.execute_input":"2021-06-09T12:30:31.969628Z","iopub.status.idle":"2021-06-09T12:30:44.161460Z","shell.execute_reply.started":"2021-06-09T12:30:31.969597Z","shell.execute_reply":"2021-06-09T12:30:44.160233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.show_batch()","metadata":{"execution":{"iopub.status.busy":"2021-06-09T12:30:44.163260Z","iopub.execute_input":"2021-06-09T12:30:44.163583Z","iopub.status.idle":"2021-06-09T12:30:48.580713Z","shell.execute_reply.started":"2021-06-09T12:30:44.163550Z","shell.execute_reply":"2021-06-09T12:30:48.579774Z"},"trusted":true},"execution_count":null,"outputs":[]}]}