{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":20270,"databundleVersionId":1222630,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":13229715,"sourceType":"datasetVersion","datasetId":8385883},{"sourceId":13229732,"sourceType":"datasetVersion","datasetId":8385893},{"sourceId":38667125,"sourceType":"kernelVersion"}],"dockerImageVersionId":31090,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n        print(dirname)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:44:56.165120Z","iopub.execute_input":"2025-10-01T17:44:56.165918Z","iopub.status.idle":"2025-10-01T17:47:36.027652Z","shell.execute_reply.started":"2025-10-01T17:44:56.165891Z","shell.execute_reply":"2025-10-01T17:47:36.026913Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport cv2\nfrom tqdm import tqdm_notebook as tqdm\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly\nimport plotly.graph_objects as go\n%matplotlib inline","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:36.028782Z","iopub.execute_input":"2025-10-01T17:47:36.029010Z","iopub.status.idle":"2025-10-01T17:47:37.185696Z","shell.execute_reply.started":"2025-10-01T17:47:36.028993Z","shell.execute_reply":"2025-10-01T17:47:37.185163Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def get_image_names(dataframe) : \n    image_names = dataframe[\"image_name\"].values\n    image_names = image_names + \".jpg\"\n    return image_names","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.186329Z","iopub.execute_input":"2025-10-01T17:47:37.186579Z","iopub.status.idle":"2025-10-01T17:47:37.190337Z","shell.execute_reply.started":"2025-10-01T17:47:37.186563Z","shell.execute_reply":"2025-10-01T17:47:37.189699Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def get_info(image_names) : \n    image_names = np.array(image_names)\n    \n    print(\"Length = \", len(image_names))\n    print(\"Type = \", type(image_names))\n    print(\"Shape = \", image_names.shape)\n    \n    return image_names","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.192225Z","iopub.execute_input":"2025-10-01T17:47:37.192406Z","iopub.status.idle":"2025-10-01T17:47:37.204710Z","shell.execute_reply.started":"2025-10-01T17:47:37.192391Z","shell.execute_reply":"2025-10-01T17:47:37.204020Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from scipy.stats import skew\n\ndef extract_information(image_names, directory) : \n    image_statistics = pd.DataFrame(index = np.arange(len(image_names)),\n                                    columns = [\"image_name\", \"path\", \"rows\", \"columns\", \"channels\", \n                                              \"image_mean\", \"image_standard_deviation\", \"image_skewness\",\n                                              \"mean_red_value\", \"mean_green_value\", \"mean_blue_value\"])\n    i = 0 \n    for name in tqdm(image_names) : \n        path = os.path.join(directory, name)\n        image = cv2.imread(path)\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n        \n        image_statistics.iloc[i][\"image_name\"] = name\n        image_statistics.iloc[i][\"path\"] = path\n        image_statistics.iloc[i][\"rows\"] = image.shape[0]\n        image_statistics.iloc[i][\"columns\"] = image.shape[1]\n        image_statistics.iloc[i][\"channels\"] = image.shape[2]\n        image_statistics.iloc[i][\"image_mean\"] = np.mean(image.flatten())\n        image_statistics.iloc[i][\"image_standard_deviation\"] = np.std(image.flatten())\n        image_statistics.iloc[i][\"image_skewness\"] = skew(image.flatten())\n        image_statistics.iloc[i][\"mean_red_value\"] = np.mean(image[:,:,0])\n        image_statistics.iloc[i][\"mean_green_value\"] = np.mean(image[:,:,1])\n        image_statistics.iloc[i][\"mean_blue_value\"] = np.mean(image[:,:,2])\n        \n        i = i + 1\n        del image\n        \n    return image_statistics","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.205390Z","iopub.execute_input":"2025-10-01T17:47:37.205604Z","iopub.status.idle":"2025-10-01T17:47:37.213055Z","shell.execute_reply.started":"2025-10-01T17:47:37.205587Z","shell.execute_reply":"2025-10-01T17:47:37.212531Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_dir = \"/kaggle/input/siim-isic-melanoma-classification/jpeg/train/\"\ntrain = pd.DataFrame(pd.read_csv(\"/kaggle/input/siim-isic-melanoma-classification/train.csv\"))\ntrain.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.213572Z","iopub.execute_input":"2025-10-01T17:47:37.213755Z","iopub.status.idle":"2025-10-01T17:47:37.338395Z","shell.execute_reply.started":"2025-10-01T17:47:37.213740Z","shell.execute_reply":"2025-10-01T17:47:37.337824Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_names = get_image_names(train)\nimage_names = get_info(image_names)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.339087Z","iopub.execute_input":"2025-10-01T17:47:37.339309Z","iopub.status.idle":"2025-10-01T17:47:37.347360Z","shell.execute_reply.started":"2025-10-01T17:47:37.339285Z","shell.execute_reply":"2025-10-01T17:47:37.346642Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_dir = \"/kaggle/input/siim-isic-melanoma-classification/jpeg/test/\"\ntest = pd.DataFrame(pd.read_csv(\"/kaggle/input/siim-isic-melanoma-classification/test.csv\"))\ntest.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.348154Z","iopub.execute_input":"2025-10-01T17:47:37.348350Z","iopub.status.idle":"2025-10-01T17:47:37.385895Z","shell.execute_reply.started":"2025-10-01T17:47:37.348336Z","shell.execute_reply":"2025-10-01T17:47:37.385317Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_names = get_image_names(test)\nimage_names = get_info(image_names)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.386558Z","iopub.execute_input":"2025-10-01T17:47:37.386833Z","iopub.status.idle":"2025-10-01T17:47:37.392608Z","shell.execute_reply.started":"2025-10-01T17:47:37.386806Z","shell.execute_reply":"2025-10-01T17:47:37.391934Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.DataFrame(pd.read_csv(\"/kaggle/input/siim-isic-melanoma-classification/train.csv\"))\ntest = pd.DataFrame(pd.read_csv(\"/kaggle/input/siim-isic-melanoma-classification/test.csv\"))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.395014Z","iopub.execute_input":"2025-10-01T17:47:37.395564Z","iopub.status.idle":"2025-10-01T17:47:37.459430Z","shell.execute_reply.started":"2025-10-01T17:47:37.395547Z","shell.execute_reply":"2025-10-01T17:47:37.458938Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape, test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.460024Z","iopub.execute_input":"2025-10-01T17:47:37.460212Z","iopub.status.idle":"2025-10-01T17:47:37.464736Z","shell.execute_reply.started":"2025-10-01T17:47:37.460189Z","shell.execute_reply":"2025-10-01T17:47:37.464179Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.465402Z","iopub.execute_input":"2025-10-01T17:47:37.465725Z","iopub.status.idle":"2025-10-01T17:47:37.480927Z","shell.execute_reply.started":"2025-10-01T17:47:37.465701Z","shell.execute_reply":"2025-10-01T17:47:37.480343Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.481616Z","iopub.execute_input":"2025-10-01T17:47:37.481826Z","iopub.status.idle":"2025-10-01T17:47:37.494735Z","shell.execute_reply.started":"2025-10-01T17:47:37.481803Z","shell.execute_reply":"2025-10-01T17:47:37.494081Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.495837Z","iopub.execute_input":"2025-10-01T17:47:37.496080Z","iopub.status.idle":"2025-10-01T17:47:37.526373Z","shell.execute_reply.started":"2025-10-01T17:47:37.496058Z","shell.execute_reply":"2025-10-01T17:47:37.525897Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.526966Z","iopub.execute_input":"2025-10-01T17:47:37.527142Z","iopub.status.idle":"2025-10-01T17:47:37.536280Z","shell.execute_reply.started":"2025-10-01T17:47:37.527128Z","shell.execute_reply":"2025-10-01T17:47:37.535638Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(train[\"patient_id\"].unique()), len(test[\"patient_id\"].unique())\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.536940Z","iopub.execute_input":"2025-10-01T17:47:37.537157Z","iopub.status.idle":"2025-10-01T17:47:37.550781Z","shell.execute_reply.started":"2025-10-01T17:47:37.537137Z","shell.execute_reply":"2025-10-01T17:47:37.550048Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train[\"target\"].value_counts())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.551482Z","iopub.execute_input":"2025-10-01T17:47:37.551713Z","iopub.status.idle":"2025-10-01T17:47:37.560381Z","shell.execute_reply.started":"2025-10-01T17:47:37.551686Z","shell.execute_reply":"2025-10-01T17:47:37.559817Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"malignant = len(train[train[\"target\"] == 1])\nbenign = len(train[train[\"target\"] == 0])\n\nlabels = [\"Malignant\", \"Benign\"] \nsize = [malignant, benign]\n\nplt.figure(figsize = (8, 8))\nplt.pie(size, labels = labels, shadow = True, startangle = 90, colors = [\"r\", \"g\"])\nplt.title(\"Malignant VS Benign Cases\")\nplt.legend()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.561063Z","iopub.execute_input":"2025-10-01T17:47:37.561273Z","iopub.status.idle":"2025-10-01T17:47:37.927721Z","shell.execute_reply.started":"2025-10-01T17:47:37.561251Z","shell.execute_reply":"2025-10-01T17:47:37.926965Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_males = len(train[train[\"sex\"] == \"male\"])\ntrain_females  = len(train[train[\"sex\"] == \"female\"])\n\ntest_males = len(test[test[\"sex\"] == \"male\"])\ntest_females  = len(test[test[\"sex\"] == \"female\"])\n\nlabels = [\"Males\", \"Female\"] \n\nsize = [train_males, train_females]\nexplode = [0.1, 0.0]\n\nplt.figure(figsize = (16, 16))\nplt.subplot(1,2,1)\nplt.pie(size, labels = labels, explode = explode, shadow = True, startangle = 90, colors = [\"b\", \"g\"])\nplt.title(\"Male VS Female Training Set Count\", fontsize = 18)\nplt.legend()\n\nprint(\"Number of males in training set = \", train_males)\nprint(\"Number of females in training set= \", train_females)\n\nsize = [test_males, test_females]\n\nplt.subplot(1,2,2)\nplt.pie(size, labels = labels, explode = explode, shadow = True, startangle = 90, colors = [\"b\", \"g\"])\nplt.title(\"Male VS Female Test Set Count\", fontsize = 18)\nplt.legend()\n\nprint(\"Number of males in testing set = \", test_males)\nprint(\"Number of females in testing set= \", test_females)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:37.928562Z","iopub.execute_input":"2025-10-01T17:47:37.928880Z","iopub.status.idle":"2025-10-01T17:47:38.201779Z","shell.execute_reply.started":"2025-10-01T17:47:37.928862Z","shell.execute_reply":"2025-10-01T17:47:38.201115Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_malignant  = train[train[\"target\"] == 1]\ntrain_malignant_males = len(train_malignant[train_malignant[\"sex\"] == \"male\"])\ntrain_malignant_females  = len(train_malignant[train_malignant[\"sex\"] == \"female\"])\n\nlabels = [\"Malignant Male Cases\", \"Malignant Female Cases\"] \nsize = [train_malignant_males, train_malignant_females]\nexplode = [0.1, 0.0]\n\nplt.figure(figsize = (10, 10))\nplt.pie(size, labels = labels, explode = explode, shadow = True, startangle = 90, colors = [\"r\", \"c\"])\nplt.title(\"Malignant Male VS Female Cases\", fontsize = 18)\nplt.legend()\nprint(\"Malignant Male Cases = \", train_malignant_males)\nprint(\"Malignant Female Cases = \", train_malignant_females)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:38.202531Z","iopub.execute_input":"2025-10-01T17:47:38.202724Z","iopub.status.idle":"2025-10-01T17:47:38.370690Z","shell.execute_reply.started":"2025-10-01T17:47:38.202709Z","shell.execute_reply":"2025-10-01T17:47:38.369955Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_benign  = train[train[\"target\"] == 0]\n\ntrain_benign_males = len(train_benign[train_benign[\"sex\"] == \"male\"])\ntrain_benign_females  = len(train_benign[train_benign[\"sex\"] == \"female\"]) \n\nlabels = [\"Benign Male Cases\", \"Benign Female Cases\"] \nsize = [train_benign_males, train_benign_females]\nexplode = [0.1, 0.0]\n\nplt.figure(figsize = (10, 10))\nplt.pie(size, labels = labels, explode = explode, shadow = True, startangle = 90, colors = [\"g\", \"y\"])\nplt.title(\"Benign Male VS Benign Female Cases\", fontsize = 18)\nplt.legend()\nprint(\"Benign Male Cases = \", train_benign_males)\nprint(\"Benign Female Cases = \", train_benign_females)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:38.371719Z","iopub.execute_input":"2025-10-01T17:47:38.371987Z","iopub.status.idle":"2025-10-01T17:47:38.542019Z","shell.execute_reply.started":"2025-10-01T17:47:38.371964Z","shell.execute_reply":"2025-10-01T17:47:38.541251Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cancer_versus_sex = train.groupby([\"benign_malignant\", \"sex\"]).size()\nprint(cancer_versus_sex)\nprint(type(cancer_versus_sex))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:38.542861Z","iopub.execute_input":"2025-10-01T17:47:38.543047Z","iopub.status.idle":"2025-10-01T17:47:38.554298Z","shell.execute_reply.started":"2025-10-01T17:47:38.543031Z","shell.execute_reply":"2025-10-01T17:47:38.553804Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cancer_versus_sex = cancer_versus_sex.unstack(level = 1) / len(train) * 100\nprint(cancer_versus_sex)\nprint(type(cancer_versus_sex))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:38.554938Z","iopub.execute_input":"2025-10-01T17:47:38.555217Z","iopub.status.idle":"2025-10-01T17:47:38.568372Z","shell.execute_reply.started":"2025-10-01T17:47:38.555201Z","shell.execute_reply":"2025-10-01T17:47:38.567797Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.set(style='whitegrid')\nsns.set_context(\"paper\", rc={\"font.size\":12,\"axes.titlesize\":20,\"axes.labelsize\":18})   \n\nplt.figure(figsize = (10, 6))\nsns.heatmap(cancer_versus_sex, annot=True, cmap=\"icefire\", cbar=True)\nplt.title(\"Cancer VS Sex Heatmap Analysis Normalized\", fontsize = 18)\nplt.tight_layout()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:38.569119Z","iopub.execute_input":"2025-10-01T17:47:38.569338Z","iopub.status.idle":"2025-10-01T17:47:38.808378Z","shell.execute_reply.started":"2025-10-01T17:47:38.569323Z","shell.execute_reply":"2025-10-01T17:47:38.807741Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# train\ntrain_torso = len(train[train[\"anatom_site_general_challenge\"] == \"torso\"])\ntrain_lower_extremity = len(train[train[\"anatom_site_general_challenge\"] == \"lower extremity\"])\ntrain_upper_extremity = len(train[train[\"anatom_site_general_challenge\"] == \"upper extremity\"])\ntrain_head_neck = len(train[train[\"anatom_site_general_challenge\"] == \"head/neck\"])\ntrain_palms_soles = len(train[train[\"anatom_site_general_challenge\"] == \"palms/soles\"])\ntrain_oral_genital = len(train[train[\"anatom_site_general_challenge\"] == \"oral/genital\"])\n\n# test\ntest_torso = len(test[test[\"anatom_site_general_challenge\"] == \"torso\"])\ntest_lower_extremity = len(test[test[\"anatom_site_general_challenge\"] == \"lower extremity\"])\ntest_upper_extremity = len(test[test[\"anatom_site_general_challenge\"] == \"upper extremity\"])\ntest_head_neck = len(test[test[\"anatom_site_general_challenge\"] == \"head/neck\"])\ntest_palms_soles = len(test[test[\"anatom_site_general_challenge\"] == \"palms/soles\"])\ntest_oral_genital = len(test[test[\"anatom_site_general_challenge\"] == \"oral/genital\"])\n\nlabels = [\"Torso\", \"Lower Extremity\", \"Upper Extremity\", \"Head/Neck\", \"Palms/Soles\", \"Oral/Genital\"] \n\nplt.figure(figsize = (16, 16))\n\nplt.subplot(1,2,1)\nsize = [train_torso, train_lower_extremity, train_upper_extremity, train_head_neck, train_palms_soles, train_oral_genital]\nexplode = [0.05, 0.05, 0.05, 0.05, 0.05, 0.1]\nplt.pie(size, labels = labels, explode = explode, shadow = True, startangle = 90)\nplt.title(\"Anatomy Sites In Training Set\", fontsize = 18)\nplt.legend()\n\nplt.subplot(1,2,2)\nsize = [test_torso, test_lower_extremity, test_upper_extremity, test_head_neck, test_palms_soles, test_oral_genital]\nexplode = [0.05, 0.05, 0.05, 0.05, 0.05, 0.1]\nplt.pie(size, labels = labels, explode = explode, shadow = True, startangle = 90)\nplt.title(\"Anatomy Sites In Testing Set\", fontsize = 18)\nplt.legend()\n\n# Automatically adjust subplot parameters to give specified padding.\nplt.tight_layout()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:38.809010Z","iopub.execute_input":"2025-10-01T17:47:38.809173Z","iopub.status.idle":"2025-10-01T17:47:39.327969Z","shell.execute_reply.started":"2025-10-01T17:47:38.809160Z","shell.execute_reply":"2025-10-01T17:47:39.327190Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_ages_benign = train.loc[train[\"target\"] == 0, \"age_approx\"]\ntrain_ages_malignant = train.loc[train[\"target\"] == 1 , \"age_approx\"]\n\nplt.figure(figsize = (10, 8))\nsns.kdeplot(train_ages_benign, label = \"Benign\", shade = True, legend = True, cbar = True)\nsns.kdeplot(train_ages_malignant, label = \"Malignant\", shade = True, legend = True, cbar = True)\nplt.grid(True)\nplt.xlabel(\"Age Of The Patients\", fontsize = 18)\nplt.ylabel(\"Probability Density\", fontsize = 18)\nplt.grid(which = \"minor\", axis = \"both\")\nplt.title(\"Probabilistic Age Distribution In Training Set\", fontsize = 18)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:47:39.328742Z","iopub.execute_input":"2025-10-01T17:47:39.328983Z","iopub.status.idle":"2025-10-01T17:47:39.834099Z","shell.execute_reply.started":"2025-10-01T17:47:39.328964Z","shell.execute_reply":"2025-10-01T17:47:39.833435Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_image_stats_01 = pd.DataFrame(pd.read_csv(\"/kaggle/input/compiled/melanoma_image_statistics_compiled_01\"))\ntrain_image_stats_02 = pd.DataFrame(pd.read_csv(\"/kaggle/input/compiled/melanoma_image_statistics_compiled_02\"))\ntrain_image_stats_03 = pd.DataFrame(pd.read_csv(\"/kaggle/input/compiled/melanoma_image_statistics_compiled_03\"))\ntrain_image_stats_04 = pd.DataFrame(pd.read_csv(\"/kaggle/input/compiled/melanoma_image_statistics_compiled_04\"))\ntrain_image_stats_05 = pd.DataFrame(pd.read_csv(\"/kaggle/input/compiled/melanoma_image_statistics_compiled_05\"))\ntrain_image_stats_06 = pd.DataFrame(pd.read_csv(\"/kaggle/input/compiled/melanoma_image_statistics_compiled_06\"))\n\nprint(train_image_stats_01.shape)\nprint(train_image_stats_02.shape)\nprint(train_image_stats_03.shape)\nprint(train_image_stats_04.shape)\nprint(train_image_stats_05.shape)\nprint(train_image_stats_06.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:55:44.474755Z","iopub.execute_input":"2025-10-01T17:55:44.475479Z","iopub.status.idle":"2025-10-01T17:55:44.698733Z","shell.execute_reply.started":"2025-10-01T17:55:44.475452Z","shell.execute_reply":"2025-10-01T17:55:44.698164Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_image_statistics = pd.concat([train_image_stats_01, train_image_stats_02, train_image_stats_03,\n                                   train_image_stats_04, train_image_stats_05, train_image_stats_06],\n                                  ignore_index = True)\ntrain_image_statistics.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:55:47.810263Z","iopub.execute_input":"2025-10-01T17:55:47.810990Z","iopub.status.idle":"2025-10-01T17:55:47.818076Z","shell.execute_reply.started":"2025-10-01T17:55:47.810965Z","shell.execute_reply":"2025-10-01T17:55:47.817394Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_image_statistics.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:55:49.660486Z","iopub.execute_input":"2025-10-01T17:55:49.660748Z","iopub.status.idle":"2025-10-01T17:55:49.673479Z","shell.execute_reply.started":"2025-10-01T17:55:49.660729Z","shell.execute_reply":"2025-10-01T17:55:49.672641Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_image_stats_01 = pd.DataFrame(pd.read_csv(\"/kaggle/input/compiled-test/melanoma_image_statistics_compiled_test_01\"))\ntest_image_stats_02 = pd.DataFrame(pd.read_csv(\"/kaggle/input/compiled-test/melanoma_image_statistics_compiled_test_02\"))\n\nprint(test_image_stats_01.shape)\nprint(test_image_stats_02.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:57:58.874902Z","iopub.execute_input":"2025-10-01T17:57:58.875691Z","iopub.status.idle":"2025-10-01T17:57:58.943482Z","shell.execute_reply.started":"2025-10-01T17:57:58.875667Z","shell.execute_reply":"2025-10-01T17:57:58.942943Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_image_statistics = pd.concat([test_image_stats_01, test_image_stats_02], ignore_index = True)\n\ntest_image_statistics.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:58:00.268467Z","iopub.execute_input":"2025-10-01T17:58:00.268916Z","iopub.status.idle":"2025-10-01T17:58:00.275121Z","shell.execute_reply.started":"2025-10-01T17:58:00.268894Z","shell.execute_reply":"2025-10-01T17:58:00.274334Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_image_statistics.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:58:01.748298Z","iopub.execute_input":"2025-10-01T17:58:01.748842Z","iopub.status.idle":"2025-10-01T17:58:01.758893Z","shell.execute_reply.started":"2025-10-01T17:58:01.748817Z","shell.execute_reply":"2025-10-01T17:58:01.758299Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_image_statistics.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:58:02.830373Z","iopub.execute_input":"2025-10-01T17:58:02.831152Z","iopub.status.idle":"2025-10-01T17:58:02.840900Z","shell.execute_reply.started":"2025-10-01T17:58:02.831125Z","shell.execute_reply":"2025-10-01T17:58:02.840178Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_image_statistics.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:58:06.031798Z","iopub.execute_input":"2025-10-01T17:58:06.032310Z","iopub.status.idle":"2025-10-01T17:58:06.042067Z","shell.execute_reply.started":"2025-10-01T17:58:06.032286Z","shell.execute_reply":"2025-10-01T17:58:06.041361Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_names = train_image_statistics[\"image_name\"].values\nrandom_images = [np.random.choice(image_names) for i in range(4)] # Generates a random sample from a given 1-D array\nrandom_images ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:58:07.124226Z","iopub.execute_input":"2025-10-01T17:58:07.124498Z","iopub.status.idle":"2025-10-01T17:58:07.130040Z","shell.execute_reply.started":"2025-10-01T17:58:07.124478Z","shell.execute_reply":"2025-10-01T17:58:07.129426Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_dir = \"/kaggle/input/siim-isic-melanoma-classification/jpeg/train/\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:58:08.854252Z","iopub.execute_input":"2025-10-01T17:58:08.854948Z","iopub.status.idle":"2025-10-01T17:58:08.858101Z","shell.execute_reply.started":"2025-10-01T17:58:08.854925Z","shell.execute_reply":"2025-10-01T17:58:08.857337Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize = (12, 8))\nfor i in range(4) : \n    plt.subplot(2, 2, i + 1) \n    image = cv2.imread(os.path.join(train_dir, random_images[i]))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image, cmap = \"gray\")\n    plt.grid(True)\nplt.tight_layout()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:58:12.366292Z","iopub.execute_input":"2025-10-01T17:58:12.367032Z","iopub.status.idle":"2025-10-01T17:58:18.404688Z","shell.execute_reply.started":"2025-10-01T17:58:12.367005Z","shell.execute_reply":"2025-10-01T17:58:18.403726Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"benign_mean_red_value = []\nbenign_mean_green_value = []\nbenign_mean_blue_value = []\n\nmalignant_mean_red_value = []\nmalignant_mean_green_value = []\nmalignant_mean_blue_value = []\n\nfor image_name in tqdm(train_image_statistics[\"image_name\"]) : \n    name = image_name[0:len(image_name)-4] \n    extracted_section = train[train[\"image_name\"] == name]\n    r = int(train_image_statistics[train_image_statistics[\"image_name\"] == image_name][\"mean_red_value\"])\n    g = int(train_image_statistics[train_image_statistics[\"image_name\"] == image_name][\"mean_green_value\"])\n    b = int(train_image_statistics[train_image_statistics[\"image_name\"] == image_name][\"mean_blue_value\"])\n    if int(extracted_section[\"target\"]) == 0 : # benign\n        benign_mean_red_value.append(r)\n        benign_mean_green_value.append(g)\n        benign_mean_blue_value.append(b)\n    else:\n        malignant_mean_red_value.append(r)\n        malignant_mean_green_value.append(g)\n        malignant_mean_blue_value.append(b)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T17:58:56.059486Z","iopub.execute_input":"2025-10-01T17:58:56.059929Z","iopub.status.idle":"2025-10-01T18:04:43.219181Z","shell.execute_reply.started":"2025-10-01T17:58:56.059908Z","shell.execute_reply":"2025-10-01T18:04:43.218478Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"range_of_spread = max(benign_mean_red_value) - min(benign_mean_red_value)\n\nplt.figure(figsize = (12, 8))\nplt.rc(\"font\", weight = \"bold\")\nsns.set_style(\"whitegrid\")\nfig = sns.distplot(benign_mean_red_value, hist = True, kde = True, label = \"Mean Red Channel Intensities\", color = \"r\")\nfig.set(xlabel = \"Mean red channel intensities observed in each image\",\n        ylabel = \"Probability Density\")\nplt.title(\"Spread Of Red Channel In Benign Cases\", fontsize = 18)\nplt.legend()\nprint(\"The range of spread = {:.2f}\".format(range_of_spread))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:43.220300Z","iopub.execute_input":"2025-10-01T18:04:43.220527Z","iopub.status.idle":"2025-10-01T18:04:43.751509Z","shell.execute_reply.started":"2025-10-01T18:04:43.220509Z","shell.execute_reply":"2025-10-01T18:04:43.750883Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"range_of_spread = max(benign_mean_green_value) - min(benign_mean_green_value)\n\nplt.figure(figsize = (12, 8))\nplt.rc(\"font\", weight = \"bold\")\nsns.set_style(\"whitegrid\")\nfig = sns.distplot(benign_mean_green_value, hist = True, kde = True, label = \"Mean Green Channel Intensities\", color = \"g\")\nfig.set(xlabel = \"Mean green channel intensities observed in each image\",\n        ylabel = \"Probability Density\") \nplt.title(\"Spread Of Green Channel In Benign Cases\", fontsize = 18)\nplt.legend()\nprint(\"The range of spread = {:.2f}\".format(range_of_spread))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:43.752295Z","iopub.execute_input":"2025-10-01T18:04:43.752542Z","iopub.status.idle":"2025-10-01T18:04:44.302318Z","shell.execute_reply.started":"2025-10-01T18:04:43.752515Z","shell.execute_reply":"2025-10-01T18:04:44.301624Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"range_of_spread = max(benign_mean_blue_value) - min(benign_mean_blue_value)\n\nplt.figure(figsize = (12, 8))\nplt.rc(\"font\", weight = \"bold\")\nsns.set_style(\"whitegrid\")\nfig = sns.distplot(benign_mean_blue_value, hist = True, kde = True, label = \"Mean Blue Channel Intensities\", color = \"b\")\nfig.set(xlabel = \"Mean blue channel intensities observed in each image\",\n        ylabel = \"Probability Density\") \nplt.title(\"Spread Of Blue Channel In Benign Cases\", fontsize = 18)\nplt.legend()\nprint(\"The range of spread = {:.2f}\".format(range_of_spread))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:44.303825Z","iopub.execute_input":"2025-10-01T18:04:44.304019Z","iopub.status.idle":"2025-10-01T18:04:44.828801Z","shell.execute_reply.started":"2025-10-01T18:04:44.304003Z","shell.execute_reply":"2025-10-01T18:04:44.828159Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize = (12, 8))\nplt.rc(\"font\", weight = \"bold\")\nsns.set_style(\"whitegrid\")\nfig = sns.distplot(benign_mean_blue_value, hist = False, kde = True, label = \"Mean Blue Channel Intensities\", color = \"b\")\nfig = sns.distplot(benign_mean_red_value, hist = False, kde = True, label = \"Mean Red Channel Intensities\", color = \"r\")\nfig = sns.distplot(benign_mean_green_value, hist = False, kde = True, label = \"Mean Green Channel Intensities\", color = \"g\")\n\nfig.set(xlabel = \"Mean channel intensities observed in each image\",\n        ylabel = \"Probability Density\") \nplt.title(\"Spread Of Channels In Benign Cases\", fontsize = 18)\nplt.legend()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:44.829621Z","iopub.execute_input":"2025-10-01T18:04:44.829830Z","iopub.status.idle":"2025-10-01T18:04:45.632350Z","shell.execute_reply.started":"2025-10-01T18:04:44.829815Z","shell.execute_reply":"2025-10-01T18:04:45.631615Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"del benign_mean_red_value\ndel benign_mean_green_value\ndel benign_mean_blue_value","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:45.633183Z","iopub.execute_input":"2025-10-01T18:04:45.633385Z","iopub.status.idle":"2025-10-01T18:04:45.637011Z","shell.execute_reply.started":"2025-10-01T18:04:45.633368Z","shell.execute_reply":"2025-10-01T18:04:45.636324Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import gc\ngc.collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:45.637894Z","iopub.execute_input":"2025-10-01T18:04:45.638125Z","iopub.status.idle":"2025-10-01T18:04:45.743174Z","shell.execute_reply.started":"2025-10-01T18:04:45.638102Z","shell.execute_reply":"2025-10-01T18:04:45.742490Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize = (12, 8))\nplt.rc(\"font\", weight = \"bold\")\nsns.set_style(\"whitegrid\")\nfig = sns.distplot(malignant_mean_blue_value, hist = False, kde = True, label = \"Mean Blue Channel Intensities\", color = \"b\")\nfig = sns.distplot(malignant_mean_red_value, hist = False, kde = True, label = \"Mean Red Channel Intensities\", color = \"r\")\nfig = sns.distplot(malignant_mean_green_value, hist = False, kde = True, label = \"Mean Green Channel Intensities\", color = \"g\")\n\nfig.set(xlabel = \"Mean channel intensities observed in each image\",\n        ylabel = \"Probability Density\") \nplt.title(\"Spread Of Channels In Malignant Cases\", fontsize = 18)\nplt.legend()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:45.743878Z","iopub.execute_input":"2025-10-01T18:04:45.744128Z","iopub.status.idle":"2025-10-01T18:04:46.133519Z","shell.execute_reply.started":"2025-10-01T18:04:45.744106Z","shell.execute_reply":"2025-10-01T18:04:46.132799Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"gc.collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:46.134369Z","iopub.execute_input":"2025-10-01T18:04:46.134601Z","iopub.status.idle":"2025-10-01T18:04:46.212515Z","shell.execute_reply.started":"2025-10-01T18:04:46.134583Z","shell.execute_reply":"2025-10-01T18:04:46.211931Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:46.215351Z","iopub.execute_input":"2025-10-01T18:04:46.215544Z","iopub.status.idle":"2025-10-01T18:04:46.227888Z","shell.execute_reply.started":"2025-10-01T18:04:46.215529Z","shell.execute_reply":"2025-10-01T18:04:46.227297Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"missing = len(train[train[\"sex\"].isna() == True])\navailable = len(train[train[\"sex\"].isna() == False])\n\nx = [\"Availabe data\", \"Unavailable data\"]\ny = [np.log(available), np.log(missing)]\n\nprint(\"Count of missing data = \", missing)\nprint(\"Count of available data = \", available)\n\nplt.figure(figsize = (12, 8))\nplt.subplot(1,1,1)\nplt.barh(x, y, color = \"m\")\nplt.grid(True)\nplt.title(\"Data On Patient's Sex\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:46.228597Z","iopub.execute_input":"2025-10-01T18:04:46.229209Z","iopub.status.idle":"2025-10-01T18:04:46.423656Z","shell.execute_reply.started":"2025-10-01T18:04:46.229185Z","shell.execute_reply":"2025-10-01T18:04:46.422978Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['sex'].fillna('male', inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:15:05.020215Z","iopub.execute_input":"2025-10-01T18:15:05.020918Z","iopub.status.idle":"2025-10-01T18:15:05.025980Z","shell.execute_reply.started":"2025-10-01T18:15:05.020891Z","shell.execute_reply":"2025-10-01T18:15:05.025246Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"missing =  len(train[train[\"age_approx\"].isna() == True]) \navailable = len(train[train[\"age_approx\"].isna() == False]) \n\nprint(\"Missing age values = \", missing)\nprint(\"Available age data = \", available)\n\nx = [\"Availabe data\", \"Unavailable data\"]\ny = [np.log(available), np.log(missing)] \n\nplt.figure(figsize = (12, 8))\nplt.subplot(1,1,1)\nplt.barh(x, y, color = \"y\")\nplt.grid(True)\nplt.title(\"Data On Patient's Age\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:46.431561Z","iopub.execute_input":"2025-10-01T18:04:46.431742Z","iopub.status.idle":"2025-10-01T18:04:46.620274Z","shell.execute_reply.started":"2025-10-01T18:04:46.431728Z","shell.execute_reply":"2025-10-01T18:04:46.619709Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# train\nanatomy_sites = [\"torso\", \"upper extremity\", \"lower extremity\"]\n\nrelevant_dataframe_part = train[(train[\"sex\"] == \"male\") &\n                     (train[\"anatom_site_general_challenge\"].isin(anatomy_sites)) &\n                     (train[\"target\"] == 0)]\n\nmedian_value = relevant_dataframe_part[\"age_approx\"].median()\n\nprint(\"Median value = \", median_value)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:46.620952Z","iopub.execute_input":"2025-10-01T18:04:46.621126Z","iopub.status.idle":"2025-10-01T18:04:46.632074Z","shell.execute_reply.started":"2025-10-01T18:04:46.621112Z","shell.execute_reply":"2025-10-01T18:04:46.631393Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"age_approx\"].fillna(median_value, inplace = True)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:46.632740Z","iopub.execute_input":"2025-10-01T18:04:46.632971Z","iopub.status.idle":"2025-10-01T18:04:46.641563Z","shell.execute_reply.started":"2025-10-01T18:04:46.632956Z","shell.execute_reply":"2025-10-01T18:04:46.640916Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"anatom_site_general_challenge\"].fillna(\"torso\", inplace = True)\ntest[\"anatom_site_general_challenge\"].fillna(\"torso\", inplace = True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:46.642247Z","iopub.execute_input":"2025-10-01T18:04:46.642521Z","iopub.status.idle":"2025-10-01T18:04:46.655211Z","shell.execute_reply.started":"2025-10-01T18:04:46.642502Z","shell.execute_reply":"2025-10-01T18:04:46.654449Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:46.655826Z","iopub.execute_input":"2025-10-01T18:04:46.656053Z","iopub.status.idle":"2025-10-01T18:04:46.679330Z","shell.execute_reply.started":"2025-10-01T18:04:46.656038Z","shell.execute_reply":"2025-10-01T18:04:46.678649Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-01T18:04:46.680002Z","iopub.execute_input":"2025-10-01T18:04:46.680200Z","iopub.status.idle":"2025-10-01T18:04:46.693365Z","shell.execute_reply.started":"2025-10-01T18:04:46.680186Z","shell.execute_reply":"2025-10-01T18:04:46.692705Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}