{"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":"","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport cv2","metadata":{"execution":{"iopub.status.busy":"2022-02-02T10:29:21.630794Z","iopub.execute_input":"2022-02-02T10:29:21.631243Z","iopub.status.idle":"2022-02-02T10:29:21.637066Z","shell.execute_reply.started":"2022-02-02T10:29:21.631195Z","shell.execute_reply":"2022-02-02T10:29:21.636151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"../input/happy-whale-and-dolphin/train.csv\")\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-02T10:29:21.639119Z","iopub.execute_input":"2022-02-02T10:29:21.640241Z","iopub.status.idle":"2022-02-02T10:29:21.718131Z","shell.execute_reply.started":"2022-02-02T10:29:21.640176Z","shell.execute_reply":"2022-02-02T10:29:21.717214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'Unique species: {train.species.nunique()}')\nprint(f'Species names: {train.species.unique()}')","metadata":{"execution":{"iopub.status.busy":"2022-02-02T10:29:21.719655Z","iopub.execute_input":"2022-02-02T10:29:21.720598Z","iopub.status.idle":"2022-02-02T10:29:21.737604Z","shell.execute_reply.started":"2022-02-02T10:29:21.720549Z","shell.execute_reply":"2022-02-02T10:29:21.736391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Distribution of the classes\nspecies_count = train[\"species\"].value_counts()\n\nplt.figure(figsize=(20,10))\nplt.bar(species_count.index, height=species_count)\nplt.xticks(rotation=90, fontsize=16)\nplt.yticks(fontsize=16)\nplt.title('Distribution of the species')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-02T10:29:21.74058Z","iopub.execute_input":"2022-02-02T10:29:21.741216Z","iopub.status.idle":"2022-02-02T10:29:22.171935Z","shell.execute_reply.started":"2022-02-02T10:29:21.741167Z","shell.execute_reply":"2022-02-02T10:29:22.170656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train/test images paths\ntrain_dir = '../input/happy-whale-and-dolphin/train_images'\ntest_dir = '../input/happy-whale-and-dolphin/test_images'\n\nprint(f'Number of train images: {len([file for file in os.listdir(train_dir)])}')\nprint(f'Number of test images: {len([file for file in os.listdir(test_dir)])}')","metadata":{"execution":{"iopub.status.busy":"2022-02-02T10:29:22.173903Z","iopub.execute_input":"2022-02-02T10:29:22.174223Z","iopub.status.idle":"2022-02-02T10:29:22.223861Z","shell.execute_reply.started":"2022-02-02T10:29:22.174177Z","shell.execute_reply":"2022-02-02T10:29:22.222955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Image shapes\n#train['img_size'] = train.image.apply(lambda x: cv2.imread(f'{train_dir}/{x}').shape)\n#train.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-02T10:29:22.224815Z","iopub.execute_input":"2022-02-02T10:29:22.225042Z","iopub.status.idle":"2022-02-02T10:29:22.229875Z","shell.execute_reply.started":"2022-02-02T10:29:22.225015Z","shell.execute_reply":"2022-02-02T10:29:22.228727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"species_count.index[-1]","metadata":{"execution":{"iopub.status.busy":"2022-02-02T10:29:22.231041Z","iopub.execute_input":"2022-02-02T10:29:22.231246Z","iopub.status.idle":"2022-02-02T10:29:22.244301Z","shell.execute_reply.started":"2022-02-02T10:29:22.231221Z","shell.execute_reply":"2022-02-02T10:29:22.243688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.species.astype('str')","metadata":{"execution":{"iopub.status.busy":"2022-02-02T10:29:22.245234Z","iopub.execute_input":"2022-02-02T10:29:22.245472Z","iopub.status.idle":"2022-02-02T10:29:22.262074Z","shell.execute_reply.started":"2022-02-02T10:29:22.245446Z","shell.execute_reply":"2022-02-02T10:29:22.261072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Rare species\ntrain_rare = train[train.species==species_count.index[-1]].reset_index(drop=True)\nplt.figure(figsize=(20,20))\nfor i in range(len(train_rare)):\n    plt.subplot(4,4,i+1)\n    img = cv2.imread(f'{train_dir}/{train_rare.image[i]}')\n    plt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2022-02-02T10:32:20.522887Z","iopub.execute_input":"2022-02-02T10:32:20.523235Z","iopub.status.idle":"2022-02-02T10:32:23.515876Z","shell.execute_reply.started":"2022-02-02T10:32:20.523202Z","shell.execute_reply":"2022-02-02T10:32:23.51487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}