{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"!pip install plotly==4.8.0","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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)\nfrom sklearn.metrics import roc_auc_score\nimport matplotlib.pyplot as plt\nimport pydicom\nimport os","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train = pd.read_csv('../input/siim-isic-melanoma-classification/train.csv')\ntest  = pd.read_csv('../input/siim-isic-melanoma-classification/test.csv')\nsub   = pd.read_csv('../input/siim-isic-melanoma-classification/sample_submission.csv')\n\nprint(f\"train.shape: {train.shape}\")\nprint(f\"test.shape: {test.shape}\")\nprint(f\"sub.shape: {sub.shape}\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train['sex'] = train['sex'].fillna('na')\ntrain['age_approx'] = train['age_approx'].fillna(0)\ntrain['anatom_site_general_challenge'] = train['anatom_site_general_challenge'].fillna('na')\n\ntest['sex'] = test['sex'].fillna('na')\ntest['age_approx'] = test['age_approx'].fillna(0)\ntest['anatom_site_general_challenge'] = test['anatom_site_general_challenge'].fillna('na')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(f\"total train patient: {len(train.patient_id.value_counts())}\")\nprint(f\"total test patient: {len(test.patient_id.value_counts())}\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.groupby(['benign_malignant']).count()['sex'].to_frame()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"duplicate= []\nfor i in train.patient_id.unique():\n    if i in test.patient_id.unique():\n        print(i)\n        duplicate.append(i)\nif len(duplicate) == 0:\n    print(\"No patient at train and test dataset in the same time\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Train Set')\nprint(train.info())\nprint('\\n')\nprint(' - '*30)\nprint('\\n')\nprint('Test Set')\nprint(test.info())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"L = 15\nfeat = ['sex','age_approx','anatom_site_general_challenge']\n\nM = train.target.mean()\nte = train.groupby(feat)['target'].agg(['mean','count']).reset_index()\nte['ll'] = ((te['mean']*te['count'])+(M*L))/(te['count']+L)\ndel te['mean'], te['count']\n\ntest = test.merge( te, on=feat, how='left' )\ntest['ll'] = test['ll'].fillna(M)\n\ntest.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.target = test.ll.values\nsub.head(10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import plotly.express as px\nfig = px.histogram(train, x=\"age_approx\", color=\"sex\", marginal=\"box\",  hover_data=train.columns) # marginal=\"rug\",  `box`, `violin`\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import plotly.express as px\nfig = px.histogram(train, x=\"age_approx\", color=\"sex\", marginal=\"box\",  hover_data=train.columns) # marginal=\"rug\",  `box`, `violin`\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train['anatom_site_general_challenge'].value_counts(normalize=True).sort_values()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.diagnosis.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import plotly.graph_objects as go\n\nlabels = []\nvalues = []\n\nfor k, v in train.diagnosis.value_counts().items():\n    print(k, v)\n    labels.append(k)\n    values.append(v)\n\nfig = go.Figure(data=[go.Pie(labels=labels, values=values)])\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sample = train.sample(1, random_state=777)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dcm = pydicom.dcmread(f'../input/siim-isic-melanoma-classification/train/{sample.image_name[25417]}.dcm')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dcm","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.imshow(pydicom.dcmread(f'../input/siim-isic-melanoma-classification/train/{sample.image_name[25417]}.dcm').pixel_array)","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}