{"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":"!cp /kaggle/input/gdcm-conda-install/gdcm.tar .\n!tar -xvzf gdcm.tar\n!conda install --offline ./gdcm/gdcm-2.8.9-py37h71b2a6d_0.tar.bz2\n!rm -rf ./gdcm.tar","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:26:45.874222Z","iopub.execute_input":"2022-12-01T14:26:45.874851Z","iopub.status.idle":"2022-12-01T14:27:10.869827Z","shell.execute_reply.started":"2022-12-01T14:26:45.874721Z","shell.execute_reply":"2022-12-01T14:27:10.868466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport pydicom as pydm\nimport gdcm","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-01T14:27:10.874008Z","iopub.execute_input":"2022-12-01T14:27:10.874566Z","iopub.status.idle":"2022-12-01T14:27:11.707767Z","shell.execute_reply.started":"2022-12-01T14:27:10.874512Z","shell.execute_reply":"2022-12-01T14:27:11.706394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images_path='/kaggle/input/rsna-breast-cancer-detection/train_images'\ntest_images_path='/kaggle/input/rsna-breast-cancer-detection/test_images'\n\ntrain_df=pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/train.csv')\ntrain_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:27:11.71011Z","iopub.execute_input":"2022-12-01T14:27:11.71077Z","iopub.status.idle":"2022-12-01T14:27:11.841208Z","shell.execute_reply.started":"2022-12-01T14:27:11.710732Z","shell.execute_reply":"2022-12-01T14:27:11.839857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Lets have a look at records\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:27:11.844548Z","iopub.execute_input":"2022-12-01T14:27:11.845163Z","iopub.status.idle":"2022-12-01T14:27:11.868799Z","shell.execute_reply.started":"2022-12-01T14:27:11.845114Z","shell.execute_reply":"2022-12-01T14:27:11.867505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Add one more column which will contain path of images\ntrain_df['path_image']=[os.path.join(train_images_path,str(train_df.loc[ix,'patient_id']),\n                                     str(train_df.loc[ix,'image_id'])+'.dcm') \n                       for ix in range(train_df.shape[0])]\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:27:11.870044Z","iopub.execute_input":"2022-12-01T14:27:11.870395Z","iopub.status.idle":"2022-12-01T14:27:13.295399Z","shell.execute_reply.started":"2022-12-01T14:27:11.870353Z","shell.execute_reply":"2022-12-01T14:27:13.293975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Column names: ',list(train_df.columns))\nprint('Total unique patientids: {}'.format(train_df['patient_id'].nunique()))\nprint('Total unique imageids: {}'.format(train_df['image_id'].nunique()))\nprint('Average image per patient: {}'.format(np.round((train_df['image_id'].nunique()/train_df['patient_id'].nunique()))))","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:27:13.297003Z","iopub.execute_input":"2022-12-01T14:27:13.297456Z","iopub.status.idle":"2022-12-01T14:27:13.316551Z","shell.execute_reply.started":"2022-12-01T14:27:13.297419Z","shell.execute_reply":"2022-12-01T14:27:13.315384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Target Column Distribution\nsns.displot(train_df['cancer'])\nvalue_count_target=train_df['cancer'].value_counts()\nprint('Images with Cancer: {}'.format(value_count_target[1]))\nprint('Images without Cancer: {}'.format(value_count_target[0]))\nprint('Percentage of Images with Cancer: {:.1f}%'.format((value_count_target[1]/train_df.shape[0])*100))","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:27:13.318328Z","iopub.execute_input":"2022-12-01T14:27:13.318637Z","iopub.status.idle":"2022-12-01T14:27:13.733691Z","shell.execute_reply.started":"2022-12-01T14:27:13.318609Z","shell.execute_reply":"2022-12-01T14:27:13.732466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rest_of_cols=['laterality', 'view', 'cancer', 'biopsy', 'invasive',\n'BIRADS', 'implant', 'density', 'difficult_negative_case']\nprint('Unique values in rest of the columns')\nfor col in rest_of_cols:\n    print(col+':',train_df[col].unique())\n    print()","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:27:13.735668Z","iopub.execute_input":"2022-12-01T14:27:13.73614Z","iopub.status.idle":"2022-12-01T14:27:13.759792Z","shell.execute_reply.started":"2022-12-01T14:27:13.736095Z","shell.execute_reply":"2022-12-01T14:27:13.758061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Count of NaNs in each column')\ntrain_df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:27:13.761674Z","iopub.execute_input":"2022-12-01T14:27:13.762163Z","iopub.status.idle":"2022-12-01T14:27:13.788466Z","shell.execute_reply.started":"2022-12-01T14:27:13.762117Z","shell.execute_reply":"2022-12-01T14:27:13.787195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Lets Look at some cancer infected images\ndf_subset=train_df[train_df['cancer']==1].reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:27:13.792576Z","iopub.execute_input":"2022-12-01T14:27:13.793062Z","iopub.status.idle":"2022-12-01T14:27:13.807816Z","shell.execute_reply.started":"2022-12-01T14:27:13.793023Z","shell.execute_reply":"2022-12-01T14:27:13.806602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Images with cancer')\nr=c=3\nfig=plt.figure(figsize=(20,20))\n\nfor i in range(1,r*c+1):\n    img=df_subset.loc[i,'path_image']\n    img=pydm.read_file(img).pixel_array\n    fig.add_subplot(r,c,i)\n    plt.imshow(img,cmap='bone')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:27:13.809176Z","iopub.execute_input":"2022-12-01T14:27:13.809505Z","iopub.status.idle":"2022-12-01T14:27:42.181101Z","shell.execute_reply.started":"2022-12-01T14:27:13.809475Z","shell.execute_reply":"2022-12-01T14:27:42.179929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Images without cancer')\nr=c=3\nfig=plt.figure(figsize=(20,20))\n\ndf_subset=train_df[train_df['cancer']==0].reset_index(drop=True)\n\nfor i in range(1,r*c+1):\n    img=df_subset.loc[i,'path_image']\n    img=pydm.read_file(img).pixel_array\n    fig.add_subplot(r,c,i)\n    plt.imshow(img,cmap='bone')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:27:42.18271Z","iopub.execute_input":"2022-12-01T14:27:42.183148Z","iopub.status.idle":"2022-12-01T14:28:10.063245Z","shell.execute_reply.started":"2022-12-01T14:27:42.183106Z","shell.execute_reply":"2022-12-01T14:28:10.061927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_subset=train_df[train_df['age'].notna()]\n\ngraph=sns.FacetGrid(data=df_subset,col='implant',row='cancer',height=5,aspect=1.1)\ngraph.map_dataframe(sns.histplot,x='age')","metadata":{"execution":{"iopub.status.busy":"2022-12-01T14:28:10.065159Z","iopub.execute_input":"2022-12-01T14:28:10.066157Z","iopub.status.idle":"2022-12-01T14:28:11.247367Z","shell.execute_reply.started":"2022-12-01T14:28:10.066112Z","shell.execute_reply":"2022-12-01T14:28:11.246262Z"},"trusted":true},"execution_count":null,"outputs":[]}]}