{"cells":[{"metadata":{},"cell_type":"markdown","source":"As I desperate to make a little tiny improvement in public leaderboard, it comes to my mind that I should check how is my poor model actually doing. My model's accuracy is about 0.87-0.88. After training, I ran it on the whole training set and saved result in \"erroran-2.csv\". "},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nimport matplotlib.pyplot as plt\nfrom PIL import Image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"compare_df = pd.read_csv(\"../input/errorfortrain/erroran-2.csv\",index_col=[0])\ncompare_df","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"\"label\" is ground truth from \"train.csv\". \"p_label\" and \"prob\" is predicted by my model."},{"metadata":{"trusted":true},"cell_type":"code","source":"error_df = compare_df[compare_df['label']!=compare_df['p_label']]\ncorrect_df = compare_df[compare_df['label']==compare_df['p_label']]\nerror_df","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Error rate is 0.12. Let's focus on \"Healthy\" class where my model disagrees with ground truth."},{"metadata":{"trusted":true},"cell_type":"code","source":"error_4_x = error_df[error_df['label']==4]\nerror_4_x","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def show_image(image_ids, labels, plabels):\n    plt.figure(figsize=(16, 12))\n    for ind, (image_id, label, plabel) in enumerate(zip(image_ids, labels, plabels)):\n        plt.subplot(3, 3, ind + 1)\n        image = Image.open(os.path.join('../input/cassava-leaf-disease-classification/train_images',image_id))\n        plt.imshow(image)\n        plt.title(f\"Class: {label} - Predict: {plabel}\", fontsize=12)\n        plt.axis(\"off\")\n    plt.show()\n    \ndef show_batch(batch_index, df):\n    image_ids = df[9*batch_index:9*(batch_index+1)][\"image_id\"].values\n    labels = df[9*batch_index:9*(batch_index+1)][\"label\"].values\n    plabels = df[9*batch_index:9*(batch_index+1)][\"p_label\"].values\n    show_image(image_ids, labels, plabels)\n    \ndef show_one_inbatch(batch_index, i,df):\n    image_id = df['image_id'].values[9*batch_index+i]\n    image = Image.open(os.path.join('../input/cassava-leaf-disease-classification/train_images',image_id))\n    plt.figure(figsize=(10, 10))\n    plt.imshow(image)\n    plt.title(df[df['image_id']==image_id]['prob'].values[0], fontsize=18)\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"show_batch(0,error_4_x)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Most of them don't look healthy."},{"metadata":{"trusted":true},"cell_type":"code","source":"show_one_inbatch(0, 0, error_4_x)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The first one should be classified as \"Cassava Bacterial Blight(CBB)\" as my model suggests. Let's look at ones wrongfully predicted as healthy."},{"metadata":{"trusted":true},"cell_type":"code","source":"error_x_4 = error_df[error_df['p_label']==4]\nshow_batch(0,error_x_4)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"show_one_inbatch(0, 4, error_x_4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Though predicted as healthy, the probability for CBB is 0.27, only 0.02 less than healthy. So I think maybe my model isn't that bad. Looking at how model actually performs does cheer me up. You should try it too. Thanks for your time."}],"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}