{"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 pandas as pd\nimport cv2\nimport os\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport tensorflow_hub as hub\nimport seaborn as sns\n    \nkeras_layer = hub.KerasLayer('https://kaggle.com/models/tensorflow/resnet-50/frameworks/TensorFlow2/variations/classification/versions/1')\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-08T18:10:40.819921Z","iopub.execute_input":"2023-03-08T18:10:40.820306Z","iopub.status.idle":"2023-03-08T18:11:01.580523Z","shell.execute_reply.started":"2023-03-08T18:10:40.820271Z","shell.execute_reply":"2023-03-08T18:11:01.579326Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020 = pd.read_csv(\"/kaggle/input/siim-isic-melanoma-classification/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.583283Z","iopub.execute_input":"2023-03-08T18:11:01.584093Z","iopub.status.idle":"2023-03-08T18:11:01.676019Z","shell.execute_reply.started":"2023-03-08T18:11:01.584035Z","shell.execute_reply":"2023-03-08T18:11:01.674814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.677351Z","iopub.execute_input":"2023-03-08T18:11:01.677817Z","iopub.status.idle":"2023-03-08T18:11:01.711147Z","shell.execute_reply.started":"2023-03-08T18:11:01.677772Z","shell.execute_reply":"2023-03-08T18:11:01.709896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020.count()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.712747Z","iopub.execute_input":"2023-03-08T18:11:01.713497Z","iopub.status.idle":"2023-03-08T18:11:01.738238Z","shell.execute_reply.started":"2023-03-08T18:11:01.713430Z","shell.execute_reply":"2023-03-08T18:11:01.736790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020.drop([ 'benign_malignant'], inplace=True , axis = 1)","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.741815Z","iopub.execute_input":"2023-03-08T18:11:01.742543Z","iopub.status.idle":"2023-03-08T18:11:01.751432Z","shell.execute_reply.started":"2023-03-08T18:11:01.742495Z","shell.execute_reply":"2023-03-08T18:11:01.750220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.753570Z","iopub.execute_input":"2023-03-08T18:11:01.753894Z","iopub.status.idle":"2023-03-08T18:11:01.771288Z","shell.execute_reply.started":"2023-03-08T18:11:01.753862Z","shell.execute_reply":"2023-03-08T18:11:01.770129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020 = df_2020.replace({\n    'diagnosis': {\n        'unknown': 'UNK',\n        'nevus': 'NV',\n        'melanoma': 'MEL',\n        'seborrheic keratosis': 'BKL',\n        'lentigo NOS': 'BKL',\n        'lichenoid keratosis': 'BKL',\n        'solar lentigo': 'BKL',\n        'cafe-au-lait macule': 'UNK',\n        'atypical melanocytic proliferation': 'UNK'\n    }\n})","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.772625Z","iopub.execute_input":"2023-03-08T18:11:01.772983Z","iopub.status.idle":"2023-03-08T18:11:01.800720Z","shell.execute_reply.started":"2023-03-08T18:11:01.772948Z","shell.execute_reply":"2023-03-08T18:11:01.799454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020.head(9)","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.802264Z","iopub.execute_input":"2023-03-08T18:11:01.802634Z","iopub.status.idle":"2023-03-08T18:11:01.819465Z","shell.execute_reply.started":"2023-03-08T18:11:01.802597Z","shell.execute_reply":"2023-03-08T18:11:01.818255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020 = df_2020.rename(columns= {\n    'anatom_site_general_challenge': 'anatom_site_general',\n    'image_name': 'image',\n})\n","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.820864Z","iopub.execute_input":"2023-03-08T18:11:01.821187Z","iopub.status.idle":"2023-03-08T18:11:01.828753Z","shell.execute_reply.started":"2023-03-08T18:11:01.821157Z","shell.execute_reply":"2023-03-08T18:11:01.827806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020.head()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.830109Z","iopub.execute_input":"2023-03-08T18:11:01.830432Z","iopub.status.idle":"2023-03-08T18:11:01.848701Z","shell.execute_reply.started":"2023-03-08T18:11:01.830401Z","shell.execute_reply":"2023-03-08T18:11:01.847362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_csv(\"/kaggle/input/siim-isic-melanoma-classification/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.850528Z","iopub.execute_input":"2023-03-08T18:11:01.850859Z","iopub.status.idle":"2023-03-08T18:11:01.884365Z","shell.execute_reply.started":"2023-03-08T18:11:01.850828Z","shell.execute_reply":"2023-03-08T18:11:01.883129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.head(8)","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.885886Z","iopub.execute_input":"2023-03-08T18:11:01.886325Z","iopub.status.idle":"2023-03-08T18:11:01.900955Z","shell.execute_reply.started":"2023-03-08T18:11:01.886287Z","shell.execute_reply":"2023-03-08T18:11:01.899982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = df_test.rename(columns= {\n    'anatom_site_general_challenge': 'anatom_site_general',\n    'image_name': 'image',\n})\n","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.902316Z","iopub.execute_input":"2023-03-08T18:11:01.903147Z","iopub.status.idle":"2023-03-08T18:11:01.912723Z","shell.execute_reply.started":"2023-03-08T18:11:01.903096Z","shell.execute_reply":"2023-03-08T18:11:01.911577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.head(8)","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.918964Z","iopub.execute_input":"2023-03-08T18:11:01.919355Z","iopub.status.idle":"2023-03-08T18:11:01.934878Z","shell.execute_reply.started":"2023-03-08T18:11:01.919310Z","shell.execute_reply":"2023-03-08T18:11:01.933582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020.diagnosis.unique()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.936406Z","iopub.execute_input":"2023-03-08T18:11:01.936883Z","iopub.status.idle":"2023-03-08T18:11:01.951774Z","shell.execute_reply.started":"2023-03-08T18:11:01.936824Z","shell.execute_reply":"2023-03-08T18:11:01.950557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020.shape","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.953503Z","iopub.execute_input":"2023-03-08T18:11:01.953894Z","iopub.status.idle":"2023-03-08T18:11:01.963531Z","shell.execute_reply.started":"2023-03-08T18:11:01.953861Z","shell.execute_reply":"2023-03-08T18:11:01.962277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020[['anatom_site_general', 'sex']] = df_2020[['anatom_site_general', 'sex']].fillna(value = 'unknown')\ndf_2020['age_approx'] = df_2020['age_approx'].fillna(value = 50)\n\ndf_test['anatom_site_general'] = df_test['anatom_site_general'].fillna(value = 'unknown')","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.964598Z","iopub.execute_input":"2023-03-08T18:11:01.965381Z","iopub.status.idle":"2023-03-08T18:11:01.983189Z","shell.execute_reply.started":"2023-03-08T18:11:01.965342Z","shell.execute_reply":"2023-03-08T18:11:01.981860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:01.984690Z","iopub.execute_input":"2023-03-08T18:11:01.985845Z","iopub.status.idle":"2023-03-08T18:11:01.999374Z","shell.execute_reply.started":"2023-03-08T18:11:01.985795Z","shell.execute_reply":"2023-03-08T18:11:01.998078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_2020.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:02.001002Z","iopub.execute_input":"2023-03-08T18:11:02.002001Z","iopub.status.idle":"2023-03-08T18:11:02.019332Z","shell.execute_reply.started":"2023-03-08T18:11:02.001962Z","shell.execute_reply":"2023-03-08T18:11:02.018213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Dataset\")\nprint(df_test.shape)\nprint(df_2020.shape)\nprint('\\n')","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:02.021433Z","iopub.execute_input":"2023-03-08T18:11:02.021885Z","iopub.status.idle":"2023-03-08T18:11:02.029132Z","shell.execute_reply.started":"2023-03-08T18:11:02.021852Z","shell.execute_reply":"2023-03-08T18:11:02.027889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"files = [df_2020,df_test]\nfor dff in files:\n    print(dff.info())\n    print('\\n')","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:02.030693Z","iopub.execute_input":"2023-03-08T18:11:02.031468Z","iopub.status.idle":"2023-03-08T18:11:02.068183Z","shell.execute_reply.started":"2023-03-08T18:11:02.031420Z","shell.execute_reply":"2023-03-08T18:11:02.067304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Train set 2020 RAW missing values')\ndisplay(pd.DataFrame(df_2020.isnull().sum(), columns=['Null count']))\nprint('Test set 2020 RAW missing values')\ndisplay(pd.DataFrame(df_test.isnull().sum(), columns=['Null count']))","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:27.550723Z","iopub.execute_input":"2023-03-08T18:11:27.551116Z","iopub.status.idle":"2023-03-08T18:11:27.583185Z","shell.execute_reply.started":"2023-03-08T18:11:27.551082Z","shell.execute_reply":"2023-03-08T18:11:27.581817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax1 = sns.countplot(data=df_2020, x='anatom_site_general')\nax1.set_title('Distribution of Anatomical Sites Training Set')\nax1.tick_params(axis='x', labelrotation = 45, labelsize = 12)\n","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:38.361059Z","iopub.execute_input":"2023-03-08T18:11:38.361614Z","iopub.status.idle":"2023-03-08T18:11:38.723426Z","shell.execute_reply.started":"2023-03-08T18:11:38.361560Z","shell.execute_reply":"2023-03-08T18:11:38.722552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"z=df_2020.groupby(['sex','age_approx'])['anatom_site_general'].count().to_frame().reset_index()\nz.style.background_gradient(cmap='Reds')  ","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:43.190652Z","iopub.execute_input":"2023-03-08T18:11:43.191050Z","iopub.status.idle":"2023-03-08T18:11:43.299570Z","shell.execute_reply.started":"2023-03-08T18:11:43.191015Z","shell.execute_reply":"2023-03-08T18:11:43.298582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = sns.catplot(x=\"diagnosis\",y=\"age_approx\",data=df_2020,kind='bar')","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:49.570739Z","iopub.execute_input":"2023-03-08T18:11:49.571426Z","iopub.status.idle":"2023-03-08T18:11:50.231893Z","shell.execute_reply.started":"2023-03-08T18:11:49.571384Z","shell.execute_reply":"2023-03-08T18:11:50.230707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = sns.countplot(y=\"diagnosis\",data=df_2020)","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:53.479099Z","iopub.execute_input":"2023-03-08T18:11:53.479591Z","iopub.status.idle":"2023-03-08T18:11:53.647519Z","shell.execute_reply.started":"2023-03-08T18:11:53.479548Z","shell.execute_reply":"2023-03-08T18:11:53.646163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax2 = sns.countplot(data=df_2020, x='sex')\nax2.set_title('Distribution of Gender')","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:11:56.539056Z","iopub.execute_input":"2023-03-08T18:11:56.539727Z","iopub.status.idle":"2023-03-08T18:11:56.773956Z","shell.execute_reply.started":"2023-03-08T18:11:56.539670Z","shell.execute_reply":"2023-03-08T18:11:56.772960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"individuals_count = df_2020.groupby('patient_id').count()\n\nindividuals_count.head()\n","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:12:01.753100Z","iopub.execute_input":"2023-03-08T18:12:01.753551Z","iopub.status.idle":"2023-03-08T18:12:01.783740Z","shell.execute_reply.started":"2023-03-08T18:12:01.753506Z","shell.execute_reply":"2023-03-08T18:12:01.782564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('the mean number of images per patient is: {}'.format(round(individuals_count.image.mean(),2)))\nprint('the median number of images per patient is: {}'.format(round(individuals_count.image.median(),2)))\nprint('the standard deviation of the number of images per patient is: {}'.format(round(individuals_count.image.std(),2)))","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:12:04.815605Z","iopub.execute_input":"2023-03-08T18:12:04.816009Z","iopub.status.idle":"2023-03-08T18:12:04.825034Z","shell.execute_reply.started":"2023-03-08T18:12:04.815972Z","shell.execute_reply":"2023-03-08T18:12:04.823908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import imageio.v2 as imageio\n\n#load an image\nim = imageio.imread('../input/siim-isic-melanoma-classification/jpeg/train/ISIC_0015719.jpg')\n\n#plot image\nplt.imshow(im)\nplt.axis('off')\n#plt.show()\n\n#print metadata\nprint(im.meta.keys())","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:13:36.861420Z","iopub.execute_input":"2023-03-08T18:13:36.861850Z","iopub.status.idle":"2023-03-08T18:13:42.711737Z","shell.execute_reply.started":"2023-03-08T18:13:36.861812Z","shell.execute_reply":"2023-03-08T18:13:42.710562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mal_ims = df_2020[df_2020['target']==1].image","metadata":{"execution":{"iopub.status.busy":"2023-03-08T18:13:31.569618Z","iopub.execute_input":"2023-03-08T18:13:31.570018Z","iopub.status.idle":"2023-03-08T18:13:31.577246Z","shell.execute_reply.started":"2023-03-08T18:13:31.569983Z","shell.execute_reply":"2023-03-08T18:13:31.576211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}