{"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 os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport cv2\nfrom tqdm import tqdm\nfrom glob import glob\n\nfrom termcolor import colored\nfrom colorama import Fore, Back, Style\n# colored output\ny_ = Fore.YELLOW\nr_ = Fore.RED\ng_ = Fore.GREEN\nb_ = Fore.BLUE\nm_ = Fore.MAGENTA\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:45.147100Z","iopub.execute_input":"2022-02-15T15:27:45.147508Z","iopub.status.idle":"2022-02-15T15:27:45.492501Z","shell.execute_reply.started":"2022-02-15T15:27:45.147410Z","shell.execute_reply":"2022-02-15T15:27:45.491427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMG_DIR=\"../input/happy-whale-and-dolphin\"","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:45.494636Z","iopub.execute_input":"2022-02-15T15:27:45.575782Z","iopub.status.idle":"2022-02-15T15:27:45.580355Z","shell.execute_reply.started":"2022-02-15T15:27:45.575713Z","shell.execute_reply":"2022-02-15T15:27:45.579088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv(\"../input/happy-whale-and-dolphin/train.csv\")\nsubmission=pd.read_csv(\"../input/happy-whale-and-dolphin/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:45.582269Z","iopub.execute_input":"2022-02-15T15:27:45.582805Z","iopub.status.idle":"2022-02-15T15:27:45.730567Z","shell.execute_reply.started":"2022-02-15T15:27:45.582760Z","shell.execute_reply":"2022-02-15T15:27:45.729508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:45.734722Z","iopub.execute_input":"2022-02-15T15:27:45.734953Z","iopub.status.idle":"2022-02-15T15:27:45.757171Z","shell.execute_reply.started":"2022-02-15T15:27:45.734925Z","shell.execute_reply":"2022-02-15T15:27:45.756155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:45.870495Z","iopub.execute_input":"2022-02-15T15:27:45.870758Z","iopub.status.idle":"2022-02-15T15:27:45.896859Z","shell.execute_reply.started":"2022-02-15T15:27:45.870729Z","shell.execute_reply":"2022-02-15T15:27:45.895564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:46.051062Z","iopub.execute_input":"2022-02-15T15:27:46.051437Z","iopub.status.idle":"2022-02-15T15:27:46.065200Z","shell.execute_reply.started":"2022-02-15T15:27:46.051397Z","shell.execute_reply":"2022-02-15T15:27:46.063843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"{r_}shape of the dataframe is : {g_}{train.shape}\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:46.200776Z","iopub.execute_input":"2022-02-15T15:27:46.201044Z","iopub.status.idle":"2022-02-15T15:27:46.207333Z","shell.execute_reply.started":"2022-02-15T15:27:46.201015Z","shell.execute_reply":"2022-02-15T15:27:46.206090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"{r_}Number of unique species is : {g_}{train.species.nunique()}\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:46.340943Z","iopub.execute_input":"2022-02-15T15:27:46.341601Z","iopub.status.idle":"2022-02-15T15:27:46.359445Z","shell.execute_reply.started":"2022-02-15T15:27:46.341548Z","shell.execute_reply":"2022-02-15T15:27:46.357884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nprint(train.species.unique())","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:46.585557Z","iopub.execute_input":"2022-02-15T15:27:46.586214Z","iopub.status.idle":"2022-02-15T15:27:46.596659Z","shell.execute_reply.started":"2022-02-15T15:27:46.586169Z","shell.execute_reply":"2022-02-15T15:27:46.595563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['species'] = train['species'].str.replace('bottlenose_dolpin','bottlenose_dolphin')\ntrain['species'] = train['species'].str.replace('kiler_whale','killer_whale')","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:46.885989Z","iopub.execute_input":"2022-02-15T15:27:46.886883Z","iopub.status.idle":"2022-02-15T15:27:46.975784Z","shell.execute_reply.started":"2022-02-15T15:27:46.886849Z","shell.execute_reply":"2022-02-15T15:27:46.974777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# append _whale to beluga and globis\ntrain[\"species\"].replace({\"beluga\": \"beluga_whale\", \"globis\": \"globis_whale\"}, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:46.977802Z","iopub.execute_input":"2022-02-15T15:27:46.978277Z","iopub.status.idle":"2022-02-15T15:27:46.995971Z","shell.execute_reply.started":"2022-02-15T15:27:46.978215Z","shell.execute_reply":"2022-02-15T15:27:46.994897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"{r_}Number of unique species is : {g_}{train.species.nunique()}\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:47.357088Z","iopub.execute_input":"2022-02-15T15:27:47.357936Z","iopub.status.idle":"2022-02-15T15:27:47.368952Z","shell.execute_reply.started":"2022-02-15T15:27:47.357901Z","shell.execute_reply":"2022-02-15T15:27:47.367704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(train.species.value_counts()).plot.bar(figsize=(12,8))\nplt.xticks(fontsize=12,fontweight='bold')\nplt.yticks(fontsize=12,fontweight='bold')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:47.611047Z","iopub.execute_input":"2022-02-15T15:27:47.611674Z","iopub.status.idle":"2022-02-15T15:27:48.068950Z","shell.execute_reply.started":"2022-02-15T15:27:47.611638Z","shell.execute_reply":"2022-02-15T15:27:48.068030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sp=train.groupby('individual_id').count()['species'].sort_values(ascending=False)[:20]\nsp.plot.bar(figsize=(12,8))\nplt.xticks(fontsize=12,fontweight='bold')\nplt.yticks(fontsize=12,fontweight='bold')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:48.070920Z","iopub.execute_input":"2022-02-15T15:27:48.072028Z","iopub.status.idle":"2022-02-15T15:27:48.479726Z","shell.execute_reply.started":"2022-02-15T15:27:48.071968Z","shell.execute_reply":"2022-02-15T15:27:48.477976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(train.groupby('individual_id').count()['image'].sort_values(ascending=False)[:20]).plot.bar(figsize=(12,8))\nplt.xticks(fontsize=12,fontweight='bold')\nplt.yticks(fontsize=12,fontweight='bold')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:48.481755Z","iopub.execute_input":"2022-02-15T15:27:48.482348Z","iopub.status.idle":"2022-02-15T15:27:48.871287Z","shell.execute_reply.started":"2022-02-15T15:27:48.482303Z","shell.execute_reply":"2022-02-15T15:27:48.868946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['label'] = train.species.map(lambda x: 'dolphin' if 'dolphin' in x else 'whale')\n\nfig, ax  = plt.subplots(figsize=(16, 8))\nfig.suptitle('Whales and Dolphins ', size = 20, font=\"Serif\")\nexplode = (0.05, 0.05)\nlabels = list(train.label.value_counts().index)\nsizes = train.label.value_counts().values\nax.pie(sizes, explode=explode,startangle=60, labels=labels,autopct='%1.0f%%', pctdistance=0.7, colors=[\"#0077b6\",\"#90e0ef\"])\nax.add_artist(plt.Circle((0,0),0.4,fc='white'))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:48.873949Z","iopub.execute_input":"2022-02-15T15:27:48.874407Z","iopub.status.idle":"2022-02-15T15:27:49.065398Z","shell.execute_reply.started":"2022-02-15T15:27:48.874363Z","shell.execute_reply":"2022-02-15T15:27:49.064261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label=train[train['label']=='dolphin']\nwhale=train[train['label']=='whale']","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:49.071162Z","iopub.execute_input":"2022-02-15T15:27:49.074055Z","iopub.status.idle":"2022-02-15T15:27:49.118306Z","shell.execute_reply.started":"2022-02-15T15:27:49.074003Z","shell.execute_reply":"2022-02-15T15:27:49.117133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(label.species.value_counts()).plot.bar(figsize=(12,10))\nplt.xticks(fontsize=12,fontweight='bold')\nplt.yticks(fontsize=12,fontweight='bold')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:49.120908Z","iopub.execute_input":"2022-02-15T15:27:49.121273Z","iopub.status.idle":"2022-02-15T15:27:49.400223Z","shell.execute_reply.started":"2022-02-15T15:27:49.121228Z","shell.execute_reply":"2022-02-15T15:27:49.399171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(whale.species.value_counts()).plot.bar(figsize=(12,10))\nplt.xticks(fontsize=12,fontweight='bold')\nplt.yticks(fontsize=12,fontweight='bold')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:27:49.401658Z","iopub.execute_input":"2022-02-15T15:27:49.402568Z","iopub.status.idle":"2022-02-15T15:27:49.769966Z","shell.execute_reply.started":"2022-02-15T15:27:49.402522Z","shell.execute_reply":"2022-02-15T15:27:49.768997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=\"train_images\"\ntest=\"test_images\"\nimg_path_train=glob(os.path.join(IMG_DIR,f\"{train}/*.jpg\"))\n","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:40:35.356947Z","iopub.execute_input":"2022-02-15T15:40:35.357596Z","iopub.status.idle":"2022-02-15T15:40:35.543204Z","shell.execute_reply.started":"2022-02-15T15:40:35.357560Z","shell.execute_reply":"2022-02-15T15:40:35.542145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_path_train[0]","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:40:38.094567Z","iopub.execute_input":"2022-02-15T15:40:38.094868Z","iopub.status.idle":"2022-02-15T15:40:38.104101Z","shell.execute_reply.started":"2022-02-15T15:40:38.094837Z","shell.execute_reply":"2022-02-15T15:40:38.102858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_path_test=glob(os.path.join(IMG_DIR,f\"{test}/*.jpg\"))\nimg_path_test[0]","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:41:13.980483Z","iopub.execute_input":"2022-02-15T15:41:13.980834Z","iopub.status.idle":"2022-02-15T15:41:14.556107Z","shell.execute_reply.started":"2022-02-15T15:41:13.980793Z","shell.execute_reply":"2022-02-15T15:41:14.555177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_images(nrows,ncols,data):\n    figure, axs= plt.subplots(nrows,ncols,figsize=(16,8))\n    for i,ax in enumerate(axs.ravel()):\n        img=cv2.imread(data[i])\n        img=cv2.resize(img,(300,300))\n        img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)\n        ax.imshow(img,interpolation=None)\n        plt.tight_layout()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:42:35.265707Z","iopub.execute_input":"2022-02-15T15:42:35.266474Z","iopub.status.idle":"2022-02-15T15:42:35.274748Z","shell.execute_reply.started":"2022-02-15T15:42:35.266415Z","shell.execute_reply":"2022-02-15T15:42:35.273443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Display train images\nshow_images(5,3,img_path_train)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:42:37.239342Z","iopub.execute_input":"2022-02-15T15:42:37.239642Z","iopub.status.idle":"2022-02-15T15:42:44.033960Z","shell.execute_reply.started":"2022-02-15T15:42:37.239611Z","shell.execute_reply":"2022-02-15T15:42:44.033008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Display test images\nshow_images(5,3,img_path_test)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T15:42:54.890917Z","iopub.execute_input":"2022-02-15T15:42:54.891380Z","iopub.status.idle":"2022-02-15T15:43:01.050967Z","shell.execute_reply.started":"2022-02-15T15:42:54.891333Z","shell.execute_reply":"2022-02-15T15:43:01.050045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<center><h1 style=\"color:green;\">Work in Progress</h1></center>","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}