{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport ast\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport cv2\nimport random\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Before starting there are some important terms\n\n- ETT Abnormal (endotracheal tube placement abnormal)\n- ETT Borderline (endotracheal tube placement borderline abnormal)\n- ETT Normal (endotracheal tube placement normal)\n- NGT Abnormal (nasogastric tube placement abnormal)\n- NGT Borderline (nasogastric tube placement borderline abnormal)\n- NGT Incompletely Imaged (nasogastric tube placement inconclusive due to imaging)\n- NGT Normal (nasogastric tube placement borderline normal)\n- CVC Abnormal (central venous catheter placement abnormal)\n- CVC Borderline (central venous catheter placement borderline abnormal)\n- CVC Normal (central venous catheter placement normal)\n- Swan Ganz Catheter Present"},{"metadata":{"trusted":true},"cell_type":"code","source":"BASE_DIR = \"../input/ranzcr-clip-catheter-line-classification\"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train = pd.read_csv(f\"{BASE_DIR}/train.csv\", index_col=0)\ntrain_annotations = pd.read_csv(f\"{BASE_DIR}/train_annotations.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.iloc[:, :-1].sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def display_image(img_ids):\n    plt.figure(figsize=(14, 10))\n    \n    for index, img_id in enumerate(img_ids):\n        plt.subplot(3, 4, index + 1)\n        img = cv2.imread(os.path.join(BASE_DIR, \"train\", f\"{img_id}.jpg\"))\n        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n        plt.imshow(img)\n        plt.axis(\"off\")\n    \n    plt.show()\n    \n\ndef disp_describe(df, col):\n    print(\"Distribution:\")\n    print(df[col].value_counts())\n    print()\n    print(f\"Percent of 1: {df[col].mean():.4f}\")\n    \n\ndef disp_image_with_annotate(df, row_ind):\n    row = df.iloc[row_ind]\n    img_path = os.path.join(BASE_DIR, \"train\", row[\"StudyInstanceUID\"] + \".jpg\")\n    label = row[\"label\"]\n    data = np.array(ast.literal_eval(row[\"data\"]))\n    \n    plt.figure(figsize=(10, 5))\n    img = cv2.imread(img_path)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    plt.subplot(1, 2, 1)\n    plt.imshow(img)\n    plt.subplot(1, 2, 2)\n    plt.imshow(img)\n    plt.scatter(data[:, 0], data[:, 1])\n    \n    plt.suptitle(label, fontsize=14)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_annotations.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_annotations.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"disp_image_with_annotate(train_annotations, 10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for i in range(10):\n    disp_image_with_annotate(train_annotations, random.randint(0, 1500))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.columns","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### ETT Abnormal"},{"metadata":{"trusted":true},"cell_type":"code","source":"col_name = \"ETT - Abnormal\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### ETT Borderline"},{"metadata":{"trusted":true},"cell_type":"code","source":"col_name = \"ETT - Borderline\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### ETT Normal"},{"metadata":{"trusted":true},"cell_type":"code","source":"col_name = \"ETT - Normal\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### NGT Abnormal"},{"metadata":{"trusted":true},"cell_type":"code","source":"col_name = \"NGT - Abnormal\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### NGT Borderline"},{"metadata":{"trusted":true},"cell_type":"code","source":"col_name = \"NGT - Borderline\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### NGT Incompletely Imaged"},{"metadata":{"trusted":true},"cell_type":"code","source":"col_name = \"NGT - Incompletely Imaged\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### NGT Normal"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"col_name = \"NGT - Normal\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### CVC Abnormal"},{"metadata":{"trusted":true},"cell_type":"code","source":"col_name = \"CVC - Abnormal\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### CVC Borderline"},{"metadata":{"trusted":true},"cell_type":"code","source":"col_name = \"CVC - Borderline\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### CVC Normal"},{"metadata":{"trusted":true},"cell_type":"code","source":"col_name = \"CVC - Normal\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Swan Ganz Catheter Present"},{"metadata":{"trusted":true},"cell_type":"code","source":"col_name = \"Swan Ganz Catheter Present\"\ndisp_describe(train, col_name)\ntmp_df = train[train[col_name] == 1]\ndisplay_image(random.sample(tmp_df.index.tolist(), 12))","execution_count":null,"outputs":[]},{"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}