{"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\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pydicom\nimport os\nimport matplotlib.pyplot as plt\nfrom glob import glob\nfrom mpl_toolkits.mplot3d.art3d import Poly3DCollection\nimport scipy.ndimage\nfrom skimage import morphology\nfrom skimage import measure\nfrom skimage.transform import resize\nfrom sklearn.cluster import KMeans\nfrom plotly import __version__\nfrom plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot\nimport plotly.figure_factory as ff\nfrom plotly.graph_objs import *\ninit_notebook_mode(connected=True)\nimport pandas as pd\nfrom tqdm import tqdm\nimport seaborn as sns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train = pd.read_csv('/kaggle/input/rsna-str-pulmonary-embolism-detection/train.csv')\ndf_test = pd.read_csv('/kaggle/input/rsna-str-pulmonary-embolism-detection/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Plotting PE present on images')\nplt.hist(df_train['pe_present_on_image'])\nplt.xlabel('PE present or not')\nplt.ylabel('Number of patients with PE present')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# It is evident from the above image that the Classes for PE present or not is imbalanced"},{"metadata":{"trusted":true},"cell_type":"code","source":"df_test.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Number of Studies in the dataset', df_train['StudyInstanceUID'].nunique())\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Let's see how many series in each study**"},{"metadata":{"trusted":true},"cell_type":"code","source":"seriesIDs = []\nseriesIDs_lens = []\nstudyIDs = df_train['StudyInstanceUID'].unique()\nfor studyID in tqdm(studyIDs):\n    seriesIDs.append(df_train[df_train['StudyInstanceUID'] == studyID]['SeriesInstanceUID'].unique())\n    seriesIDs_lens.append(len(df_train[df_train['StudyInstanceUID'] == studyID]['SeriesInstanceUID'].unique()))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.bar(len(seriesIDs_lens),np.array(seriesIDs_lens))\nplt.xlabel('Studies')\nplt.ylabel('Series Length')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Let's find out how many images in each study"},{"metadata":{"trusted":true},"cell_type":"code","source":"SOPInstanceIDs = []\nSOPInstanceIDs_lens = []\nfor seriesID in tqdm(seriesIDs):\n    SOPInstanceIDs.append(df_train[df_train['SeriesInstanceUID'] == str(seriesID)[2:-2]]['SOPInstanceUID'].unique())\n    SOPInstanceIDs_lens.append(len(df_train[df_train['SeriesInstanceUID'] == str(seriesID)[2:-2]]['SOPInstanceUID'].unique()))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.hist(np.array(SOPInstanceIDs_lens))\nplt.xlabel('Series IDs')\nplt.ylabel('Number of images Length')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Columns in the Training Dataset : \\n',list(df_train))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_corr = df_train[['pe_present_on_image', 'negative_exam_for_pe', 'qa_motion', \n                    'qa_contrast', 'flow_artifact', 'rv_lv_ratio_gte_1', 'rv_lv_ratio_lt_1', \n                    'leftsided_pe', 'chronic_pe', 'true_filling_defect_not_pe', 'rightsided_pe', 'acute_and_chronic_pe', \n                    'central_pe', 'indeterminate']]\ndf_corr.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"corr = df_corr.corr()\nsns.heatmap(corr, \n        xticklabels=corr.columns,\n        yticklabels=corr.columns)\ncmap = cmap=sns.diverging_palette(5, 250, as_cmap=True)\ncorr.style.background_gradient(cmap, axis=1)\\\n    .set_properties(**{'max-width': '80px', 'font-size': '10pt'})\\\n    .set_caption(\"Hover to magify\")\\\n    .set_precision(2)\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Inference :\n\n1. Comparing Left, Right and Center with PE or not -- From the above correlation matrix it is evident that the column PE or Not is correlated with the following attributes in descending order - Left-sided > Right-sided > Center. "}],"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}