{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":20270,"databundleVersionId":1222630,"sourceType":"competition"}],"dockerImageVersionId":30635,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sb\nimport pandas as pd\nimport os\nfrom PIL import Image\nimport torch\nimport torchvision.models as models\nimport torchvision.transforms as transforms","metadata":{"execution":{"iopub.status.busy":"2024-01-31T13:10:29.798214Z","iopub.execute_input":"2024-01-31T13:10:29.798670Z","iopub.status.idle":"2024-01-31T13:10:36.612690Z","shell.execute_reply.started":"2024-01-31T13:10:29.798614Z","shell.execute_reply":"2024-01-31T13:10:36.611488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv('/kaggle/input/siim-isic-melanoma-classification/train.csv')\ntrain_data.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-01-31T13:10:36.614348Z","iopub.execute_input":"2024-01-31T13:10:36.614973Z","iopub.status.idle":"2024-01-31T13:10:36.756307Z","shell.execute_reply.started":"2024-01-31T13:10:36.614934Z","shell.execute_reply":"2024-01-31T13:10:36.755425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 6))\nsb.countplot(data=train_data, x='benign_malignant')\nplt.xlabel('benign_malignant')\nplt.ylabel('Count')\nplt.title('Benign Malignant Variable Distribution')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-31T13:10:36.757560Z","iopub.execute_input":"2024-01-31T13:10:36.758073Z","iopub.status.idle":"2024-01-31T13:10:37.112344Z","shell.execute_reply.started":"2024-01-31T13:10:36.758038Z","shell.execute_reply":"2024-01-31T13:10:37.111076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nsb.countplot(data=train_data, x='sex', hue='benign_malignant')\nplt.title('Benign vs Malignant by Sex')\nplt.xlabel('Sex')\nplt.ylabel('Count')\nplt.legend(title='Benign/Malignant', loc='upper right')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-31T13:10:37.115966Z","iopub.execute_input":"2024-01-31T13:10:37.116382Z","iopub.status.idle":"2024-01-31T13:10:37.514179Z","shell.execute_reply.started":"2024-01-31T13:10:37.116348Z","shell.execute_reply":"2024-01-31T13:10:37.512995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nsb.countplot(data=train_data, x='age_approx', hue='benign_malignant')\nplt.title('Benign vs Malignant by Age')\nplt.xlabel('Age')\nplt.ylabel('Count')\nplt.legend(title='Benign/Malignant', loc='upper right')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-31T13:10:37.515590Z","iopub.execute_input":"2024-01-31T13:10:37.515985Z","iopub.status.idle":"2024-01-31T13:10:38.037977Z","shell.execute_reply.started":"2024-01-31T13:10:37.515953Z","shell.execute_reply":"2024-01-31T13:10:38.036735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Imbalance in the records.\nbenign_malignant_count = train_data[\"benign_malignant\"].value_counts()\nbenign_malignant_count","metadata":{"execution":{"iopub.status.busy":"2024-01-31T13:10:38.039462Z","iopub.execute_input":"2024-01-31T13:10:38.039907Z","iopub.status.idle":"2024-01-31T13:10:38.059655Z","shell.execute_reply.started":"2024-01-31T13:10:38.039863Z","shell.execute_reply":"2024-01-31T13:10:38.058332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"jpeg_folder = \"/kaggle/input/siim-isic-melanoma-classification/jpeg/train\"\n\n# List all files in the directory\njpeg_files = os.listdir(jpeg_folder)","metadata":{"execution":{"iopub.status.busy":"2024-01-31T13:10:38.061193Z","iopub.execute_input":"2024-01-31T13:10:38.061617Z","iopub.status.idle":"2024-01-31T13:10:38.677767Z","shell.execute_reply.started":"2024-01-31T13:10:38.061581Z","shell.execute_reply":"2024-01-31T13:10:38.676390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Display the first few sample images with labels\nimport matplotlib.pyplot as plt\n\nnum_samples_per_class = 10\nnum_rows = 5\nnum_cols = 4\n\n# Filter melanoma and non-melanoma images\nmelanoma_images = train_data[train_data['benign_malignant'] == 'malignant'].sample(num_samples_per_class)\nnon_melanoma_images = train_data[train_data['benign_malignant'] == 'benign'].sample(num_samples_per_class)\nselected_images = pd.concat([melanoma_images, non_melanoma_images])\n\nfig, axes = plt.subplots(num_rows, num_cols, figsize=(16, 20))\n\nfor i in range(num_samples_per_class * 2):  # Display both melanoma and non-melanoma images\n    row = i // num_cols\n    col = i % num_cols\n    \n    # Load image using PIL\n    image_filename = selected_images['image_name'].iloc[i]\n    image_path = os.path.join(jpeg_folder, image_filename + \".jpg\")\n    image = Image.open(image_path)\n    \n    # Display image with label\n    axes[row, col].imshow(image)\n    axes[row, col].axis('off')\n    axes[row, col].set_title(f\"Label: {selected_images['benign_malignant'].iloc[i]}\")\n\nplt.tight_layout()\nplt.show()\n\n","metadata":{"execution":{"iopub.status.busy":"2024-01-31T13:14:47.839840Z","iopub.execute_input":"2024-01-31T13:14:47.840249Z","iopub.status.idle":"2024-01-31T13:15:16.429849Z","shell.execute_reply.started":"2024-01-31T13:14:47.840216Z","shell.execute_reply":"2024-01-31T13:15:16.427971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}