{"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\nfor 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","collapsed":true,"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":false},"cell_type":"markdown","source":"# Import the required libraries","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport os\nimport path\n\n# library used for plots\nimport seaborn as sns \n%matplotlib inline\nimport matplotlib.pyplot as plt\nplt.style.use('seaborn-white')\nimport numpy as np\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Set directory path and import data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"Path=\"../input/siim-isic-melanoma-classification/\"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Import the train and test csv files\nTrain_File= os.path.join(Path + 'train.csv')\nTest_File = os.path.join(Path + 'test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Create the DataFrame\nTrainFile_DF = pd.read_csv(Train_File)\nTestFile_DF = pd.read_csv(Test_File)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Check the Train Data\nTrainFile_DF.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Check the Test Data\nTestFile_DF.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Analysing the target variable w.r.t. age, sex and anatom_site","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"#### Check the missing values/ NaN values in the train dataset","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# Check if null values present in train data frame\nTrainFile_DF.isnull().values.any()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Check the count of null values present in train data frame\nTrainFile_DF.isnull().sum().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Number of nulls in Train Data set\nprint('Number of nulls in image_name column=', TrainFile_DF['image_name'].isnull().sum())\nprint('Number of nulls in patient_id column=', TrainFile_DF['patient_id'].isnull().sum())\nprint('Number of nulls in sex column=', TrainFile_DF['sex'].isnull().sum())\nprint('Number of nulls in age_approx column=', TrainFile_DF['age_approx'].isnull().sum())\nprint('Number of nulls in anatom_site_general_challenge column=', TrainFile_DF['anatom_site_general_challenge'].isnull().sum())\nprint('Number of nulls in benign_malignant column=', TrainFile_DF['benign_malignant'].isnull().sum())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Number of nulls in Test Data set\nprint('Number of nulls in image_name column=', TestFile_DF['image_name'].isnull().sum())\nprint('Number of nulls in patient_id column=', TestFile_DF['patient_id'].isnull().sum())\nprint('Number of nulls in sex column=', TestFile_DF['sex'].isnull().sum())\nprint('Number of nulls in age_approx column=', TestFile_DF['age_approx'].isnull().sum())\nprint('Number of nulls in anatom_site_general_challenge column=', TestFile_DF['anatom_site_general_challenge'].isnull().sum())","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Plot the Heat maps","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fig,ax1=plt.subplots(figsize=(30, 15))\nax1 = plt.subplot(2, 2, 1)\n\n\ndf1 = TrainFile_DF.pivot_table(index='target', columns='sex', values='age_approx', aggfunc='mean')\nsns.heatmap(df1)\n\nax2 = plt.subplot(2, 2, 2)\ndf2 = TrainFile_DF.pivot_table(index='target', columns='anatom_site_general_challenge', values='age_approx', aggfunc='mean')\nsns.heatmap(df2)\n\n\nax3 = plt.subplot(2, 2, 3)\ndf2 = TrainFile_DF.pivot_table(index='target', columns='diagnosis', values='age_approx', aggfunc='mean')\nsns.heatmap(df2)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Converting sex, anatom_site_general_challenge and diagnosis to numarical values","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"#droping the rows where values for sex column is missing as this is a categorical column\nTrainFile_DF.dropna(subset = [\"sex\"], inplace=True)\n\n#replacing the rows where values for age column is missing with mean\nTrainFile_DF['age_approx'].fillna((TrainFile_DF['age_approx'].mean()), inplace=True)\n\n\n#replacing the rows where values for diagnosis and anatom_site_general_challenge column is missing with unknown\nTrainFile_DF.fillna('unknown', inplace=True)\n\n# creating a dict file  \nsex = {'male': 0,'female': 1} \nanatom_site_general_challenge={'head/neck':1, 'lower extremity':2, 'oral/genital':3, 'palms/soles':4, 'torso':5, 'upper extremity':6,'unknown':7}\ndiagnosis={'atypical melanocytic proliferation':1, 'cafe-au-lait macule':2, 'lentigo NOS':3, 'lichenoid keratosis':4, 'melanoma':5, 'nevus':6,'seborrheic keratosis':7, 'solar lentigo':8,'unknown':9}\n\n\n\n\n# Looping through dataframe \nTrainFile_DF.sex = [sex[value] for value in TrainFile_DF.sex] \nTrainFile_DF.diagnosis = [diagnosis[value] for value in TrainFile_DF.diagnosis] \nTrainFile_DF.anatom_site_general_challenge = [anatom_site_general_challenge[value] for value in TrainFile_DF.anatom_site_general_challenge]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.set()  #Set aesthetic parameters in one step.\nsns.pairplot(TrainFile_DF,height=5 , hue='target',diag_kind='hist')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Inference","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"#### High age group has a greater number of positive Melanoma cases. These patients are above 50 years of age. This is evident from first heat map. \n\n#### Marks detected in all body parts (Sites) have probability of positive Melanoma cases. There is no specific site excluded from positive cases. This is evident from second heat map. \n\n#### There are 8 other types of diagnostic information highlighted in third heat map. The value melanoma in diagnosis column equals a positive case.\n\n#### The sns plot states the relationship between target values and feature Values.\n","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"# To be continued","execution_count":null}],"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}