<jupyter_start><jupyter_text>**Project Contributors: 18111006 (<NAME>), 18111015 (<NAME>), 18111016 (<NAME>), 18111025 (<NAME>)** **1. Importing Libraries**<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
from glob import glob
import seaborn as sns
from PIL import Image
np.random.seed(123)
from sklearn.preprocessing import label_binarize
from sklearn.metrics import confusion_matrix
import itertools

import keras

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import (
    BatchNormalization, SeparableConv2D, MaxPooling2D, Activation, Flatten, Dropout, Dense
)
from tensorflow.keras import backend as K


from keras.utils.np_utils import to_categorical # used for converting labels to one-hot-encoding
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D
from keras import backend as K
import itertools
from tensorflow.keras.layers import BatchNormalization

from keras.utils.np_utils import to_categorical # convert to one-hot-encoding

from tensorflow.keras.optimizers import Adam
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import ReduceLROnPlateau
from sklearn.model_selection import train_test_split
#1. Function to plot model's validation loss and validation accuracy
def plot_model_history(model_history):
    fig, axs = plt.subplots(1,2,figsize=(15,5))
    # summarize history for accuracy
    axs[0].plot(range(1,len(model_history.history['acc'])+1),model_history.history['acc'])
    axs[0].plot(range(1,len(model_history.history['val_acc'])+1),model_history.history['val_acc'])
    axs[0].set_title('Model Accuracy')
    axs[0].set_ylabel('Accuracy')
    axs[0].set_xlabel('Epoch')
    axs[0].set_xticks(np.arange(1,len(model_history.history['acc'])+1),len(model_history.history['acc'])/10)
    axs[0].legend(['train', 'val'], loc='best')
    # summarize history for loss
    axs[1].plot(range(1,len(model_history.history['loss'])+1),model_history.history['loss'])
    axs[1].plot(range(1,len(model_history.history['val_loss'])+1),model_history.history['val_loss'])
    axs[1].set_title('Model Loss')
    axs[1].set_ylabel('Loss')
    axs[1].set_xlabel('Epoch')
    axs[1].set_xticks(np.arange(1,len(model_history.history['loss'])+1),len(model_history.history['loss'])/10)
    axs[1].legend(['train', 'val'], loc='best')
    plt.show()
from google.colab import drive
drive.mount('/content/gdrive')
df = pd.read_csv('/content/gdrive/My Drive/Skin_Cancer/archive/HAM10000_metadata.csv')
df.head()
cwd = os.getcwd()

print(cwd)<jupyter_output>/content<jupyter_text>Now, merging images from both folders HAM10000_images_part1.zip and HAM10000_images_part2.zip into one dictionary<jupyter_code>base_skin_dir = os.path.join('/', 'content/gdrive/My Drive/Skin_Cancer/archive')



imageid_path_dict = {os.path.splitext(os.path.basename(x))[0]: x
                     for x in glob(os.path.join(base_skin_dir, '*', '*.jpg'))}



lesion_type_dict = {
    'nv': 'Melanocytic nevi',
    'mel': 'Melanoma',
    'bkl': 'Benign keratosis-like lesions ',
    'bcc': 'Basal cell carcinoma',
    'akiec': 'Actinic keratoses',
    'vasc': 'Vascular lesions',
    'df': 'Dermatofibroma'
}<jupyter_output><empty_output><jupyter_text>**2. Reading and Processing data**<jupyter_code>skin_df = pd.read_csv(os.path.join(base_skin_dir, 'HAM10000_metadata.csv'))

# Creating New Columns for better readability

skin_df['path'] = skin_df['image_id'].map(imageid_path_dict.get)
skin_df['cell_type'] = skin_df['dx'].map(lesion_type_dict.get) 
skin_df['cell_type_idx'] = pd.Categorical(skin_df['cell_type']).codes

skin_df.head()<jupyter_output><empty_output><jupyter_text>**3. Data Cleaning**<jupyter_code>skin_df.isnull().sum()<jupyter_output><empty_output><jupyter_text>As it is evident from the above that only age has null values which is 57 so we will fill the null values by their mean.<jupyter_code>skin_df['age'].fillna((skin_df['age'].mean()), inplace=True)<jupyter_output><empty_output><jupyter_text>Now checking if null values are still present or not<jupyter_code>skin_df.isnull().sum()<jupyter_output><empty_output><jupyter_text>**4. Exploratory data analysis (EDA)** In this we will explore different features of the dataset , their distrubtions and actual countsPlot to see distribution of 7 different classes of cell type<jupyter_code>fig, ax1 = plt.subplots(1, 1, figsize= (10, 5))
skin_df['cell_type'].value_counts().plot(kind='bar', ax=ax1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1359543158357127, 'fraction_numerical': 0.024599165385460135, 'mean_word_length': 6.514851485148514, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '323645', 'license': 'MIT', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1590, 'n_words': 324, 'path': 'Skin_Cancer_Classification_Major_Project.ipynb', 'repo_name': 'grvkr777/Major_Project', 'size': '4576'}