{"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":"nvidiaTeslaT4","dataSources":[{"sourceId":16880,"databundleVersionId":858837,"sourceType":"competition"},{"sourceId":924245,"sourceType":"datasetVersion","datasetId":464091}],"dockerImageVersionId":30627,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"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 20GB 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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_path = '/kaggle/input/deepfake-faces/metadata.csv'","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:48.762717Z","iopub.execute_input":"2024-10-05T10:54:48.763014Z","iopub.status.idle":"2024-10-05T10:54:48.767295Z","shell.execute_reply.started":"2024-10-05T10:54:48.762967Z","shell.execute_reply":"2024-10-05T10:54:48.766313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(dataset_path)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:48.769564Z","iopub.execute_input":"2024-10-05T10:54:48.769960Z","iopub.status.idle":"2024-10-05T10:54:48.964383Z","shell.execute_reply.started":"2024-10-05T10:54:48.769909Z","shell.execute_reply":"2024-10-05T10:54:48.963456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:48.966790Z","iopub.execute_input":"2024-10-05T10:54:48.967140Z","iopub.status.idle":"2024-10-05T10:54:48.990557Z","shell.execute_reply.started":"2024-10-05T10:54:48.967111Z","shell.execute_reply":"2024-10-05T10:54:48.989719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.tail()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:48.991661Z","iopub.execute_input":"2024-10-05T10:54:48.991924Z","iopub.status.idle":"2024-10-05T10:54:49.004398Z","shell.execute_reply.started":"2024-10-05T10:54:48.991900Z","shell.execute_reply":"2024-10-05T10:54:49.003008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.005787Z","iopub.execute_input":"2024-10-05T10:54:49.006125Z","iopub.status.idle":"2024-10-05T10:54:49.013885Z","shell.execute_reply.started":"2024-10-05T10:54:49.006098Z","shell.execute_reply":"2024-10-05T10:54:49.012879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.014974Z","iopub.execute_input":"2024-10-05T10:54:49.015307Z","iopub.status.idle":"2024-10-05T10:54:49.026764Z","shell.execute_reply.started":"2024-10-05T10:54:49.015274Z","shell.execute_reply":"2024-10-05T10:54:49.025820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.028145Z","iopub.execute_input":"2024-10-05T10:54:49.028530Z","iopub.status.idle":"2024-10-05T10:54:49.090724Z","shell.execute_reply.started":"2024-10-05T10:54:49.028494Z","shell.execute_reply":"2024-10-05T10:54:49.089860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.091951Z","iopub.execute_input":"2024-10-05T10:54:49.092325Z","iopub.status.idle":"2024-10-05T10:54:49.129279Z","shell.execute_reply.started":"2024-10-05T10:54:49.092291Z","shell.execute_reply":"2024-10-05T10:54:49.128371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.134823Z","iopub.execute_input":"2024-10-05T10:54:49.135431Z","iopub.status.idle":"2024-10-05T10:54:49.179858Z","shell.execute_reply.started":"2024-10-05T10:54:49.135400Z","shell.execute_reply":"2024-10-05T10:54:49.178964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.nunique()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.181014Z","iopub.execute_input":"2024-10-05T10:54:49.181312Z","iopub.status.idle":"2024-10-05T10:54:49.229622Z","shell.execute_reply.started":"2024-10-05T10:54:49.181288Z","shell.execute_reply":"2024-10-05T10:54:49.228752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"object_columns = df.select_dtypes(include=['object']).columns\nprint(\"Object type columns:\")\nprint(object_columns)\n\nnumerical_columns = df.select_dtypes(include=['int64', 'float64']).columns\nprint(\"\\nNumerical type columns:\")\nprint(numerical_columns)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.230800Z","iopub.execute_input":"2024-10-05T10:54:49.231118Z","iopub.status.idle":"2024-10-05T10:54:49.241858Z","shell.execute_reply.started":"2024-10-05T10:54:49.231092Z","shell.execute_reply":"2024-10-05T10:54:49.240777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def classify_features(df):\n    categorical_features = []\n    non_categorical_features = []\n    discrete_features = []\n    continuous_features = []\n\n    for column in df.columns:\n        if df[column].dtype == 'object':\n            if df[column].nunique() < 10:\n                categorical_features.append(column)\n            else:\n                non_categorical_features.append(column)\n        elif df[column].dtype in ['int64', 'float64']:\n            if df[column].nunique() < 10:\n                discrete_features.append(column)\n            else:\n                continuous_features.append(column)\n\n    return categorical_features, non_categorical_features, discrete_features, continuous_features","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.243079Z","iopub.execute_input":"2024-10-05T10:54:49.243389Z","iopub.status.idle":"2024-10-05T10:54:49.251762Z","shell.execute_reply.started":"2024-10-05T10:54:49.243364Z","shell.execute_reply":"2024-10-05T10:54:49.251046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categorical, non_categorical, discrete, continuous = classify_features(df)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.252915Z","iopub.execute_input":"2024-10-05T10:54:49.253273Z","iopub.status.idle":"2024-10-05T10:54:49.304335Z","shell.execute_reply.started":"2024-10-05T10:54:49.253240Z","shell.execute_reply":"2024-10-05T10:54:49.303571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Categorical Features:\", categorical)\nprint(\"Non-Categorical Features:\", non_categorical)\nprint(\"Discrete Features:\", discrete)\nprint(\"Continuous Features:\", continuous)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.305327Z","iopub.execute_input":"2024-10-05T10:54:49.305589Z","iopub.status.idle":"2024-10-05T10:54:49.310976Z","shell.execute_reply.started":"2024-10-05T10:54:49.305565Z","shell.execute_reply":"2024-10-05T10:54:49.310197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.fillna(\"Not Available\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.312166Z","iopub.execute_input":"2024-10-05T10:54:49.312533Z","iopub.status.idle":"2024-10-05T10:54:49.355095Z","shell.execute_reply.started":"2024-10-05T10:54:49.312490Z","shell.execute_reply":"2024-10-05T10:54:49.354343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in categorical:\n    print(i,':', df[i].unique())\n    print()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.356168Z","iopub.execute_input":"2024-10-05T10:54:49.356489Z","iopub.status.idle":"2024-10-05T10:54:49.369451Z","shell.execute_reply.started":"2024-10-05T10:54:49.356462Z","shell.execute_reply":"2024-10-05T10:54:49.368549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in categorical:\n    print(df[i].value_counts())\n    print()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.370702Z","iopub.execute_input":"2024-10-05T10:54:49.371054Z","iopub.status.idle":"2024-10-05T10:54:49.388768Z","shell.execute_reply.started":"2024-10-05T10:54:49.371021Z","shell.execute_reply":"2024-10-05T10:54:49.387761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:49.389901Z","iopub.execute_input":"2024-10-05T10:54:49.390200Z","iopub.status.idle":"2024-10-05T10:54:50.010177Z","shell.execute_reply.started":"2024-10-05T10:54:49.390174Z","shell.execute_reply":"2024-10-05T10:54:50.009276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:50.011694Z","iopub.execute_input":"2024-10-05T10:54:50.012005Z","iopub.status.idle":"2024-10-05T10:54:50.016460Z","shell.execute_reply.started":"2024-10-05T10:54:50.011963Z","shell.execute_reply":"2024-10-05T10:54:50.015360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in categorical:\n    plt.figure(figsize=(15,6))\n    sns.countplot(x = df[i], data = df, palette = 'hls')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:50.017657Z","iopub.execute_input":"2024-10-05T10:54:50.017957Z","iopub.status.idle":"2024-10-05T10:54:50.426269Z","shell.execute_reply.started":"2024-10-05T10:54:50.017925Z","shell.execute_reply":"2024-10-05T10:54:50.425297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in categorical:\n    plt.figure(figsize=(30,20)) \n    plt.pie(df[i].value_counts(), labels=df[i].value_counts().index, \n            autopct='%1.1f%%', textprops={ 'fontsize': 20,\n                                           'color': 'black',\n                                           'weight': 'bold',\n                                           'family': 'serif' }) \n    hfont = {'fontname':'serif', 'weight': 'bold'}\n    plt.title(i, size=20, **hfont) \n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:50.427657Z","iopub.execute_input":"2024-10-05T10:54:50.427977Z","iopub.status.idle":"2024-10-05T10:54:50.792874Z","shell.execute_reply.started":"2024-10-05T10:54:50.427948Z","shell.execute_reply":"2024-10-05T10:54:50.791799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in numerical_columns:\n    plt.figure(figsize=(15,6))\n    sns.histplot(df[i], kde = True, bins = 20, palette = 'hls')\n    plt.xticks(rotation = 90)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:50.794296Z","iopub.execute_input":"2024-10-05T10:54:50.794640Z","iopub.status.idle":"2024-10-05T10:54:52.566344Z","shell.execute_reply.started":"2024-10-05T10:54:50.794609Z","shell.execute_reply":"2024-10-05T10:54:52.565412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in numerical_columns:\n    plt.figure(figsize=(15,6))\n    sns.distplot(df[i], kde = True, bins = 20)\n    plt.xticks(rotation = 90)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:52.567685Z","iopub.execute_input":"2024-10-05T10:54:52.568109Z","iopub.status.idle":"2024-10-05T10:54:54.126358Z","shell.execute_reply.started":"2024-10-05T10:54:52.568069Z","shell.execute_reply":"2024-10-05T10:54:54.125344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in numerical_columns:\n    plt.figure(figsize=(15,6))\n    sns.boxplot(x = df[i],data = df, palette = 'hls')\n    plt.xticks(rotation = 90)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:54.127721Z","iopub.execute_input":"2024-10-05T10:54:54.128155Z","iopub.status.idle":"2024-10-05T10:54:54.499740Z","shell.execute_reply.started":"2024-10-05T10:54:54.128115Z","shell.execute_reply":"2024-10-05T10:54:54.498667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in numerical_columns:\n    plt.figure(figsize=(15,6))\n    sns.violinplot(x = df[i],data = df, palette = 'hls')\n    plt.xticks(rotation = 90)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:54.501458Z","iopub.execute_input":"2024-10-05T10:54:54.502060Z","iopub.status.idle":"2024-10-05T10:54:55.467513Z","shell.execute_reply.started":"2024-10-05T10:54:54.502023Z","shell.execute_reply":"2024-10-05T10:54:55.466715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in categorical:\n    for j in numerical_columns:\n        plt.figure(figsize=(15,6))\n        sns.barplot(x = df[i], y = df[j], data = df, ci = None, palette = 'hls')\n        plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:55.468809Z","iopub.execute_input":"2024-10-05T10:54:55.469227Z","iopub.status.idle":"2024-10-05T10:54:56.267694Z","shell.execute_reply.started":"2024-10-05T10:54:55.469193Z","shell.execute_reply":"2024-10-05T10:54:56.266789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in categorical:\n    for j in numerical_columns:\n        plt.figure(figsize=(15,6))\n        sns.boxplot(x = df[i], y = df[j], data = df, palette = 'hls')\n        plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:56.278432Z","iopub.execute_input":"2024-10-05T10:54:56.278772Z","iopub.status.idle":"2024-10-05T10:54:56.981085Z","shell.execute_reply.started":"2024-10-05T10:54:56.278741Z","shell.execute_reply":"2024-10-05T10:54:56.980171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in categorical:\n    for j in numerical_columns:\n        plt.figure(figsize=(15,6))\n        sns.violinplot(x = df[i], y = df[j], data = df, palette = 'hls')\n        plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:56.982873Z","iopub.execute_input":"2024-10-05T10:54:56.983238Z","iopub.status.idle":"2024-10-05T10:54:58.286688Z","shell.execute_reply.started":"2024-10-05T10:54:56.983204Z","shell.execute_reply":"2024-10-05T10:54:58.285763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in numerical_columns:\n    for j in numerical_columns:\n        if i != j:\n            plt.figure(figsize=(15,6))\n            sns.scatterplot(x = df[j], y = df[i], data = df, palette = 'hls')\n            plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:58.288062Z","iopub.execute_input":"2024-10-05T10:54:58.288487Z","iopub.status.idle":"2024-10-05T10:54:59.133833Z","shell.execute_reply.started":"2024-10-05T10:54:58.288449Z","shell.execute_reply":"2024-10-05T10:54:59.132917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"real_df = df[df[\"label\"] == \"REAL\"]\nfake_df = df[df[\"label\"] == \"FAKE\"]\nsample_size = 10000\n\nreal_df = real_df.sample(sample_size, random_state=42)\nfake_df = fake_df.sample(sample_size, random_state=42)\n\nsample_meta = pd.concat([real_df, fake_df])","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:59.136891Z","iopub.execute_input":"2024-10-05T10:54:59.137298Z","iopub.status.idle":"2024-10-05T10:54:59.195669Z","shell.execute_reply.started":"2024-10-05T10:54:59.137260Z","shell.execute_reply":"2024-10-05T10:54:59.194870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nTrain_set, Test_set = train_test_split(sample_meta,test_size=0.2,random_state=42,stratify=sample_meta['label'])\nTrain_set, Val_set  = train_test_split(Train_set,test_size=0.3,random_state=42,stratify=Train_set['label'])","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:59.196756Z","iopub.execute_input":"2024-10-05T10:54:59.197050Z","iopub.status.idle":"2024-10-05T10:54:59.436076Z","shell.execute_reply.started":"2024-10-05T10:54:59.197021Z","shell.execute_reply":"2024-10-05T10:54:59.435249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train_set.shape,Val_set.shape,Test_set.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:59.437221Z","iopub.execute_input":"2024-10-05T10:54:59.437517Z","iopub.status.idle":"2024-10-05T10:54:59.445111Z","shell.execute_reply.started":"2024-10-05T10:54:59.437491Z","shell.execute_reply":"2024-10-05T10:54:59.444047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:59.446446Z","iopub.execute_input":"2024-10-05T10:54:59.446830Z","iopub.status.idle":"2024-10-05T10:54:59.696596Z","shell.execute_reply.started":"2024-10-05T10:54:59.446793Z","shell.execute_reply":"2024-10-05T10:54:59.695723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_path = '/kaggle/input/deepfake-faces/faces_224/'\n\nimage_files = os.listdir(image_path)\n\nimage_files.sort()\n\nselected_images = image_files[:9]\n\nplt.figure(figsize=(10, 10))\n\nfor index, image_file in enumerate(selected_images):\n    image = cv2.imread(os.path.join(image_path, image_file))\n\n    plt.subplot(3, 3, index + 1)\n    plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))\n    plt.title(f'Image {index + 1}')\n    plt.axis('off')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:54:59.697871Z","iopub.execute_input":"2024-10-05T10:54:59.698272Z","iopub.status.idle":"2024-10-05T10:55:00.947967Z","shell.execute_reply.started":"2024-10-05T10:54:59.698239Z","shell.execute_reply":"2024-10-05T10:55:00.946870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, image_file in enumerate(image_files[:10]):\n    image = cv2.imread(os.path.join(image_path, image_file))\n    if image is not None:\n        height, width, _ = image.shape\n        print(f\"Resolution of image {i+1}: {width} x {height}\")\n    else:\n        print(f\"Error reading image {i+1}\")\n\nif len(image_files) < 10:\n    print(f\"Only {len(image_files)} images found in the directory.\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:55:00.949432Z","iopub.execute_input":"2024-10-05T10:55:00.950247Z","iopub.status.idle":"2024-10-05T10:55:00.978576Z","shell.execute_reply.started":"2024-10-05T10:55:00.950207Z","shell.execute_reply":"2024-10-05T10:55:00.977591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,15))\nfor cur,i in enumerate(Train_set.index[25:50]):\n    plt.subplot(5,5,cur+1)\n    plt.xticks([])\n    plt.yticks([])\n    plt.grid(False)\n    \n    plt.imshow(cv2.imread('../input/deepfake-faces/faces_224/'+Train_set.loc[i,'videoname'][:-4]+'.jpg'))\n    \n    if(Train_set.loc[i,'label']=='FAKE'):\n        plt.xlabel('FAKE Image')\n    else:\n        plt.xlabel('REAL Image')\n        \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:55:00.979803Z","iopub.execute_input":"2024-10-05T10:55:00.980146Z","iopub.status.idle":"2024-10-05T10:55:03.214739Z","shell.execute_reply.started":"2024-10-05T10:55:00.980118Z","shell.execute_reply":"2024-10-05T10:55:03.213772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def retreive_dataset(set_name):\n    images,labels=[],[]\n    for (img, imclass) in zip(set_name['videoname'], set_name['label']):\n        images.append(cv2.imread('../input/deepfake-faces/faces_224/'+img[:-4]+'.jpg'))\n        if(imclass=='FAKE'):\n            labels.append(1)\n        else:\n            labels.append(0)\n    \n    return np.array(images),np.array(labels)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:55:03.215953Z","iopub.execute_input":"2024-10-05T10:55:03.216304Z","iopub.status.idle":"2024-10-05T10:55:03.223888Z","shell.execute_reply.started":"2024-10-05T10:55:03.216273Z","shell.execute_reply":"2024-10-05T10:55:03.222727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train,y_train=retreive_dataset(Train_set)\nX_val,y_val=retreive_dataset(Val_set)\nX_test,y_test=retreive_dataset(Test_set)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:55:03.225311Z","iopub.execute_input":"2024-10-05T10:55:03.225680Z","iopub.status.idle":"2024-10-05T10:56:46.258853Z","shell.execute_reply.started":"2024-10-05T10:55:03.225647Z","shell.execute_reply":"2024-10-05T10:56:46.258022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import layers, models\nfrom functools import partial","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:56:46.260223Z","iopub.execute_input":"2024-10-05T10:56:46.260567Z","iopub.status.idle":"2024-10-05T10:56:59.579112Z","shell.execute_reply.started":"2024-10-05T10:56:46.260539Z","shell.execute_reply":"2024-10-05T10:56:59.578304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.random.set_seed(42)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:56:59.580532Z","iopub.execute_input":"2024-10-05T10:56:59.581189Z","iopub.status.idle":"2024-10-05T10:56:59.585913Z","shell.execute_reply.started":"2024-10-05T10:56:59.581156Z","shell.execute_reply":"2024-10-05T10:56:59.584878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DefaultConv2D = partial(layers.Conv2D, kernel_size=3, padding=\"same\",\n                        activation=\"relu\", kernel_initializer=\"he_normal\")\n\n# Model Definition\nmodel = models.Sequential([\n    DefaultConv2D(filters=64, kernel_size=7, input_shape=[224, 224, 3]),\n    layers.MaxPooling2D(),\n    layers.BatchNormalization(),\n    DefaultConv2D(filters=128),\n    DefaultConv2D(filters=128),\n    layers.MaxPooling2D(),\n    layers.BatchNormalization(),\n    layers.Flatten(),\n    layers.Dense(units=128, activation=\"relu\",\n                 kernel_initializer=\"he_normal\"),\n    layers.BatchNormalization(),\n    layers.Dropout(0.5),\n    layers.Dense(units=64, activation=\"relu\",\n                 kernel_initializer=\"he_normal\"),\n    layers.BatchNormalization(),\n    layers.Dropout(0.5),\n    layers.Dense(units=1, activation=\"sigmoid\")\n])","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:56:59.587106Z","iopub.execute_input":"2024-10-05T10:56:59.587636Z","iopub.status.idle":"2024-10-05T10:57:01.025019Z","shell.execute_reply.started":"2024-10-05T10:56:59.587610Z","shell.execute_reply":"2024-10-05T10:57:01.024260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"initial_learning_rate = 0.001\nlr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(\n    initial_learning_rate, decay_steps=100000, decay_rate=0.96, staircase=True\n)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:57:01.026299Z","iopub.execute_input":"2024-10-05T10:57:01.026965Z","iopub.status.idle":"2024-10-05T10:57:01.032103Z","shell.execute_reply.started":"2024-10-05T10:57:01.026929Z","shell.execute_reply":"2024-10-05T10:57:01.030956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=lr_schedule),\n              loss=\"binary_crossentropy\", metrics=[\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:57:01.033512Z","iopub.execute_input":"2024-10-05T10:57:01.033890Z","iopub.status.idle":"2024-10-05T10:57:01.075435Z","shell.execute_reply.started":"2024-10-05T10:57:01.033857Z","shell.execute_reply":"2024-10-05T10:57:01.074738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:57:01.076529Z","iopub.execute_input":"2024-10-05T10:57:01.076871Z","iopub.status.idle":"2024-10-05T10:57:01.122315Z","shell.execute_reply.started":"2024-10-05T10:57:01.076836Z","shell.execute_reply":"2024-10-05T10:57:01.121420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    X_train, y_train,\n    epochs=10,  # Adjust as needed\n    batch_size=32,  # Adjust as needed\n    validation_data=(X_val, y_val),\n    verbose=1\n)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T10:57:01.123641Z","iopub.execute_input":"2024-10-05T10:57:01.123977Z","iopub.status.idle":"2024-10-05T11:06:47.397384Z","shell.execute_reply.started":"2024-10-05T10:57:01.123945Z","shell.execute_reply":"2024-10-05T11:06:47.396250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:06:47.403811Z","iopub.execute_input":"2024-10-05T11:06:47.404131Z","iopub.status.idle":"2024-10-05T11:06:54.147811Z","shell.execute_reply.started":"2024-10-05T11:06:47.404104Z","shell.execute_reply":"2024-10-05T11:06:54.146969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, confusion_matrix, classification_report","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:06:54.149096Z","iopub.execute_input":"2024-10-05T11:06:54.149384Z","iopub.status.idle":"2024-10-05T11:06:54.154155Z","shell.execute_reply.started":"2024-10-05T11:06:54.149358Z","shell.execute_reply":"2024-10-05T11:06:54.153171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test_pred_binary = (y_pred > 0.5).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:06:54.155204Z","iopub.execute_input":"2024-10-05T11:06:54.155462Z","iopub.status.idle":"2024-10-05T11:06:54.169017Z","shell.execute_reply.started":"2024-10-05T11:06:54.155440Z","shell.execute_reply":"2024-10-05T11:06:54.168176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_pred = model.predict(X_train)\ny_train_pred_binary = (y_train_pred > 0.5).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:06:54.170114Z","iopub.execute_input":"2024-10-05T11:06:54.170404Z","iopub.status.idle":"2024-10-05T11:07:12.490128Z","shell.execute_reply.started":"2024-10-05T11:06:54.170375Z","shell.execute_reply":"2024-10-05T11:07:12.489245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_accuracy = accuracy_score(y_train, y_train_pred_binary)\nprint(f\"Training Accuracy: {train_accuracy * 100:.2f}%\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:12.491421Z","iopub.execute_input":"2024-10-05T11:07:12.492149Z","iopub.status.idle":"2024-10-05T11:07:12.499666Z","shell.execute_reply.started":"2024-10-05T11:07:12.492109Z","shell.execute_reply":"2024-10-05T11:07:12.498680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_accuracy = accuracy_score(y_test, y_test_pred_binary)\nprint(f\"Test Accuracy: {test_accuracy * 100:.2f}%\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:12.500838Z","iopub.execute_input":"2024-10-05T11:07:12.501144Z","iopub.status.idle":"2024-10-05T11:07:12.511335Z","shell.execute_reply.started":"2024-10-05T11:07:12.501117Z","shell.execute_reply":"2024-10-05T11:07:12.510411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f1 = f1_score(y_test, y_test_pred_binary)\nprint(f\"F1 Score: {f1:.4f}\")\n\nprecision = precision_score(y_test, y_test_pred_binary)\nprint(f\"Precison: {precision:.4f}\")\n\nrecall = recall_score(y_test, y_test_pred_binary)\nprint(f\"Recall: {recall:.4f}\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:12.512551Z","iopub.execute_input":"2024-10-05T11:07:12.513083Z","iopub.status.idle":"2024-10-05T11:07:12.533775Z","shell.execute_reply.started":"2024-10-05T11:07:12.513048Z","shell.execute_reply":"2024-10-05T11:07:12.532868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"conf_matrix = confusion_matrix(y_test, y_test_pred_binary)\nprint(\"Confusion Matrix:\")\nprint(conf_matrix)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:12.534902Z","iopub.execute_input":"2024-10-05T11:07:12.535155Z","iopub.status.idle":"2024-10-05T11:07:12.545912Z","shell.execute_reply.started":"2024-10-05T11:07:12.535132Z","shell.execute_reply":"2024-10-05T11:07:12.545044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import scikitplot as skplt","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:12.547454Z","iopub.execute_input":"2024-10-05T11:07:12.547800Z","iopub.status.idle":"2024-10-05T11:07:12.685417Z","shell.execute_reply.started":"2024-10-05T11:07:12.547767Z","shell.execute_reply":"2024-10-05T11:07:12.684383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"skplt.metrics.plot_confusion_matrix(y_test, y_test_pred_binary, normalize=True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:12.686632Z","iopub.execute_input":"2024-10-05T11:07:12.686933Z","iopub.status.idle":"2024-10-05T11:07:12.968672Z","shell.execute_reply.started":"2024-10-05T11:07:12.686907Z","shell.execute_reply":"2024-10-05T11:07:12.967678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_report = classification_report(y_test, y_test_pred_binary)\nprint(\"Classification Report:\")\nprint(class_report)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:12.970028Z","iopub.execute_input":"2024-10-05T11:07:12.970338Z","iopub.status.idle":"2024-10-05T11:07:12.991365Z","shell.execute_reply.started":"2024-10-05T11:07:12.970311Z","shell.execute_reply":"2024-10-05T11:07:12.990372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 4))\nplt.subplot(1, 2, 1)\nplt.plot(history.history['accuracy'], label='Training Accuracy')\nplt.plot(history.history['val_accuracy'], label='Validation Accuracy')\nplt.title('Training and Validation Accuracy')\nplt.xlabel('Epoch')\nplt.ylabel('Accuracy')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:12.992701Z","iopub.execute_input":"2024-10-05T11:07:12.993127Z","iopub.status.idle":"2024-10-05T11:07:13.259047Z","shell.execute_reply.started":"2024-10-05T11:07:12.993090Z","shell.execute_reply":"2024-10-05T11:07:13.258039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['loss'], label='Training Loss')\nplt.plot(history.history['val_loss'], label='Validation Loss')\nplt.title('Training and Validation Loss')\nplt.xlabel('Epoch')\nplt.ylabel('Loss')\nplt.legend()\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:13.260537Z","iopub.execute_input":"2024-10-05T11:07:13.260948Z","iopub.status.idle":"2024-10-05T11:07:13.550098Z","shell.execute_reply.started":"2024-10-05T11:07:13.260911Z","shell.execute_reply":"2024-10-05T11:07:13.549275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications import ResNet50","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:13.551238Z","iopub.execute_input":"2024-10-05T11:07:13.551520Z","iopub.status.idle":"2024-10-05T11:07:13.556953Z","shell.execute_reply.started":"2024-10-05T11:07:13.551494Z","shell.execute_reply":"2024-10-05T11:07:13.556019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_shape = (224, 224, 3)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:13.558168Z","iopub.execute_input":"2024-10-05T11:07:13.558476Z","iopub.status.idle":"2024-10-05T11:07:13.569990Z","shell.execute_reply.started":"2024-10-05T11:07:13.558451Z","shell.execute_reply":"2024-10-05T11:07:13.569159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model = ResNet50(weights='imagenet', include_top=False, input_shape=input_shape)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:13.571200Z","iopub.execute_input":"2024-10-05T11:07:13.571609Z","iopub.status.idle":"2024-10-05T11:07:16.182571Z","shell.execute_reply.started":"2024-10-05T11:07:13.571578Z","shell.execute_reply":"2024-10-05T11:07:16.181657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for layer in base_model.layers:\n    layer.trainable = False","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:16.183751Z","iopub.execute_input":"2024-10-05T11:07:16.184132Z","iopub.status.idle":"2024-10-05T11:07:16.195784Z","shell.execute_reply.started":"2024-10-05T11:07:16.184102Z","shell.execute_reply":"2024-10-05T11:07:16.195056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_resnet50 = models.Sequential()\nmodel_resnet50.add(base_model)\nmodel_resnet50.add(layers.GlobalAveragePooling2D())\nmodel_resnet50.add(layers.Dense(1, activation='sigmoid'))","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:16.197179Z","iopub.execute_input":"2024-10-05T11:07:16.197559Z","iopub.status.idle":"2024-10-05T11:07:17.305205Z","shell.execute_reply.started":"2024-10-05T11:07:16.197527Z","shell.execute_reply":"2024-10-05T11:07:17.304255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_resnet50.summary()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:17.306332Z","iopub.execute_input":"2024-10-05T11:07:17.306755Z","iopub.status.idle":"2024-10-05T11:07:17.346280Z","shell.execute_reply.started":"2024-10-05T11:07:17.306721Z","shell.execute_reply":"2024-10-05T11:07:17.345439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import optimizers","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:17.347360Z","iopub.execute_input":"2024-10-05T11:07:17.347622Z","iopub.status.idle":"2024-10-05T11:07:17.352085Z","shell.execute_reply.started":"2024-10-05T11:07:17.347597Z","shell.execute_reply":"2024-10-05T11:07:17.351039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_resnet50.compile(optimizer=optimizers.Adam(lr=0.001), loss='binary_crossentropy', metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:17.353277Z","iopub.execute_input":"2024-10-05T11:07:17.353595Z","iopub.status.idle":"2024-10-05T11:07:17.373826Z","shell.execute_reply.started":"2024-10-05T11:07:17.353569Z","shell.execute_reply":"2024-10-05T11:07:17.372830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model_resnet50.fit(\n    X_train, y_train,\n    epochs=10,  \n    validation_data=(X_val, y_val),\n    verbose=1\n)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:07:17.375391Z","iopub.execute_input":"2024-10-05T11:07:17.376086Z","iopub.status.idle":"2024-10-05T11:15:25.571517Z","shell.execute_reply.started":"2024-10-05T11:07:17.376047Z","shell.execute_reply":"2024-10-05T11:15:25.570380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model_resnet50.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:15:25.578812Z","iopub.execute_input":"2024-10-05T11:15:25.579256Z","iopub.status.idle":"2024-10-05T11:15:40.007037Z","shell.execute_reply.started":"2024-10-05T11:15:25.579224Z","shell.execute_reply":"2024-10-05T11:15:40.006220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test_pred_binary = (y_pred > 0.5).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:15:40.008442Z","iopub.execute_input":"2024-10-05T11:15:40.008739Z","iopub.status.idle":"2024-10-05T11:15:40.013764Z","shell.execute_reply.started":"2024-10-05T11:15:40.008712Z","shell.execute_reply":"2024-10-05T11:15:40.012807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_pred = model_resnet50.predict(X_train)\ny_train_pred_binary = (y_train_pred > 0.5).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:15:40.014931Z","iopub.execute_input":"2024-10-05T11:15:40.015277Z","iopub.status.idle":"2024-10-05T11:16:17.183901Z","shell.execute_reply.started":"2024-10-05T11:15:40.015243Z","shell.execute_reply":"2024-10-05T11:16:17.182743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_accuracy = accuracy_score(y_train, y_train_pred_binary)\nprint(f\"Training Accuracy: {train_accuracy * 100:.2f}%\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:16:17.185296Z","iopub.execute_input":"2024-10-05T11:16:17.185625Z","iopub.status.idle":"2024-10-05T11:16:17.194748Z","shell.execute_reply.started":"2024-10-05T11:16:17.185596Z","shell.execute_reply":"2024-10-05T11:16:17.193487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_accuracy = accuracy_score(y_test, y_test_pred_binary)\nprint(f\"Test Accuracy: {test_accuracy * 100:.2f}%\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:16:17.196158Z","iopub.execute_input":"2024-10-05T11:16:17.196555Z","iopub.status.idle":"2024-10-05T11:16:17.205444Z","shell.execute_reply.started":"2024-10-05T11:16:17.196519Z","shell.execute_reply":"2024-10-05T11:16:17.204422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f1 = f1_score(y_test, y_test_pred_binary)\nprint(f\"F1 Score: {f1:.4f}\")\n\nprecision = precision_score(y_test, y_test_pred_binary)\nprint(f\"Precison: {precision:.4f}\")\n\nrecall = recall_score(y_test, y_test_pred_binary)\nprint(f\"Recall: {recall:.4f}\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:16:17.206678Z","iopub.execute_input":"2024-10-05T11:16:17.207066Z","iopub.status.idle":"2024-10-05T11:16:17.228789Z","shell.execute_reply.started":"2024-10-05T11:16:17.207028Z","shell.execute_reply":"2024-10-05T11:16:17.227739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"conf_matrix = confusion_matrix(y_test, y_test_pred_binary)\nprint(\"Confusion Matrix:\")\nprint(conf_matrix)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:16:17.230332Z","iopub.execute_input":"2024-10-05T11:16:17.230756Z","iopub.status.idle":"2024-10-05T11:16:17.239351Z","shell.execute_reply.started":"2024-10-05T11:16:17.230718Z","shell.execute_reply":"2024-10-05T11:16:17.238323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"skplt.metrics.plot_confusion_matrix(y_test, y_test_pred_binary, normalize=True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:16:17.240959Z","iopub.execute_input":"2024-10-05T11:16:17.241433Z","iopub.status.idle":"2024-10-05T11:16:17.467764Z","shell.execute_reply.started":"2024-10-05T11:16:17.241347Z","shell.execute_reply":"2024-10-05T11:16:17.466747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_report = classification_report(y_test, y_test_pred_binary)\nprint(\"Classification Report:\")\nprint(class_report)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:16:17.469002Z","iopub.execute_input":"2024-10-05T11:16:17.469332Z","iopub.status.idle":"2024-10-05T11:16:17.490834Z","shell.execute_reply.started":"2024-10-05T11:16:17.469302Z","shell.execute_reply":"2024-10-05T11:16:17.489789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 4))\nplt.subplot(1, 2, 1)\nplt.plot(history.history['accuracy'], label='Training Accuracy')\nplt.plot(history.history['val_accuracy'], label='Validation Accuracy')\nplt.title('Training and Validation Accuracy')\nplt.xlabel('Epoch')\nplt.ylabel('Accuracy')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:16:17.492171Z","iopub.execute_input":"2024-10-05T11:16:17.492575Z","iopub.status.idle":"2024-10-05T11:16:17.753442Z","shell.execute_reply.started":"2024-10-05T11:16:17.492536Z","shell.execute_reply":"2024-10-05T11:16:17.752471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['loss'], label='Training Loss')\nplt.plot(history.history['val_loss'], label='Validation Loss')\nplt.title('Training and Validation Loss')\nplt.xlabel('Epoch')\nplt.ylabel('Loss')\nplt.legend()\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T11:16:17.754691Z","iopub.execute_input":"2024-10-05T11:16:17.756265Z","iopub.status.idle":"2024-10-05T11:16:18.046147Z","shell.execute_reply.started":"2024-10-05T11:16:17.756234Z","shell.execute_reply":"2024-10-05T11:16:18.045211Z"},"trusted":true},"execution_count":null,"outputs":[]}]}