{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport ast\n\nimport pandas as pd\nimport numpy as np\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as ex\nfrom matplotlib_venn import venn2,venn3\n\n\nimport torch \nimport torch.nn as nn\nimport cv2","metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2 style=\"color:purple\"> \nall the columns details\n</h2>\n\nStudyInstanceUID - unique ID for each image\n\nETT - Abnormal - endotracheal tube placement abnormal\n\nETT - Borderline - endotracheal tube placement borderline abnormal\n\nETT - Normal - endotracheal tube placement normal\n\nNGT - Abnormal - nasogastric tube placement abnormal\n\nNGT - Borderline - nasogastric tube placement borderline abnormal\n\nNGT - Incompletely Imaged - nasogastric tube placement inconclusive due to imaging\n\nNGT - Normal - nasogastric tube placement borderline normal\n\nCVC - Abnormal - central venous catheter placement abnormal\n\nCVC - Borderline - central venous catheter placement borderline abnormal\n\nCVC - Normal - central venous catheter placement normal\n\nSwan Ganz Catheter Present\n\nPatientID - unique ID for each patient in the dataset","metadata":{}},{"cell_type":"code","source":"DIR = '../input/ranzcr-clip-catheter-line-classification'\nos.listdir(DIR)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv(os.path.join(DIR,'train.csv'))\ndf_train.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plot1 = df_train.iloc[:, 1:-1]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plot1.dtypes","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in df_plot1.columns:\n    if df_plot1[col].dtype== int :\n        df_plot1.hist(col,color= '#008294')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 8))\ndf_plot2 = df_train.iloc[:, 1:-1].sum()\nsns.barplot(x=df_plot2.values, y=df_plot2.index,color='#008294')\nplt.xticks(fontsize=14)\nplt.yticks(fontsize=14)\nplt.xlabel(\"Number of images\", fontsize=15)\nplt.title(\"Distribution of labels\", fontsize=16);","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plot2 = pd.DataFrame(df_plot2)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# the data represents the coordinates of the pipe in the body\ndf_annot = pd.read_csv(os.path.join(DIR,'train_annotations.csv'))\ndf_annot.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def label_plotting(name):\n    # we take first occurence of every label and not random numbers \n    row = df_annot.loc[df_annot['label']== name,:].iloc[0,:]\n    image_path = os.path.join(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    image = cv2.imread(image_path)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.subplot(1, 2, 1)\n    plt.imshow(image)\n    plt.subplot(1, 2, 2)\n    plt.imshow(image)\n    plt.scatter(data[:, 0], data[:, 1])\n    \n    plt.suptitle(label, fontsize=15)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_plotting('CVC - Borderline')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_plotting('NGT - Borderline')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_plotting('CVC - Abnormal')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_plotting('NGT - Abnormal')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_plotting('ETT - Abnormal')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_plotting('CVC - Normal')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_plotting('NGT - Normal')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_plotting('ETT - Borderline')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_plotting('ETT - Normal')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# lets see the commonness between the columns in the data \n\ndef venn2_drawer(col1,col2):\n    venn2(subsets=\n          #area1\n          (df_train[col1].sum(),\n           #area2\n           df_train[col2].sum(),\n           #common area\n           df_train[(df_train[col2]==1)&(df_train[col1]==1)].shape[0]),\n          set_colors='bg',normalize_to=1,alpha=0.3,\n          set_labels=(col1,col2))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"venn2_drawer('ETT - Abnormal','NGT - Abnormal')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_venn3(col_1, col_2, col_3):\n    plt.figure(figsize=(6, 6))\n    \n    area_100 = df_train[col_1].sum()\n    area_010 = df_train[col_2].sum()\n    area_110 = df_train[(df_train[col_1] == 1) & (df_train[col_2] == 1)].shape[0]\n    area_001 = df_train[col_3].sum()\n    area_101 = df_train[(df_train[col_1] == 1) & (df_train[col_3] == 1)].shape[0]\n    area_011 = df_train[(df_train[col_2] == 1) & (df_train[col_3] == 1)].shape[0]\n    area_111 = df_train[(df_train[col_1] == 1) & (df_train[col_2] == 1) & (df_train[col_3] == 1)].shape[0]\n\n#     print(area_100, area_010, area_110, area_001, area_101, area_011, area_111)\n\n    venn3(\n        subsets=(area_100, area_010, area_110, area_001, area_101, area_011, area_111), \n        set_labels=(col_1, col_2, col_3), set_colors='ybg',\n        alpha=0.3\n    );\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_venn3(\n    \"ETT - Abnormal\",\n    \"NGT - Abnormal\",\n    \"CVC - Abnormal\",\n)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_venn3(\n    \"ETT - Normal\",\n    \"NGT - Normal\",\n    \"CVC - Normal\",\n)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_venn3(\n    \"ETT - Borderline\",\n    \"NGT - Borderline\",\n    \"CVC - Borderline\",\n)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_annot","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}