{"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 pandas as pd\nimport warnings\nwarnings.simplefilter(action='ignore', category=FutureWarning)\ntrain = pd.read_csv('../input/happy-whale-and-dolphin/train.csv')\ntest = pd.read_csv('../input/happy-whale-and-dolphin/sample_submission.csv')\nimport pickle\nimage_sizes = pickle.load(open('../input/whale-image-eda-image-size/sizes.pkl','rb'))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:54:14.561138Z","iopub.execute_input":"2022-02-02T06:54:14.561543Z","iopub.status.idle":"2022-02-02T06:54:14.867396Z","shell.execute_reply.started":"2022-02-02T06:54:14.561428Z","shell.execute_reply":"2022-02-02T06:54:14.866747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_sizes = []\nfor name, size in zip(image_sizes['train_images']['names'], image_sizes['train_images']['sizes']):\n    name = name.replace('../input/happy-whale-and-dolphin/train_images/','')\n    train_sizes.append({'image':name, 'width': size[0], 'height': size[1]})\ntest_sizes = []\nfor name, size in zip(image_sizes['test_images']['names'], image_sizes['test_images']['sizes']):\n    name = name.replace('../input/happy-whale-and-dolphin/test_images/','')\n    test_sizes.append({'image':name, 'width': size[0], 'height': size[1]})","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:54:14.868887Z","iopub.execute_input":"2022-02-02T06:54:14.869221Z","iopub.status.idle":"2022-02-02T06:54:14.975084Z","shell.execute_reply.started":"2022-02-02T06:54:14.869194Z","shell.execute_reply":"2022-02-02T06:54:14.974148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images = pd.DataFrame(train_sizes)\ntest_images = pd.DataFrame(test_sizes)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:54:14.976336Z","iopub.execute_input":"2022-02-02T06:54:14.976666Z","iopub.status.idle":"2022-02-02T06:54:15.104966Z","shell.execute_reply.started":"2022-02-02T06:54:14.976628Z","shell.execute_reply":"2022-02-02T06:54:15.104294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.merge(train_images, on=['image'], how='inner')\ntest = test.merge(test_images, on=['image'], how='inner')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:54:15.106816Z","iopub.execute_input":"2022-02-02T06:54:15.107262Z","iopub.status.idle":"2022-02-02T06:54:15.196146Z","shell.execute_reply.started":"2022-02-02T06:54:15.107228Z","shell.execute_reply":"2022-02-02T06:54:15.195304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2022-02-02T06:54:15.197401Z","iopub.execute_input":"2022-02-02T06:54:15.197699Z","iopub.status.idle":"2022-02-02T06:54:15.220707Z","shell.execute_reply.started":"2022-02-02T06:54:15.197669Z","shell.execute_reply":"2022-02-02T06:54:15.220030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['group'] = 'train'\ntrain['predictions'] = ''\ntest['group'] = 'test'\ntest['species'] = ''\ntest['individual_id'] = ''\nall_df = pd.concat([train,test], axis=0)\nall_df['ratio'] = all_df['height']/all_df['width']\nall_df","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:54:15.221922Z","iopub.execute_input":"2022-02-02T06:54:15.222272Z","iopub.status.idle":"2022-02-02T06:54:15.264069Z","shell.execute_reply.started":"2022-02-02T06:54:15.222242Z","shell.execute_reply":"2022-02-02T06:54:15.263464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_df['area'] = all_df['width']*all_df['height']","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:54:15.265143Z","iopub.execute_input":"2022-02-02T06:54:15.265821Z","iopub.status.idle":"2022-02-02T06:54:15.273823Z","shell.execute_reply.started":"2022-02-02T06:54:15.265767Z","shell.execute_reply":"2022-02-02T06:54:15.272718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_df = all_df.reset_index()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:54:15.275201Z","iopub.execute_input":"2022-02-02T06:54:15.275939Z","iopub.status.idle":"2022-02-02T06:54:15.318827Z","shell.execute_reply.started":"2022-02-02T06:54:15.275897Z","shell.execute_reply":"2022-02-02T06:54:15.318116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def fix_species_name(species):\n    if species in ['bottlenose_dolphin','bottlenose_dolpin']:\n        return 'bottlenose_dolphin'\n    elif species in ['killer_whale','kiler_whale']:\n        return 'kiler_whale'\n    else:\n        return species\nall_df.species = all_df.species.apply(lambda name: fix_species_name(name))","metadata":{"execution":{"iopub.status.busy":"2022-02-02T06:54:15.319944Z","iopub.execute_input":"2022-02-02T06:54:15.320691Z","iopub.status.idle":"2022-02-02T06:54:15.359711Z","shell.execute_reply.started":"2022-02-02T06:54:15.320655Z","shell.execute_reply":"2022-02-02T06:54:15.358678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt \np = sns.jointplot(\"width\", \"height\", all_df, hue='group')\np.fig.suptitle(\"Train vs Test (Width vs Height)\")\np.fig.set_dpi(100)\n\np = sns.jointplot(\"width\", \"ratio\", all_df, hue='group')\np.fig.suptitle(\"Train vs Test (Width vs Ratio)\")\np.fig.set_dpi(100)\n\np = sns.jointplot(\"height\", \"ratio\", all_df, hue='group')\np.fig.suptitle(\"Train vs Test (Height vs Ratio)\")\np.fig.set_dpi(100)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:54:15.363198Z","iopub.execute_input":"2022-02-02T06:54:15.363581Z","iopub.status.idle":"2022-02-02T06:54:35.688244Z","shell.execute_reply.started":"2022-02-02T06:54:15.363531Z","shell.execute_reply":"2022-02-02T06:54:35.687582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train vs Test images are well overlapped","metadata":{}},{"cell_type":"code","source":"prev = 0\nfor max_w in [500,1000,1500,2000,5000]:\n    curr = max_w\n    p = sns.jointplot(\"width\", \"height\", all_df[(all_df.width<curr) & (all_df.width>=prev)], hue='group')\n    p.fig.suptitle(f\"Train vs Test Width:{prev} to {curr}\")\n    p.fig.set_dpi(100)\n    prev = curr","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:54:35.689753Z","iopub.execute_input":"2022-02-02T06:54:35.690246Z","iopub.status.idle":"2022-02-02T06:54:45.517334Z","shell.execute_reply.started":"2022-02-02T06:54:35.690197Z","shell.execute_reply":"2022-02-02T06:54:45.516447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prev = 0\nfor max_h in [500,1000,1500,2000,5000]:\n    curr = max_h\n    p = sns.jointplot(\"width\", \"height\", all_df[(all_df.height<curr) & (all_df.height>=prev)], hue='group')\n    p.fig.suptitle(f\"Train vs Test Height:{prev} to {curr}\")\n    p.fig.set_dpi(100)\n    prev = curr","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:54:45.518666Z","iopub.execute_input":"2022-02-02T06:54:45.518898Z","iopub.status.idle":"2022-02-02T06:54:55.181456Z","shell.execute_reply.started":"2022-02-02T06:54:45.518870Z","shell.execute_reply":"2022-02-02T06:54:55.180562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Interesting Data split by height is good option","metadata":{}},{"cell_type":"code","source":"all_species = set(all_df['species'].values)-set([''])\nlen(all_species)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:56:25.485349Z","iopub.execute_input":"2022-02-02T06:56:25.485715Z","iopub.status.idle":"2022-02-02T06:56:25.496052Z","shell.execute_reply.started":"2022-02-02T06:56:25.485676Z","shell.execute_reply":"2022-02-02T06:56:25.495167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for name in all_species:\n    p = sns.jointplot(\"width\", \"height\", all_df[(all_df.species==name)], hue='group')\n    p.fig.suptitle(f\"{name} distribution\")\n    p.fig.set_dpi(100)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-02T06:56:27.094694Z","iopub.execute_input":"2022-02-02T06:56:27.095125Z","iopub.status.idle":"2022-02-02T06:56:46.188017Z","shell.execute_reply.started":"2022-02-02T06:56:27.095094Z","shell.execute_reply":"2022-02-02T06:56:46.187030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **frasiers dolphin are outliers from all other species**","metadata":{}},{"cell_type":"code","source":"all_df.to_csv('all.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-02-02T06:56:46.189717Z","iopub.execute_input":"2022-02-02T06:56:46.189960Z","iopub.status.idle":"2022-02-02T06:56:46.803787Z","shell.execute_reply.started":"2022-02-02T06:56:46.189931Z","shell.execute_reply":"2022-02-02T06:56:46.802847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Please Upvote if you find this Helpful","metadata":{}},{"cell_type":"markdown","source":"# Can we find the source from width/height/species analysis ? ","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}