{"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":"## Brief EDA of the Happywhale competition data. 🐋🐬","metadata":{}},{"cell_type":"markdown","source":"<img src=\"https://static.simpsonswiki.com/images/thumb/e/ec/Betsy.png/250px-Betsy.png\" alt=\"alt text\" title=\"image Title\" height=\"750\"/>\n","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nimport cv2\nimport matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-01T19:35:44.265811Z","iopub.execute_input":"2022-02-01T19:35:44.266407Z","iopub.status.idle":"2022-02-01T19:35:44.272638Z","shell.execute_reply.started":"2022-02-01T19:35:44.266372Z","shell.execute_reply":"2022-02-01T19:35:44.271637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Look at the train csv","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('../input/happy-whale-and-dolphin/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-02-01T19:27:53.617096Z","iopub.execute_input":"2022-02-01T19:27:53.617386Z","iopub.status.idle":"2022-02-01T19:27:53.739294Z","shell.execute_reply.started":"2022-02-01T19:27:53.617350Z","shell.execute_reply":"2022-02-01T19:27:53.738515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-01T19:28:02.342506Z","iopub.execute_input":"2022-02-01T19:28:02.342951Z","iopub.status.idle":"2022-02-01T19:28:02.362675Z","shell.execute_reply.started":"2022-02-01T19:28:02.342902Z","shell.execute_reply":"2022-02-01T19:28:02.362112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## The dataframe has 3 rows:\n* Image id\n* The species\n* An individual id\n\n## How many images do we have?","metadata":{}},{"cell_type":"code","source":"df.image.shape","metadata":{"execution":{"iopub.status.busy":"2022-02-01T19:29:28.902578Z","iopub.execute_input":"2022-02-01T19:29:28.902936Z","iopub.status.idle":"2022-02-01T19:29:28.914084Z","shell.execute_reply.started":"2022-02-01T19:29:28.902902Z","shell.execute_reply":"2022-02-01T19:29:28.913366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Number of species?","metadata":{}},{"cell_type":"code","source":"len(df.species.unique())","metadata":{"execution":{"iopub.status.busy":"2022-02-01T19:30:16.793128Z","iopub.execute_input":"2022-02-01T19:30:16.793863Z","iopub.status.idle":"2022-02-01T19:30:16.804654Z","shell.execute_reply.started":"2022-02-01T19:30:16.793818Z","shell.execute_reply":"2022-02-01T19:30:16.803855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## How many unique individual id?","metadata":{}},{"cell_type":"code","source":"len(df.individual_id.unique())","metadata":{"execution":{"iopub.status.busy":"2022-02-01T19:30:33.742646Z","iopub.execute_input":"2022-02-01T19:30:33.743129Z","iopub.status.idle":"2022-02-01T19:30:33.755632Z","shell.execute_reply.started":"2022-02-01T19:30:33.743094Z","shell.execute_reply":"2022-02-01T19:30:33.754385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Let's find the number of images per specie","metadata":{}},{"cell_type":"code","source":"df.groupby('species').count().plot.barh(figsize=(10,8))","metadata":{"execution":{"iopub.status.busy":"2022-02-01T19:38:58.347300Z","iopub.execute_input":"2022-02-01T19:38:58.348074Z","iopub.status.idle":"2022-02-01T19:38:58.908027Z","shell.execute_reply.started":"2022-02-01T19:38:58.348018Z","shell.execute_reply":"2022-02-01T19:38:58.907085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# The number of image per species seems to be inbalanced. 🧐","metadata":{}},{"cell_type":"markdown","source":"# Explore some images","metadata":{}},{"cell_type":"code","source":"df_show = df.sample(9)\nimg_ids = df_show['image'].values\nspecies_ids = df_show['species'].values\n\npath = '../input/happy-whale-and-dolphin/train_images/'\n\nfig = plt.figure(figsize=(15, 15))\ncolumns = 3\nrows = 3\nfor i in range(1, columns*rows +1):\n    img = cv2.imread(path+ img_ids[i-1])\n    fig.add_subplot(rows, columns, i)\n    plt.imshow(img)\n    plt.title(species_ids[i-1])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-01T20:01:43.695607Z","iopub.execute_input":"2022-02-01T20:01:43.695891Z","iopub.status.idle":"2022-02-01T20:01:49.972006Z","shell.execute_reply.started":"2022-02-01T20:01:43.695859Z","shell.execute_reply":"2022-02-01T20:01:49.971281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Now by unique id which is the label we will predict.","metadata":{}},{"cell_type":"code","source":"random_id = df.individual_id.sample(1).values\nunique_id = df[df['individual_id'] == random_id[0]]\n\nimg_ids = unique_id.sample(3)['image'].values\n\npath = '../input/happy-whale-and-dolphin/train_images/'\n\nfig = plt.figure(figsize=(15, 15))\ncolumns = 3\nrows = 1\nfor i in range(1, columns*rows +1):\n    img = cv2.imread(path+ img_ids[i-1])\n    fig.add_subplot(rows, columns, i)\n    plt.imshow(img)\n    plt.title(unique_id.species.unique()[0] + '\\n' + random_id[0])\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-02-01T19:59:41.186040Z","iopub.execute_input":"2022-02-01T19:59:41.186394Z","iopub.status.idle":"2022-02-01T19:59:41.935212Z","shell.execute_reply.started":"2022-02-01T19:59:41.186358Z","shell.execute_reply":"2022-02-01T19:59:41.934011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Working...","metadata":{}}]}