{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","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 in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Modify the dev set evaluation code to get the true indices of your predictions "},{"metadata":{},"cell_type":"markdown","source":"That is our dictionary called : true_idx_2_shuffled_idx"},{"metadata":{"trusted":true},"cell_type":"code","source":"from collections import defaultdict\nbad_pos_to_indices= defaultdict(list)\ntrue_idx_2_shuffled_idx = {}\ndev_scores = []\ndev_pos_list = []\nfor i in range(num_dev):\n    pred_dist_idx = list(np.argsort(dev_final_combined[i]))\n    dev_pos = pred_dist_idx.index(i)\n    dev_pos_list.append(dev_pos)\n    if dev_pos < 20:\n        dev_scores.append(1 / (dev_pos + 1))\n\n    else:\n        dev_scores.append(0.0)\n        bad_pos_to_indices[dev_pos].append(dev_indexes[i])\n        true_idx_2_shuffled_idx[dev_indexes[i]] = i\n\nprint(\"Development MAP@20:\", np.mean(dev_scores))\nprint(\"Mean index of true image\", np.mean(dev_pos_list))\nprint(\"Median index of true image\", np.median(dev_pos_list))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"bad_pos_to_indices tracks images that were predicted poorly"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","collapsed":true,"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":false},"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\ncheck_index= 1377 # chech this index from bad_pos_to_indices \nimg = mpimg.imread('/kaggle/input/cs5785-fall-2019-final/images_train/{}.jpg'.format(check_index))\nimgplot = plt.imshow(img)\nplt.show()\nprint(\"-------------------------\")\nprint(\"Real Tags\")\nprint(train_dev_tags[check_index])\n\npredicted_tag_index= true_idx_2_shuffled_idx[check_index]\nprint(\"-------------------------\")\nprint(\"Predicted Tags\")\nfor index, val in enumerate(tag_pred_dev[predicted_tag_index]):\n    if val == 1:\n        print(idx2tags[index])\nprint(\"-------------------------\")\nprint(\"Real Description\")\nprint(train_dev_desc[check_index])","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":1}