{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"markdown","source":"# Cassava Leaf Disease - Data Analysis\nIn Cassava Leaf disease competition, They provided dataset of 21,367 labeled images. Most images were crowdsourced from farmers taking photos of their gardens.\n\nUsing this dataset we are going to explore images and see insights of data to get better understanding of problem.\n\nIn this competition, We need to solve multi class classification problem where we need to classify plant image to any of 5 classes(4 diseases or healthy plant)."},{"metadata":{"trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport json\nfrom math import sqrt\nimport os","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"BASE_DIR = '/kaggle/input/cassava-leaf-disease-classification/'\ntrain_image_base_dir = BASE_DIR + 'train_images'\nfilenames = os.listdir(train_image_base_dir)\nprint(filenames[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# we will use it later\ndef plot_images(df, no_of_images):\n    \"\"\"\n    function that will plot images for visualisation\n    \"\"\"\n    \n    size = int(sqrt(no_of_images))\n    fig, axis = plt.subplots(size, size)\n    fig.set_figheight(15)\n    fig.set_figwidth(15)\n    for i in range(size * size):\n        image = plt.imread(os.path.join(train_image_base_dir, df.loc[i, 'image_id']))\n        axis[int(i/size)][int(i%size)].imshow(image)\n        axis[int(i/size)][int(i%size)].title.set_text(df.loc[i, 'image_id'])\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# General Visualization of Images"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_label_file_path = BASE_DIR + 'train.csv'\ntrain_df = pd.read_csv(train_label_file_path)\nprint(train_df.loc[0:8])\nprint('Total no of training Images: ', len(train_df))\nplot_images(train_df, no_of_images=9)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Multiclass classification based on 5 classes (4 diseases and healthy plant)"},{"metadata":{"trusted":true},"cell_type":"code","source":"with open(BASE_DIR + 'label_num_to_disease_map.json') as f:\n    label_mapping = json.load(f)\nprint(json.dumps(label_mapping, indent=4, sort_keys=True))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Images of leaves having Cassava Bacterial Blight(CBB) with label 0"},{"metadata":{"trusted":true},"cell_type":"code","source":"ccb_df = train_df[train_df['label'] == 0].reset_index()\nprint('No of Images of Cassava Bacterial Blight (CBB) in training set:', len(ccb_df))\nplot_images(ccb_df, no_of_images=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Images of leaves having Cassava Brown Streak Disease (CBSD) with label 1"},{"metadata":{"trusted":true},"cell_type":"code","source":"cbsd_df = train_df[train_df['label'] == 1].reset_index()\nprint('No of images of Cassava Brown Streak Disease (CBSD) for training:', len(cbsd_df))\nplot_images(cbsd_df, no_of_images=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Images of leaves having Cassava Green Mottle (CGM) with label 2"},{"metadata":{"trusted":true},"cell_type":"code","source":"cgm_df = train_df[train_df['label'] == 2].reset_index()\nprint('No of Images for Cassava Brown Streak Disease (CBSD) in training set:', len(cgm_df))\nplot_images(cgm_df, no_of_images=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Images of leaves having Cassava Mosaic Disease (CMD) with label 3"},{"metadata":{"trusted":true},"cell_type":"code","source":"cmd_df = train_df[train_df['label'] == 3].reset_index()\nprint('No of Images in Cassava Mosaic Disease (CMD) for training:', len(cmd_df))\nplot_images(cmd_df, no_of_images=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Images of healthy plants"},{"metadata":{"trusted":true},"cell_type":"code","source":"hp_df = train_df[train_df['label'] == 4].reset_index()\nprint('No of Images of Helthy plants:', len(hp_df))\nplot_images(hp_df, no_of_images=4)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots()\n\nN, bins, patches = ax.hist(train_df['label'], edgecolor='white', linewidth=1, color=['black'])\n\npatches[0].set_fc('black')\npatches[2].set_fc('red')\npatches[5].set_fc('grey')\npatches[7].set_facecolor('blue')\npatches[9].set_facecolor('green')\n\nplt.ylabel('no of examples')\nplt.xlabel('class')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## We can see problem of class imbalancing\n\n# WORK IN PROGRESS..."},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}