{"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":"# [Happywhale - Whale and Dolphin Identification](https://www.kaggle.com/c/happy-whale-and-dolphin)\n> Identify whales and dolphins by unique characteristics\n\n<img src=\"https://storage.googleapis.com/kaggle-competitions/kaggle/22962/logos/header.png?t=2021-03-17-22-44-09\">","metadata":{}},{"cell_type":"markdown","source":"# 🛠 Dependencies","metadata":{}},{"cell_type":"code","source":"import os\nimport pandas as pd\nimport cv2\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:53.882510Z","iopub.execute_input":"2022-02-03T12:47:53.883066Z","iopub.status.idle":"2022-02-03T12:47:53.888823Z","shell.execute_reply.started":"2022-02-03T12:47:53.883024Z","shell.execute_reply":"2022-02-03T12:47:53.887581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Meta Data\n\n* train_images/ - a folder containing the training images\n\n* train.csv - provides the species and the individual_id for each of the training images\n\n* test_images/ - a folder containing the test images; for each image, your task is to predict the individual_id; no   species information is given for the test data; there are individuals in the test data that are not observed in the training data, which should be predicted as new_individual.\n\n* sample_submission.csv - a sample submission file in the correct format","metadata":{}},{"cell_type":"markdown","source":"# Data ","metadata":{}},{"cell_type":"code","source":"path = '/kaggle/input/happy-whale-and-dolphin/'\nos.listdir(path)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:53.891262Z","iopub.execute_input":"2022-02-03T12:47:53.891828Z","iopub.status.idle":"2022-02-03T12:47:53.909770Z","shell.execute_reply.started":"2022-02-03T12:47:53.891778Z","shell.execute_reply":"2022-02-03T12:47:53.909027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(path+'train.csv')\nsamp_sub = pd.read_csv(path+'sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:53.911480Z","iopub.execute_input":"2022-02-03T12:47:53.911704Z","iopub.status.idle":"2022-02-03T12:47:54.034316Z","shell.execute_reply.started":"2022-02-03T12:47:53.911675Z","shell.execute_reply":"2022-02-03T12:47:54.033167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Number train samples: ', len(train_data))\nprint('Number train images: ', len(os.listdir(path+'train_images')))\nprint('Number test images: ', len(os.listdir(path+'test_images')))","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.035871Z","iopub.execute_input":"2022-02-03T12:47:54.036163Z","iopub.status.idle":"2022-02-03T12:47:54.084793Z","shell.execute_reply.started":"2022-02-03T12:47:54.036129Z","shell.execute_reply":"2022-02-03T12:47:54.083811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.087036Z","iopub.execute_input":"2022-02-03T12:47:54.087309Z","iopub.status.idle":"2022-02-03T12:47:54.099500Z","shell.execute_reply.started":"2022-02-03T12:47:54.087274Z","shell.execute_reply":"2022-02-03T12:47:54.098505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{}},{"cell_type":"code","source":"train_data","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.100992Z","iopub.execute_input":"2022-02-03T12:47:54.101225Z","iopub.status.idle":"2022-02-03T12:47:54.124730Z","shell.execute_reply.started":"2022-02-03T12:47:54.101197Z","shell.execute_reply":"2022-02-03T12:47:54.123829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Length of train data\", len(train_data))\nprint(\"Number of Species: \",len(train_data['species'].unique()))\nprint(\"number of Individuals: \", len(train_data['individual_id'].unique()))","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.126234Z","iopub.execute_input":"2022-02-03T12:47:54.127067Z","iopub.status.idle":"2022-02-03T12:47:54.150147Z","shell.execute_reply.started":"2022-02-03T12:47:54.127015Z","shell.execute_reply":"2022-02-03T12:47:54.149191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['species'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.151676Z","iopub.execute_input":"2022-02-03T12:47:54.152517Z","iopub.status.idle":"2022-02-03T12:47:54.163795Z","shell.execute_reply.started":"2022-02-03T12:47:54.152476Z","shell.execute_reply":"2022-02-03T12:47:54.162794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['species'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.165163Z","iopub.execute_input":"2022-02-03T12:47:54.165507Z","iopub.status.idle":"2022-02-03T12:47:54.185029Z","shell.execute_reply.started":"2022-02-03T12:47:54.165478Z","shell.execute_reply":"2022-02-03T12:47:54.184150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Load Single Image","metadata":{}},{"cell_type":"code","source":"file = train_data.loc[0, 'image']\nspecies = train_data.loc[0, 'species']\nindividual_id = train_data.loc[0, 'individual_id']\nprint(file)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.186299Z","iopub.execute_input":"2022-02-03T12:47:54.186653Z","iopub.status.idle":"2022-02-03T12:47:54.194653Z","shell.execute_reply.started":"2022-02-03T12:47:54.186623Z","shell.execute_reply":"2022-02-03T12:47:54.193665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = cv2.imread(path+'train_images/'+file)\nprint('Shape: ', img.shape)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.196876Z","iopub.execute_input":"2022-02-03T12:47:54.197258Z","iopub.status.idle":"2022-02-03T12:47:54.218392Z","shell.execute_reply.started":"2022-02-03T12:47:54.197211Z","shell.execute_reply":"2022-02-03T12:47:54.217400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(1, 1, figsize = (10, 10))\nax.imshow((cv2.cvtColor(img, cv2.COLOR_BGR2RGB)))\nax.set_xticklabels([])\nax.set_yticklabels([])\nax.set_title(species)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.219825Z","iopub.execute_input":"2022-02-03T12:47:54.220208Z","iopub.status.idle":"2022-02-03T12:47:54.740512Z","shell.execute_reply.started":"2022-02-03T12:47:54.220177Z","shell.execute_reply":"2022-02-03T12:47:54.739827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Raw Submission","metadata":{}},{"cell_type":"code","source":"samp_sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.741835Z","iopub.execute_input":"2022-02-03T12:47:54.742219Z","iopub.status.idle":"2022-02-03T12:47:54.752188Z","shell.execute_reply.started":"2022-02-03T12:47:54.742174Z","shell.execute_reply":"2022-02-03T12:47:54.751192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(samp_sub)\nsamp_sub[\"predictions\"] = \"new_individual\"\nprint(samp_sub)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.753678Z","iopub.execute_input":"2022-02-03T12:47:54.754110Z","iopub.status.idle":"2022-02-03T12:47:54.770857Z","shell.execute_reply.started":"2022-02-03T12:47:54.754071Z","shell.execute_reply":"2022-02-03T12:47:54.769928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samp_sub.to_csv('submission.csv', index = False)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T12:47:54.772500Z","iopub.execute_input":"2022-02-03T12:47:54.773477Z","iopub.status.idle":"2022-02-03T12:47:54.857544Z","shell.execute_reply.started":"2022-02-03T12:47:54.773413Z","shell.execute_reply":"2022-02-03T12:47:54.856610Z"},"trusted":true},"execution_count":null,"outputs":[]}]}