{"cells":[{"metadata":{},"cell_type":"markdown","source":"## Abnormal ETT - are they labelled correctly?\n\nAs there are only 30 `ETT - Abnormal` cases for which we annotations - let's visualize all and decide if all of them are correctly labelled.\n\nIf there are at least one wrong label, it could have huge impact on AUC scores for `ETT - Abnormal` class"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import ast\nimport numpy as np\nimport pandas as pd\nimport cv2\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\ntrain = pd.read_csv('../input/ranzcr-clip-catheter-line-classification/train.csv')\nann = pd.read_csv('../input/ranzcr-clip-catheter-line-classification/train_annotations.csv')\nann = ann.loc[ann.label == 'ETT - Abnormal']\nprint(ann.shape)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"def plot_xray(StudyInstanceUID):\n    \"\"\"\n    intubation points as green\n    \"\"\"\n    img = cv2.imread('../input/ranzcr-clip-catheter-line-classification/train/'+StudyInstanceUID+'.jpg')\n    intubation = ast.literal_eval(ann.loc[(ann.StudyInstanceUID==StudyInstanceUID),'data'].values[0])\n    for point in intubation:\n        img = cv2.circle(img, tuple(point), 10, (0,255,0), 10)\n    plt.figure(figsize=(8,8))\n    print(f'StudyInstanceUID {StudyInstanceUID}')\n    plt.imshow(img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"First train instance seems to be ok:"},{"metadata":{"trusted":true},"cell_type":"code","source":"plot_xray(ann.StudyInstanceUID[ann.index[0]])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"However, the very second instance is not ok! it should be labelled as CVC - Abnormal!"},{"metadata":{"trusted":true},"cell_type":"code","source":"plot_xray(ann.StudyInstanceUID[ann.index[1]])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"I looked through the rest of the cases - all other 28 cases seem to be fine.\n\nSo, during loading train data make sure to correct the case above,\n\nthis should do the trick:\n\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"train.loc[train.StudyInstanceUID=='1.2.826.0.1.3680043.8.498.93345761486297843389996628528592497280', 'ETT - Abnormal'] = 0\ntrain.loc[train.StudyInstanceUID=='1.2.826.0.1.3680043.8.498.93345761486297843389996628528592497280', 'CVC - Abnormal'] = 1\nann.loc[4344, 'label'] = 'CVC - Abnormal'","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## To sum up\n\nTo have label errors within a category with low instance count is troublesome. Cleaning the data must be considered.\n\nI guess we could ask organizers to lookup if private dataset's `ETT - Abnormal` class is labelled correctly in all instances."}],"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}