{"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","execution":{"iopub.status.busy":"2023-12-17T06:40:43.742259Z","iopub.execute_input":"2023-12-17T06:40:43.742777Z","iopub.status.idle":"2023-12-17T06:42:48.180667Z","shell.execute_reply.started":"2023-12-17T06:40:43.742734Z","shell.execute_reply":"2023-12-17T06:42:48.179494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_path = '/kaggle/input/deepfake-faces/metadata.csv'","metadata":{"execution":{"iopub.status.busy":"2023-12-17T06:46:38.661521Z","iopub.execute_input":"2023-12-17T06:46:38.662040Z","iopub.status.idle":"2023-12-17T06:46:38.666495Z","shell.execute_reply.started":"2023-12-17T06:46:38.662008Z","shell.execute_reply":"2023-12-17T06:46:38.665500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(dataset_path)","metadata":{"execution":{"iopub.status.busy":"2023-12-17T06:47:43.593828Z","iopub.execute_input":"2023-12-17T06:47:43.594710Z","iopub.status.idle":"2023-12-17T06:47:43.771242Z","shell.execute_reply.started":"2023-12-17T06:47:43.594669Z","shell.execute_reply":"2023-12-17T06:47:43.770172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-17T06:47:58.586515Z","iopub.execute_input":"2023-12-17T06:47:58.587157Z","iopub.status.idle":"2023-12-17T06:47:58.602537Z","shell.execute_reply.started":"2023-12-17T06:47:58.587124Z","shell.execute_reply":"2023-12-17T06:47:58.601619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.tail()","metadata":{"execution":{"iopub.status.busy":"2023-12-17T06:48:10.430115Z","iopub.execute_input":"2023-12-17T06:48:10.430877Z","iopub.status.idle":"2023-12-17T06:48:10.440962Z","shell.execute_reply.started":"2023-12-17T06:48:10.430842Z","shell.execute_reply":"2023-12-17T06:48:10.440072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2023-12-17T06:48:21.306624Z","iopub.execute_input":"2023-12-17T06:48:21.307341Z","iopub.status.idle":"2023-12-17T06:48:21.313697Z","shell.execute_reply.started":"2023-12-17T06:48:21.307304Z","shell.execute_reply":"2023-12-17T06:48:21.312470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2023-12-17T06:48:31.010461Z","iopub.execute_input":"2023-12-17T06:48:31.011180Z","iopub.status.idle":"2023-12-17T06:48:31.018537Z","shell.execute_reply.started":"2023-12-17T06:48:31.011148Z","shell.execute_reply":"2023-12-17T06:48:31.017615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2023-12-17T06:48:47.878460Z","iopub.execute_input":"2023-12-17T06:48:47.879049Z","iopub.status.idle":"2023-12-17T06:48:47.943572Z","shell.execute_reply.started":"2023-12-17T06:48:47.879016Z","shell.execute_reply":"2023-12-17T06:48:47.942646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-12-17T06:48:56.854732Z","iopub.execute_input":"2023-12-17T06:48:56.855160Z","iopub.status.idle":"2023-12-17T06:48:56.888761Z","shell.execute_reply.started":"2023-12-17T06:48:56.855130Z","shell.execute_reply":"2023-12-17T06:48:56.887828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2023-12-17T07:15:30.018539Z","iopub.execute_input":"2023-12-17T07:15:30.018925Z","iopub.status.idle":"2023-12-17T07:15:30.064733Z","shell.execute_reply.started":"2023-12-17T07:15:30.018893Z","shell.execute_reply":"2023-12-17T07:15:30.063815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.nunique()","metadata":{"execution":{"iopub.status.busy":"2023-12-17T07:16:17.933596Z","iopub.execute_input":"2023-12-17T07:16:17.933964Z","iopub.status.idle":"2023-12-17T07:16:17.981667Z","shell.execute_reply.started":"2023-12-17T07:16:17.933934Z","shell.execute_reply":"2023-12-17T07:16:17.980836Z"},"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":"2023-12-17T07:18:06.840016Z","iopub.execute_input":"2023-12-17T07:18:06.840651Z","iopub.status.idle":"2023-12-17T07:18:06.852406Z","shell.execute_reply.started":"2023-12-17T07:18:06.840618Z","shell.execute_reply":"2023-12-17T07:18:06.851630Z"},"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":"2023-12-17T07:18:44.724595Z","iopub.execute_input":"2023-12-17T07:18:44.725499Z","iopub.status.idle":"2023-12-17T07:18:44.733962Z","shell.execute_reply.started":"2023-12-17T07:18:44.725457Z","shell.execute_reply":"2023-12-17T07:18:44.732814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categorical, non_categorical, discrete, continuous = classify_features(df)","metadata":{"execution":{"iopub.status.busy":"2023-12-17T07:18:59.329824Z","iopub.execute_input":"2023-12-17T07:18:59.330590Z","iopub.status.idle":"2023-12-17T07:18:59.375251Z","shell.execute_reply.started":"2023-12-17T07:18:59.330554Z","shell.execute_reply":"2023-12-17T07:18:59.374489Z"},"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":"2023-12-17T07:19:11.662651Z","iopub.execute_input":"2023-12-17T07:19:11.663536Z","iopub.status.idle":"2023-12-17T07:19:11.668467Z","shell.execute_reply.started":"2023-12-17T07:19:11.663503Z","shell.execute_reply":"2023-12-17T07:19:11.667658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.fillna(\"Not Available\")","metadata":{"execution":{"iopub.status.busy":"2023-12-17T07:19:31.376782Z","iopub.execute_input":"2023-12-17T07:19:31.377625Z","iopub.status.idle":"2023-12-17T07:19:31.417547Z","shell.execute_reply.started":"2023-12-17T07:19:31.377592Z","shell.execute_reply":"2023-12-17T07:19:31.416792Z"},"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":"2023-12-17T07:19:56.264230Z","iopub.execute_input":"2023-12-17T07:19:56.264573Z","iopub.status.idle":"2023-12-17T07:19:56.276309Z","shell.execute_reply.started":"2023-12-17T07:19:56.264544Z","shell.execute_reply":"2023-12-17T07:19:56.275415Z"},"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":"2023-12-17T07:20:10.059315Z","iopub.execute_input":"2023-12-17T07:20:10.059980Z","iopub.status.idle":"2023-12-17T07:20:10.075996Z","shell.execute_reply.started":"2023-12-17T07:20:10.059945Z","shell.execute_reply":"2023-12-17T07:20:10.074966Z"},"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":"2023-12-17T07:21:35.837626Z","iopub.execute_input":"2023-12-17T07:21:35.838440Z","iopub.status.idle":"2023-12-17T07:21:36.324837Z","shell.execute_reply.started":"2023-12-17T07:21:35.838409Z","shell.execute_reply":"2023-12-17T07:21:36.324048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2023-12-17T07:21:48.215200Z","iopub.execute_input":"2023-12-17T07:21:48.215603Z","iopub.status.idle":"2023-12-17T07:21:48.220138Z","shell.execute_reply.started":"2023-12-17T07:21:48.215558Z","shell.execute_reply":"2023-12-17T07:21:48.219258Z"},"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":"2023-12-17T07:22:11.888586Z","iopub.execute_input":"2023-12-17T07:22:11.888958Z","iopub.status.idle":"2023-12-17T07:22:12.297324Z","shell.execute_reply.started":"2023-12-17T07:22:11.888927Z","shell.execute_reply":"2023-12-17T07:22:12.296510Z"},"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":"2023-12-17T07:24:10.675540Z","iopub.execute_input":"2023-12-17T07:24:10.676267Z","iopub.status.idle":"2023-12-17T07:24:11.093472Z","shell.execute_reply.started":"2023-12-17T07:24:10.676229Z","shell.execute_reply":"2023-12-17T07:24:11.092533Z"},"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":"2023-12-17T07:24:46.068820Z","iopub.execute_input":"2023-12-17T07:24:46.069175Z","iopub.status.idle":"2023-12-17T07:24:47.673622Z","shell.execute_reply.started":"2023-12-17T07:24:46.069146Z","shell.execute_reply":"2023-12-17T07:24:47.672755Z"},"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":"2023-12-17T07:25:08.218691Z","iopub.execute_input":"2023-12-17T07:25:08.219079Z","iopub.status.idle":"2023-12-17T07:25:09.595744Z","shell.execute_reply.started":"2023-12-17T07:25:08.219048Z","shell.execute_reply":"2023-12-17T07:25:09.594900Z"},"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":"2023-12-17T07:25:34.411612Z","iopub.execute_input":"2023-12-17T07:25:34.412442Z","iopub.status.idle":"2023-12-17T07:25:34.754952Z","shell.execute_reply.started":"2023-12-17T07:25:34.412406Z","shell.execute_reply":"2023-12-17T07:25:34.753005Z"},"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":"2023-12-17T07:26:03.671733Z","iopub.execute_input":"2023-12-17T07:26:03.672121Z","iopub.status.idle":"2023-12-17T07:26:04.710675Z","shell.execute_reply.started":"2023-12-17T07:26:03.672089Z","shell.execute_reply":"2023-12-17T07:26:04.709854Z"},"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":"2023-12-17T07:27:19.842840Z","iopub.execute_input":"2023-12-17T07:27:19.843888Z","iopub.status.idle":"2023-12-17T07:27:20.511969Z","shell.execute_reply.started":"2023-12-17T07:27:19.843851Z","shell.execute_reply":"2023-12-17T07:27:20.511065Z"},"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":"2023-12-17T07:28:00.485550Z","iopub.execute_input":"2023-12-17T07:28:00.486159Z","iopub.status.idle":"2023-12-17T07:28:01.164866Z","shell.execute_reply.started":"2023-12-17T07:28:00.486123Z","shell.execute_reply":"2023-12-17T07:28:01.163902Z"},"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":"2023-12-17T07:28:12.353935Z","iopub.execute_input":"2023-12-17T07:28:12.354617Z","iopub.status.idle":"2023-12-17T07:28:13.764885Z","shell.execute_reply.started":"2023-12-17T07:28:12.354586Z","shell.execute_reply":"2023-12-17T07:28:13.764038Z"},"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":"2023-12-17T07:28:36.697459Z","iopub.execute_input":"2023-12-17T07:28:36.698346Z","iopub.status.idle":"2023-12-17T07:28:37.592968Z","shell.execute_reply.started":"2023-12-17T07:28:36.698311Z","shell.execute_reply":"2023-12-17T07:28:37.592094Z"},"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":"2023-12-17T07:32:20.491183Z","iopub.execute_input":"2023-12-17T07:32:20.492015Z","iopub.status.idle":"2023-12-17T07:32:20.547552Z","shell.execute_reply.started":"2023-12-17T07:32:20.491976Z","shell.execute_reply":"2023-12-17T07:32:20.546535Z"},"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":"2023-12-17T07:33:17.849041Z","iopub.execute_input":"2023-12-17T07:33:17.849968Z","iopub.status.idle":"2023-12-17T07:33:18.082747Z","shell.execute_reply.started":"2023-12-17T07:33:17.849931Z","shell.execute_reply":"2023-12-17T07:33:18.081842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train_set.shape,Val_set.shape,Test_set.shape","metadata":{"execution":{"iopub.status.busy":"2023-12-17T07:36:24.750798Z","iopub.execute_input":"2023-12-17T07:36:24.751148Z","iopub.status.idle":"2023-12-17T07:36:24.757666Z","shell.execute_reply.started":"2023-12-17T07:36:24.751123Z","shell.execute_reply":"2023-12-17T07:36:24.756790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2","metadata":{"execution":{"iopub.status.busy":"2023-12-17T07:37:56.162134Z","iopub.execute_input":"2023-12-17T07:37:56.162494Z","iopub.status.idle":"2023-12-17T07:37:56.443751Z","shell.execute_reply.started":"2023-12-17T07:37:56.162463Z","shell.execute_reply":"2023-12-17T07:37:56.443004Z"},"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":"2023-12-17T07:41:00.529896Z","iopub.execute_input":"2023-12-17T07:41:00.530836Z","iopub.status.idle":"2023-12-17T07:41:01.603227Z","shell.execute_reply.started":"2023-12-17T07:41:00.530791Z","shell.execute_reply":"2023-12-17T07:41:01.602283Z"},"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":"2023-12-17T08:09:06.477737Z","iopub.execute_input":"2023-12-17T08:09:06.478144Z","iopub.status.idle":"2023-12-17T08:09:06.614935Z","shell.execute_reply.started":"2023-12-17T08:09:06.478113Z","shell.execute_reply":"2023-12-17T08:09:06.613993Z"},"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":"2023-12-17T07:37:58.642185Z","iopub.execute_input":"2023-12-17T07:37:58.642539Z","iopub.status.idle":"2023-12-17T07:38:01.019925Z","shell.execute_reply.started":"2023-12-17T07:37:58.642511Z","shell.execute_reply":"2023-12-17T07:38:01.019035Z"},"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":"2023-12-17T07:48:02.511341Z","iopub.execute_input":"2023-12-17T07:48:02.511746Z","iopub.status.idle":"2023-12-17T07:48:02.518356Z","shell.execute_reply.started":"2023-12-17T07:48:02.511716Z","shell.execute_reply":"2023-12-17T07:48:02.517401Z"},"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":"2023-12-17T07:48:12.119451Z","iopub.execute_input":"2023-12-17T07:48:12.119833Z","iopub.status.idle":"2023-12-17T07:50:44.421600Z","shell.execute_reply.started":"2023-12-17T07:48:12.119799Z","shell.execute_reply":"2023-12-17T07:50:44.420760Z"},"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":"2023-12-17T09:17:42.312437Z","iopub.execute_input":"2023-12-17T09:17:42.313206Z","iopub.status.idle":"2023-12-17T09:17:54.944875Z","shell.execute_reply.started":"2023-12-17T09:17:42.313172Z","shell.execute_reply":"2023-12-17T09:17:54.944041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.random.set_seed(42)","metadata":{"execution":{"iopub.status.busy":"2023-12-17T09:18:03.738543Z","iopub.execute_input":"2023-12-17T09:18:03.739477Z","iopub.status.idle":"2023-12-17T09:18:03.744012Z","shell.execute_reply.started":"2023-12-17T09:18:03.739439Z","shell.execute_reply":"2023-12-17T09:18:03.743021Z"},"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":"2023-12-17T09:18:29.204574Z","iopub.execute_input":"2023-12-17T09:18:29.205462Z","iopub.status.idle":"2023-12-17T09:18:33.494703Z","shell.execute_reply.started":"2023-12-17T09:18:29.205426Z","shell.execute_reply":"2023-12-17T09:18:33.493926Z"},"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":"2023-12-17T09:18:49.776194Z","iopub.execute_input":"2023-12-17T09:18:49.776553Z","iopub.status.idle":"2023-12-17T09:18:49.781450Z","shell.execute_reply.started":"2023-12-17T09:18:49.776522Z","shell.execute_reply":"2023-12-17T09:18:49.780580Z"},"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":"2023-12-17T09:19:01.523729Z","iopub.execute_input":"2023-12-17T09:19:01.524698Z","iopub.status.idle":"2023-12-17T09:19:01.561907Z","shell.execute_reply.started":"2023-12-17T09:19:01.524665Z","shell.execute_reply":"2023-12-17T09:19:01.561157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-12-17T09:19:09.769682Z","iopub.execute_input":"2023-12-17T09:19:09.770090Z","iopub.status.idle":"2023-12-17T09:19:09.814010Z","shell.execute_reply.started":"2023-12-17T09:19:09.770061Z","shell.execute_reply":"2023-12-17T09:19:09.813126Z"},"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":"2023-12-17T09:20:10.303169Z","iopub.execute_input":"2023-12-17T09:20:10.303531Z","iopub.status.idle":"2023-12-17T09:30:55.064928Z","shell.execute_reply.started":"2023-12-17T09:20:10.303501Z","shell.execute_reply":"2023-12-17T09:30:55.063833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-12-17T09:31:19.679518Z","iopub.execute_input":"2023-12-17T09:31:19.680155Z","iopub.status.idle":"2023-12-17T09:31:27.217385Z","shell.execute_reply.started":"2023-12-17T09:31:19.680120Z","shell.execute_reply":"2023-12-17T09:31:27.216463Z"},"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":"2023-12-17T09:32:55.539987Z","iopub.execute_input":"2023-12-17T09:32:55.540388Z","iopub.status.idle":"2023-12-17T09:32:55.545571Z","shell.execute_reply.started":"2023-12-17T09:32:55.540354Z","shell.execute_reply":"2023-12-17T09:32:55.544522Z"},"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":"2023-12-17T09:33:56.525442Z","iopub.execute_input":"2023-12-17T09:33:56.526103Z","iopub.status.idle":"2023-12-17T09:33:56.530895Z","shell.execute_reply.started":"2023-12-17T09:33:56.526069Z","shell.execute_reply":"2023-12-17T09:33:56.529676Z"},"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":"2023-12-17T09:34:18.752954Z","iopub.execute_input":"2023-12-17T09:34:18.753349Z","iopub.status.idle":"2023-12-17T09:34:39.285049Z","shell.execute_reply.started":"2023-12-17T09:34:18.753317Z","shell.execute_reply":"2023-12-17T09:34:39.283951Z"},"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":"2023-12-17T09:34:55.753950Z","iopub.execute_input":"2023-12-17T09:34:55.754279Z","iopub.status.idle":"2023-12-17T09:34:55.761890Z","shell.execute_reply.started":"2023-12-17T09:34:55.754253Z","shell.execute_reply":"2023-12-17T09:34:55.760855Z"},"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":"2023-12-17T09:35:07.138034Z","iopub.execute_input":"2023-12-17T09:35:07.138968Z","iopub.status.idle":"2023-12-17T09:35:07.145247Z","shell.execute_reply.started":"2023-12-17T09:35:07.138933Z","shell.execute_reply":"2023-12-17T09:35:07.144235Z"},"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":"2023-12-17T09:35:37.537386Z","iopub.execute_input":"2023-12-17T09:35:37.537823Z","iopub.status.idle":"2023-12-17T09:35:37.558693Z","shell.execute_reply.started":"2023-12-17T09:35:37.537760Z","shell.execute_reply":"2023-12-17T09:35:37.557639Z"},"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":"2023-12-17T09:35:51.432909Z","iopub.execute_input":"2023-12-17T09:35:51.433835Z","iopub.status.idle":"2023-12-17T09:35:51.445056Z","shell.execute_reply.started":"2023-12-17T09:35:51.433791Z","shell.execute_reply":"2023-12-17T09:35:51.444002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import scikitplot as skplt","metadata":{"execution":{"iopub.status.busy":"2023-12-17T09:36:53.354664Z","iopub.execute_input":"2023-12-17T09:36:53.355345Z","iopub.status.idle":"2023-12-17T09:36:53.592653Z","shell.execute_reply.started":"2023-12-17T09:36:53.355313Z","shell.execute_reply":"2023-12-17T09:36:53.591670Z"},"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":"2023-12-17T09:37:38.162468Z","iopub.execute_input":"2023-12-17T09:37:38.162880Z","iopub.status.idle":"2023-12-17T09:37:38.452778Z","shell.execute_reply.started":"2023-12-17T09:37:38.162844Z","shell.execute_reply":"2023-12-17T09:37:38.451827Z"},"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":"2023-12-17T09:36:03.859087Z","iopub.execute_input":"2023-12-17T09:36:03.859793Z","iopub.status.idle":"2023-12-17T09:36:03.879512Z","shell.execute_reply.started":"2023-12-17T09:36:03.859742Z","shell.execute_reply":"2023-12-17T09:36:03.878715Z"},"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":"2023-12-17T09:41:19.609264Z","iopub.execute_input":"2023-12-17T09:41:19.609691Z","iopub.status.idle":"2023-12-17T09:41:19.940269Z","shell.execute_reply.started":"2023-12-17T09:41:19.609653Z","shell.execute_reply":"2023-12-17T09:41:19.938414Z"},"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":"2023-12-17T09:41:46.089202Z","iopub.execute_input":"2023-12-17T09:41:46.090487Z","iopub.status.idle":"2023-12-17T09:41:46.500339Z","shell.execute_reply.started":"2023-12-17T09:41:46.090449Z","shell.execute_reply":"2023-12-17T09:41:46.499392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications import ResNet50","metadata":{"execution":{"iopub.status.busy":"2023-12-17T09:43:13.575517Z","iopub.execute_input":"2023-12-17T09:43:13.576009Z","iopub.status.idle":"2023-12-17T09:43:13.581100Z","shell.execute_reply.started":"2023-12-17T09:43:13.575976Z","shell.execute_reply":"2023-12-17T09:43:13.580263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_shape = (224, 224, 3)","metadata":{"execution":{"iopub.status.busy":"2023-12-17T09:44:14.684253Z","iopub.execute_input":"2023-12-17T09:44:14.684616Z","iopub.status.idle":"2023-12-17T09:44:14.689149Z","shell.execute_reply.started":"2023-12-17T09:44:14.684585Z","shell.execute_reply":"2023-12-17T09:44:14.688068Z"},"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":"2023-12-17T09:44:16.531074Z","iopub.execute_input":"2023-12-17T09:44:16.531489Z","iopub.status.idle":"2023-12-17T09:44:18.929281Z","shell.execute_reply.started":"2023-12-17T09:44:16.531458Z","shell.execute_reply":"2023-12-17T09:44:18.928454Z"},"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":"2023-12-17T09:44:39.261871Z","iopub.execute_input":"2023-12-17T09:44:39.262246Z","iopub.status.idle":"2023-12-17T09:44:39.272864Z","shell.execute_reply.started":"2023-12-17T09:44:39.262213Z","shell.execute_reply":"2023-12-17T09:44:39.271945Z"},"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":"2023-12-17T09:45:45.587951Z","iopub.execute_input":"2023-12-17T09:45:45.588342Z","iopub.status.idle":"2023-12-17T09:45:46.142214Z","shell.execute_reply.started":"2023-12-17T09:45:45.588309Z","shell.execute_reply":"2023-12-17T09:45:46.141375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_resnet50.summary()","metadata":{"execution":{"iopub.status.busy":"2023-12-17T09:46:05.843055Z","iopub.execute_input":"2023-12-17T09:46:05.843427Z","iopub.status.idle":"2023-12-17T09:46:05.879256Z","shell.execute_reply.started":"2023-12-17T09:46:05.843398Z","shell.execute_reply":"2023-12-17T09:46:05.878352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import optimizers","metadata":{"execution":{"iopub.status.busy":"2023-12-17T09:47:04.848178Z","iopub.execute_input":"2023-12-17T09:47:04.848558Z","iopub.status.idle":"2023-12-17T09:47:04.853174Z","shell.execute_reply.started":"2023-12-17T09:47:04.848526Z","shell.execute_reply":"2023-12-17T09:47:04.852081Z"},"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":"2023-12-17T09:47:10.295197Z","iopub.execute_input":"2023-12-17T09:47:10.295562Z","iopub.status.idle":"2023-12-17T09:47:10.312558Z","shell.execute_reply.started":"2023-12-17T09:47:10.295531Z","shell.execute_reply":"2023-12-17T09:47:10.311556Z"},"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":"2023-12-17T09:48:17.819512Z","iopub.execute_input":"2023-12-17T09:48:17.819884Z","iopub.status.idle":"2023-12-17T09:56:56.119457Z","shell.execute_reply.started":"2023-12-17T09:48:17.819852Z","shell.execute_reply":"2023-12-17T09:56:56.118455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model_resnet50.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-12-17T09:57:22.509876Z","iopub.execute_input":"2023-12-17T09:57:22.510221Z","iopub.status.idle":"2023-12-17T09:57:37.242659Z","shell.execute_reply.started":"2023-12-17T09:57:22.510195Z","shell.execute_reply":"2023-12-17T09:57:37.241702Z"},"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":"2023-12-17T09:57:47.592142Z","iopub.execute_input":"2023-12-17T09:57:47.592478Z","iopub.status.idle":"2023-12-17T09:57:47.597207Z","shell.execute_reply.started":"2023-12-17T09:57:47.592452Z","shell.execute_reply":"2023-12-17T09:57:47.596147Z"},"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":"2023-12-17T09:58:09.965964Z","iopub.execute_input":"2023-12-17T09:58:09.966676Z","iopub.status.idle":"2023-12-17T09:58:50.544573Z","shell.execute_reply.started":"2023-12-17T09:58:09.966642Z","shell.execute_reply":"2023-12-17T09:58:50.543719Z"},"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":"2023-12-17T09:59:18.855418Z","iopub.execute_input":"2023-12-17T09:59:18.856310Z","iopub.status.idle":"2023-12-17T09:59:18.863709Z","shell.execute_reply.started":"2023-12-17T09:59:18.856276Z","shell.execute_reply":"2023-12-17T09:59:18.862643Z"},"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":"2023-12-17T09:59:38.252948Z","iopub.execute_input":"2023-12-17T09:59:38.253332Z","iopub.status.idle":"2023-12-17T09:59:38.260476Z","shell.execute_reply.started":"2023-12-17T09:59:38.253300Z","shell.execute_reply":"2023-12-17T09:59:38.259414Z"},"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":"2023-12-17T10:00:04.988674Z","iopub.execute_input":"2023-12-17T10:00:04.989590Z","iopub.status.idle":"2023-12-17T10:00:05.007119Z","shell.execute_reply.started":"2023-12-17T10:00:04.989557Z","shell.execute_reply":"2023-12-17T10:00:05.006152Z"},"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":"2023-12-17T10:00:21.692139Z","iopub.execute_input":"2023-12-17T10:00:21.692755Z","iopub.status.idle":"2023-12-17T10:00:21.700785Z","shell.execute_reply.started":"2023-12-17T10:00:21.692713Z","shell.execute_reply":"2023-12-17T10:00:21.699831Z"},"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":"2023-12-17T10:00:34.248570Z","iopub.execute_input":"2023-12-17T10:00:34.248949Z","iopub.status.idle":"2023-12-17T10:00:34.520638Z","shell.execute_reply.started":"2023-12-17T10:00:34.248916Z","shell.execute_reply":"2023-12-17T10:00:34.519788Z"},"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":"2023-12-17T10:00:49.064468Z","iopub.execute_input":"2023-12-17T10:00:49.065225Z","iopub.status.idle":"2023-12-17T10:00:49.084526Z","shell.execute_reply.started":"2023-12-17T10:00:49.065190Z","shell.execute_reply":"2023-12-17T10:00:49.083579Z"},"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":"2023-12-17T10:01:01.786464Z","iopub.execute_input":"2023-12-17T10:01:01.787391Z","iopub.status.idle":"2023-12-17T10:01:02.085745Z","shell.execute_reply.started":"2023-12-17T10:01:01.787346Z","shell.execute_reply":"2023-12-17T10:01:02.084689Z"},"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":"2023-12-17T10:01:17.986311Z","iopub.execute_input":"2023-12-17T10:01:17.986705Z","iopub.status.idle":"2023-12-17T10:01:18.266697Z","shell.execute_reply.started":"2023-12-17T10:01:17.986673Z","shell.execute_reply":"2023-12-17T10:01:18.265757Z"},"trusted":true},"execution_count":null,"outputs":[]}]}