{"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":"2024-03-14T09:04:24.971783Z","iopub.execute_input":"2024-03-14T09:04:24.972084Z","iopub.status.idle":"2024-03-14T09:05:50.678902Z","shell.execute_reply.started":"2024-03-14T09:04:24.972058Z","shell.execute_reply":"2024-03-14T09:05:50.677911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_path = '/kaggle/input/deepfake-faces/metadata.csv'","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:50.680508Z","iopub.execute_input":"2024-03-14T09:05:50.680908Z","iopub.status.idle":"2024-03-14T09:05:50.684963Z","shell.execute_reply.started":"2024-03-14T09:05:50.680883Z","shell.execute_reply":"2024-03-14T09:05:50.684086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(dataset_path)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:50.686224Z","iopub.execute_input":"2024-03-14T09:05:50.686495Z","iopub.status.idle":"2024-03-14T09:05:50.867727Z","shell.execute_reply.started":"2024-03-14T09:05:50.686471Z","shell.execute_reply":"2024-03-14T09:05:50.867003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:50.870261Z","iopub.execute_input":"2024-03-14T09:05:50.871034Z","iopub.status.idle":"2024-03-14T09:05:50.890594Z","shell.execute_reply.started":"2024-03-14T09:05:50.870995Z","shell.execute_reply":"2024-03-14T09:05:50.889623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.tail()","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:50.891831Z","iopub.execute_input":"2024-03-14T09:05:50.892148Z","iopub.status.idle":"2024-03-14T09:05:50.905415Z","shell.execute_reply.started":"2024-03-14T09:05:50.892120Z","shell.execute_reply":"2024-03-14T09:05:50.904405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:50.906637Z","iopub.execute_input":"2024-03-14T09:05:50.907024Z","iopub.status.idle":"2024-03-14T09:05:50.914487Z","shell.execute_reply.started":"2024-03-14T09:05:50.906999Z","shell.execute_reply":"2024-03-14T09:05:50.913433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:50.915570Z","iopub.execute_input":"2024-03-14T09:05:50.915854Z","iopub.status.idle":"2024-03-14T09:05:50.925339Z","shell.execute_reply.started":"2024-03-14T09:05:50.915831Z","shell.execute_reply":"2024-03-14T09:05:50.924352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:50.926433Z","iopub.execute_input":"2024-03-14T09:05:50.927185Z","iopub.status.idle":"2024-03-14T09:05:50.987567Z","shell.execute_reply.started":"2024-03-14T09:05:50.927160Z","shell.execute_reply":"2024-03-14T09:05:50.986536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:50.988706Z","iopub.execute_input":"2024-03-14T09:05:50.989019Z","iopub.status.idle":"2024-03-14T09:05:51.021700Z","shell.execute_reply.started":"2024-03-14T09:05:50.988991Z","shell.execute_reply":"2024-03-14T09:05:51.020806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:51.026072Z","iopub.execute_input":"2024-03-14T09:05:51.026350Z","iopub.status.idle":"2024-03-14T09:05:51.068929Z","shell.execute_reply.started":"2024-03-14T09:05:51.026326Z","shell.execute_reply":"2024-03-14T09:05:51.067895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.nunique()","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:51.070112Z","iopub.execute_input":"2024-03-14T09:05:51.070456Z","iopub.status.idle":"2024-03-14T09:05:51.120601Z","shell.execute_reply.started":"2024-03-14T09:05:51.070428Z","shell.execute_reply":"2024-03-14T09:05:51.119777Z"},"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-03-14T09:05:51.121723Z","iopub.execute_input":"2024-03-14T09:05:51.122004Z","iopub.status.idle":"2024-03-14T09:05:51.131368Z","shell.execute_reply.started":"2024-03-14T09:05:51.121980Z","shell.execute_reply":"2024-03-14T09:05:51.130304Z"},"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-03-14T09:05:51.132413Z","iopub.execute_input":"2024-03-14T09:05:51.132699Z","iopub.status.idle":"2024-03-14T09:05:51.140490Z","shell.execute_reply.started":"2024-03-14T09:05:51.132676Z","shell.execute_reply":"2024-03-14T09:05:51.139550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categorical, non_categorical, discrete, continuous = classify_features(df)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:51.141834Z","iopub.execute_input":"2024-03-14T09:05:51.142108Z","iopub.status.idle":"2024-03-14T09:05:51.195677Z","shell.execute_reply.started":"2024-03-14T09:05:51.142083Z","shell.execute_reply":"2024-03-14T09:05:51.194945Z"},"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-03-14T09:05:51.196835Z","iopub.execute_input":"2024-03-14T09:05:51.197105Z","iopub.status.idle":"2024-03-14T09:05:51.202321Z","shell.execute_reply.started":"2024-03-14T09:05:51.197081Z","shell.execute_reply":"2024-03-14T09:05:51.201448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.fillna(\"Not Available\")","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:51.203533Z","iopub.execute_input":"2024-03-14T09:05:51.203866Z","iopub.status.idle":"2024-03-14T09:05:51.247646Z","shell.execute_reply.started":"2024-03-14T09:05:51.203842Z","shell.execute_reply":"2024-03-14T09:05:51.246893Z"},"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-03-14T09:05:51.248769Z","iopub.execute_input":"2024-03-14T09:05:51.249064Z","iopub.status.idle":"2024-03-14T09:05:51.260785Z","shell.execute_reply.started":"2024-03-14T09:05:51.249038Z","shell.execute_reply":"2024-03-14T09:05:51.259707Z"},"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-03-14T09:05:51.262012Z","iopub.execute_input":"2024-03-14T09:05:51.262333Z","iopub.status.idle":"2024-03-14T09:05:51.280820Z","shell.execute_reply.started":"2024-03-14T09:05:51.262285Z","shell.execute_reply":"2024-03-14T09:05:51.279830Z"},"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-03-14T09:05:51.282196Z","iopub.execute_input":"2024-03-14T09:05:51.282876Z","iopub.status.idle":"2024-03-14T09:05:51.802320Z","shell.execute_reply.started":"2024-03-14T09:05:51.282835Z","shell.execute_reply":"2024-03-14T09:05:51.801508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:05:51.803636Z","iopub.execute_input":"2024-03-14T09:05:51.804015Z","iopub.status.idle":"2024-03-14T09:05:51.808889Z","shell.execute_reply.started":"2024-03-14T09:05:51.803982Z","shell.execute_reply":"2024-03-14T09:05:51.807808Z"},"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-03-14T09:05:51.810390Z","iopub.execute_input":"2024-03-14T09:05:51.810792Z","iopub.status.idle":"2024-03-14T09:05:52.218564Z","shell.execute_reply.started":"2024-03-14T09:05:51.810730Z","shell.execute_reply":"2024-03-14T09:05:52.217530Z"},"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-03-14T09:05:52.219761Z","iopub.execute_input":"2024-03-14T09:05:52.220045Z","iopub.status.idle":"2024-03-14T09:05:52.692526Z","shell.execute_reply.started":"2024-03-14T09:05:52.220020Z","shell.execute_reply":"2024-03-14T09:05:52.691648Z"},"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-03-14T09:05:52.693847Z","iopub.execute_input":"2024-03-14T09:05:52.694158Z","iopub.status.idle":"2024-03-14T09:05:54.413179Z","shell.execute_reply.started":"2024-03-14T09:05:52.694133Z","shell.execute_reply":"2024-03-14T09:05:54.412228Z"},"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-03-14T09:05:54.414544Z","iopub.execute_input":"2024-03-14T09:05:54.414993Z","iopub.status.idle":"2024-03-14T09:05:55.964892Z","shell.execute_reply.started":"2024-03-14T09:05:54.414959Z","shell.execute_reply":"2024-03-14T09:05:55.964036Z"},"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-03-14T09:05:55.966215Z","iopub.execute_input":"2024-03-14T09:05:55.966875Z","iopub.status.idle":"2024-03-14T09:05:56.460405Z","shell.execute_reply.started":"2024-03-14T09:05:55.966838Z","shell.execute_reply":"2024-03-14T09:05:56.459351Z"},"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-03-14T09:05:56.461675Z","iopub.execute_input":"2024-03-14T09:05:56.462000Z","iopub.status.idle":"2024-03-14T09:05:57.526985Z","shell.execute_reply.started":"2024-03-14T09:05:56.461971Z","shell.execute_reply":"2024-03-14T09:05:57.525943Z"},"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-03-14T09:05:57.528212Z","iopub.execute_input":"2024-03-14T09:05:57.528510Z","iopub.status.idle":"2024-03-14T09:05:58.224199Z","shell.execute_reply.started":"2024-03-14T09:05:57.528484Z","shell.execute_reply":"2024-03-14T09:05:58.223265Z"},"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-03-14T09:32:49.434375Z","iopub.execute_input":"2024-03-14T09:32:49.435269Z","iopub.status.idle":"2024-03-14T09:32:50.151806Z","shell.execute_reply.started":"2024-03-14T09:32:49.435228Z","shell.execute_reply":"2024-03-14T09:32:50.150714Z"},"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-03-14T09:32:58.473302Z","iopub.execute_input":"2024-03-14T09:32:58.474249Z","iopub.status.idle":"2024-03-14T09:32:59.900339Z","shell.execute_reply.started":"2024-03-14T09:32:58.474205Z","shell.execute_reply":"2024-03-14T09:32:59.899434Z"},"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-03-14T09:33:10.573597Z","iopub.execute_input":"2024-03-14T09:33:10.573942Z","iopub.status.idle":"2024-03-14T09:33:11.381176Z","shell.execute_reply.started":"2024-03-14T09:33:10.573915Z","shell.execute_reply":"2024-03-14T09:33:11.380191Z"},"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-03-14T09:33:16.048165Z","iopub.execute_input":"2024-03-14T09:33:16.048527Z","iopub.status.idle":"2024-03-14T09:33:16.102991Z","shell.execute_reply.started":"2024-03-14T09:33:16.048498Z","shell.execute_reply":"2024-03-14T09:33:16.102248Z"},"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-03-14T09:33:21.998417Z","iopub.execute_input":"2024-03-14T09:33:21.998834Z","iopub.status.idle":"2024-03-14T09:33:22.323194Z","shell.execute_reply.started":"2024-03-14T09:33:21.998798Z","shell.execute_reply":"2024-03-14T09:33:22.322139Z"},"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-03-14T09:33:30.143404Z","iopub.execute_input":"2024-03-14T09:33:30.143809Z","iopub.status.idle":"2024-03-14T09:33:30.150768Z","shell.execute_reply.started":"2024-03-14T09:33:30.143771Z","shell.execute_reply":"2024-03-14T09:33:30.149647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:33:30.569465Z","iopub.execute_input":"2024-03-14T09:33:30.569940Z","iopub.status.idle":"2024-03-14T09:33:30.832358Z","shell.execute_reply.started":"2024-03-14T09:33:30.569907Z","shell.execute_reply":"2024-03-14T09:33:30.831495Z"},"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-03-14T09:33:31.729408Z","iopub.execute_input":"2024-03-14T09:33:31.729851Z","iopub.status.idle":"2024-03-14T09:33:32.846798Z","shell.execute_reply.started":"2024-03-14T09:33:31.729804Z","shell.execute_reply":"2024-03-14T09:33:32.845960Z"},"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-03-14T09:33:32.848804Z","iopub.execute_input":"2024-03-14T09:33:32.849605Z","iopub.status.idle":"2024-03-14T09:33:32.874115Z","shell.execute_reply.started":"2024-03-14T09:33:32.849569Z","shell.execute_reply":"2024-03-14T09:33:32.873319Z"},"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-03-14T09:33:32.875082Z","iopub.execute_input":"2024-03-14T09:33:32.875324Z","iopub.status.idle":"2024-03-14T09:33:34.789618Z","shell.execute_reply.started":"2024-03-14T09:33:32.875302Z","shell.execute_reply":"2024-03-14T09:33:34.788648Z"},"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-03-14T09:33:34.790956Z","iopub.execute_input":"2024-03-14T09:33:34.791247Z","iopub.status.idle":"2024-03-14T09:33:34.797281Z","shell.execute_reply.started":"2024-03-14T09:33:34.791223Z","shell.execute_reply":"2024-03-14T09:33:34.796447Z"},"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-03-14T09:41:40.335922Z","iopub.execute_input":"2024-03-14T09:41:40.336537Z","iopub.status.idle":"2024-03-14T09:42:12.580446Z","shell.execute_reply.started":"2024-03-14T09:41:40.336501Z","shell.execute_reply":"2024-03-14T09:42:12.579069Z"},"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-03-14T09:35:18.552583Z","iopub.execute_input":"2024-03-14T09:35:18.552992Z","iopub.status.idle":"2024-03-14T09:35:31.513192Z","shell.execute_reply.started":"2024-03-14T09:35:18.552955Z","shell.execute_reply":"2024-03-14T09:35:31.512190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.random.set_seed(42)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:35:31.514405Z","iopub.execute_input":"2024-03-14T09:35:31.514994Z","iopub.status.idle":"2024-03-14T09:35:31.519573Z","shell.execute_reply.started":"2024-03-14T09:35:31.514951Z","shell.execute_reply":"2024-03-14T09:35:31.518500Z"},"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-03-14T09:35:31.521065Z","iopub.execute_input":"2024-03-14T09:35:31.521646Z","iopub.status.idle":"2024-03-14T09:35:32.707623Z","shell.execute_reply.started":"2024-03-14T09:35:31.521612Z","shell.execute_reply":"2024-03-14T09:35:32.706867Z"},"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-03-14T09:35:32.708695Z","iopub.execute_input":"2024-03-14T09:35:32.708975Z","iopub.status.idle":"2024-03-14T09:35:32.713783Z","shell.execute_reply.started":"2024-03-14T09:35:32.708951Z","shell.execute_reply":"2024-03-14T09:35:32.712773Z"},"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-03-14T09:35:32.714754Z","iopub.execute_input":"2024-03-14T09:35:32.715045Z","iopub.status.idle":"2024-03-14T09:35:32.757347Z","shell.execute_reply.started":"2024-03-14T09:35:32.715022Z","shell.execute_reply":"2024-03-14T09:35:32.756086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:35:32.758700Z","iopub.execute_input":"2024-03-14T09:35:32.759009Z","iopub.status.idle":"2024-03-14T09:35:32.818197Z","shell.execute_reply.started":"2024-03-14T09:35:32.758983Z","shell.execute_reply":"2024-03-14T09:35:32.817382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    X_train, y_train,\n    epochs=5,  # 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-03-14T09:35:32.819270Z","iopub.execute_input":"2024-03-14T09:35:32.819533Z","iopub.status.idle":"2024-03-14T09:41:01.804018Z","shell.execute_reply.started":"2024-03-14T09:35:32.819508Z","shell.execute_reply":"2024-03-14T09:41:01.802982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:41:01.805433Z","iopub.execute_input":"2024-03-14T09:41:01.805830Z","iopub.status.idle":"2024-03-14T09:41:08.623098Z","shell.execute_reply.started":"2024-03-14T09:41:01.805792Z","shell.execute_reply":"2024-03-14T09:41:08.622265Z"},"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-03-14T09:42:37.945916Z","iopub.execute_input":"2024-03-14T09:42:37.946291Z","iopub.status.idle":"2024-03-14T09:42:37.950971Z","shell.execute_reply.started":"2024-03-14T09:42:37.946262Z","shell.execute_reply":"2024-03-14T09:42:37.949909Z"},"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-03-14T09:42:43.410552Z","iopub.execute_input":"2024-03-14T09:42:43.411451Z","iopub.status.idle":"2024-03-14T09:42:43.415809Z","shell.execute_reply.started":"2024-03-14T09:42:43.411417Z","shell.execute_reply":"2024-03-14T09:42:43.414788Z"},"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-03-14T09:42:47.234487Z","iopub.execute_input":"2024-03-14T09:42:47.235191Z","iopub.status.idle":"2024-03-14T09:43:05.932681Z","shell.execute_reply.started":"2024-03-14T09:42:47.235156Z","shell.execute_reply":"2024-03-14T09:43:05.931798Z"},"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-03-14T09:43:14.040129Z","iopub.execute_input":"2024-03-14T09:43:14.040508Z","iopub.status.idle":"2024-03-14T09:43:14.048301Z","shell.execute_reply.started":"2024-03-14T09:43:14.040477Z","shell.execute_reply":"2024-03-14T09:43:14.047177Z"},"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-03-14T09:43:17.710387Z","iopub.execute_input":"2024-03-14T09:43:17.711292Z","iopub.status.idle":"2024-03-14T09:43:17.717855Z","shell.execute_reply.started":"2024-03-14T09:43:17.711256Z","shell.execute_reply":"2024-03-14T09:43:17.716797Z"},"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-03-14T09:43:24.010665Z","iopub.execute_input":"2024-03-14T09:43:24.011049Z","iopub.status.idle":"2024-03-14T09:43:24.028560Z","shell.execute_reply.started":"2024-03-14T09:43:24.011020Z","shell.execute_reply":"2024-03-14T09:43:24.027633Z"},"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-03-14T09:43:29.870521Z","iopub.execute_input":"2024-03-14T09:43:29.870930Z","iopub.status.idle":"2024-03-14T09:43:29.882816Z","shell.execute_reply.started":"2024-03-14T09:43:29.870896Z","shell.execute_reply":"2024-03-14T09:43:29.881753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import scikitplot as skplt","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:43:34.140160Z","iopub.execute_input":"2024-03-14T09:43:34.140853Z","iopub.status.idle":"2024-03-14T09:43:34.267412Z","shell.execute_reply.started":"2024-03-14T09:43:34.140820Z","shell.execute_reply":"2024-03-14T09:43:34.266481Z"},"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-03-14T09:43:38.755519Z","iopub.execute_input":"2024-03-14T09:43:38.755894Z","iopub.status.idle":"2024-03-14T09:43:38.978685Z","shell.execute_reply.started":"2024-03-14T09:43:38.755865Z","shell.execute_reply":"2024-03-14T09:43:38.977793Z"},"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-03-14T09:43:46.305939Z","iopub.execute_input":"2024-03-14T09:43:46.306832Z","iopub.status.idle":"2024-03-14T09:43:46.326907Z","shell.execute_reply.started":"2024-03-14T09:43:46.306794Z","shell.execute_reply":"2024-03-14T09:43:46.325986Z"},"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-03-14T09:43:52.365547Z","iopub.execute_input":"2024-03-14T09:43:52.365962Z","iopub.status.idle":"2024-03-14T09:43:52.693692Z","shell.execute_reply.started":"2024-03-14T09:43:52.365930Z","shell.execute_reply":"2024-03-14T09:43:52.692804Z"},"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-03-14T09:43:59.485243Z","iopub.execute_input":"2024-03-14T09:43:59.485864Z","iopub.status.idle":"2024-03-14T09:43:59.779052Z","shell.execute_reply.started":"2024-03-14T09:43:59.485830Z","shell.execute_reply":"2024-03-14T09:43:59.778160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications import ResNet50","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:44:06.470301Z","iopub.execute_input":"2024-03-14T09:44:06.470663Z","iopub.status.idle":"2024-03-14T09:44:06.476594Z","shell.execute_reply.started":"2024-03-14T09:44:06.470633Z","shell.execute_reply":"2024-03-14T09:44:06.475672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_shape = (224, 224, 3)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:44:10.665904Z","iopub.execute_input":"2024-03-14T09:44:10.666264Z","iopub.status.idle":"2024-03-14T09:44:10.671136Z","shell.execute_reply.started":"2024-03-14T09:44:10.666235Z","shell.execute_reply":"2024-03-14T09:44:10.669876Z"},"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-03-14T09:44:18.966786Z","iopub.execute_input":"2024-03-14T09:44:18.967828Z","iopub.status.idle":"2024-03-14T09:44:21.348819Z","shell.execute_reply.started":"2024-03-14T09:44:18.967780Z","shell.execute_reply":"2024-03-14T09:44:21.347961Z"},"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-03-14T09:45:35.880128Z","iopub.execute_input":"2024-03-14T09:45:35.880511Z","iopub.status.idle":"2024-03-14T09:45:35.891758Z","shell.execute_reply.started":"2024-03-14T09:45:35.880480Z","shell.execute_reply":"2024-03-14T09:45:35.890816Z"},"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-03-14T09:45:42.055155Z","iopub.execute_input":"2024-03-14T09:45:42.056290Z","iopub.status.idle":"2024-03-14T09:45:42.590107Z","shell.execute_reply.started":"2024-03-14T09:45:42.056246Z","shell.execute_reply":"2024-03-14T09:45:42.588997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_resnet50.summary()","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:45:49.081777Z","iopub.execute_input":"2024-03-14T09:45:49.082163Z","iopub.status.idle":"2024-03-14T09:45:49.123716Z","shell.execute_reply.started":"2024-03-14T09:45:49.082133Z","shell.execute_reply":"2024-03-14T09:45:49.122718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import optimizers","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:46:01.805186Z","iopub.execute_input":"2024-03-14T09:46:01.805553Z","iopub.status.idle":"2024-03-14T09:46:01.809914Z","shell.execute_reply.started":"2024-03-14T09:46:01.805524Z","shell.execute_reply":"2024-03-14T09:46:01.808898Z"},"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-03-14T09:46:08.135681Z","iopub.execute_input":"2024-03-14T09:46:08.136541Z","iopub.status.idle":"2024-03-14T09:46:08.152250Z","shell.execute_reply.started":"2024-03-14T09:46:08.136508Z","shell.execute_reply":"2024-03-14T09:46:08.151344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model_resnet50.fit(\n    X_train, y_train,\n    epochs=5,  \n    validation_data=(X_val, y_val),\n    verbose=1\n)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:46:31.320519Z","iopub.execute_input":"2024-03-14T09:46:31.320891Z","iopub.status.idle":"2024-03-14T09:50:46.364756Z","shell.execute_reply.started":"2024-03-14T09:46:31.320861Z","shell.execute_reply":"2024-03-14T09:50:46.363921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model_resnet50.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-03-14T09:51:03.646367Z","iopub.execute_input":"2024-03-14T09:51:03.646759Z","iopub.status.idle":"2024-03-14T09:51:17.706708Z","shell.execute_reply.started":"2024-03-14T09:51:03.646718Z","shell.execute_reply":"2024-03-14T09:51:17.705967Z"},"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-03-14T09:51:24.855007Z","iopub.execute_input":"2024-03-14T09:51:24.859371Z","iopub.status.idle":"2024-03-14T09:51:24.863974Z","shell.execute_reply.started":"2024-03-14T09:51:24.859334Z","shell.execute_reply":"2024-03-14T09:51:24.862889Z"},"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-03-14T09:51:33.651819Z","iopub.execute_input":"2024-03-14T09:51:33.652219Z","iopub.status.idle":"2024-03-14T09:52:12.872935Z","shell.execute_reply.started":"2024-03-14T09:51:33.652185Z","shell.execute_reply":"2024-03-14T09:52:12.871878Z"},"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-03-14T09:52:25.860527Z","iopub.execute_input":"2024-03-14T09:52:25.860914Z","iopub.status.idle":"2024-03-14T09:52:25.868533Z","shell.execute_reply.started":"2024-03-14T09:52:25.860884Z","shell.execute_reply":"2024-03-14T09:52:25.867482Z"},"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-03-14T09:52:30.085389Z","iopub.execute_input":"2024-03-14T09:52:30.086302Z","iopub.status.idle":"2024-03-14T09:52:30.092549Z","shell.execute_reply.started":"2024-03-14T09:52:30.086265Z","shell.execute_reply":"2024-03-14T09:52:30.091563Z"},"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-03-14T09:52:37.860297Z","iopub.execute_input":"2024-03-14T09:52:37.860669Z","iopub.status.idle":"2024-03-14T09:52:37.879559Z","shell.execute_reply.started":"2024-03-14T09:52:37.860642Z","shell.execute_reply":"2024-03-14T09:52:37.878555Z"},"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-03-14T09:52:46.906856Z","iopub.execute_input":"2024-03-14T09:52:46.907689Z","iopub.status.idle":"2024-03-14T09:52:46.915428Z","shell.execute_reply.started":"2024-03-14T09:52:46.907650Z","shell.execute_reply":"2024-03-14T09:52:46.914531Z"},"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-03-14T09:52:52.865330Z","iopub.execute_input":"2024-03-14T09:52:52.866082Z","iopub.status.idle":"2024-03-14T09:52:53.181974Z","shell.execute_reply.started":"2024-03-14T09:52:52.866047Z","shell.execute_reply":"2024-03-14T09:52:53.180950Z"},"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-03-14T09:53:11.464654Z","iopub.execute_input":"2024-03-14T09:53:11.465028Z","iopub.status.idle":"2024-03-14T09:53:11.487464Z","shell.execute_reply.started":"2024-03-14T09:53:11.464999Z","shell.execute_reply":"2024-03-14T09:53:11.486522Z"},"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-03-14T09:53:16.180672Z","iopub.execute_input":"2024-03-14T09:53:16.181577Z","iopub.status.idle":"2024-03-14T09:53:16.483690Z","shell.execute_reply.started":"2024-03-14T09:53:16.181544Z","shell.execute_reply":"2024-03-14T09:53:16.482798Z"},"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-03-14T09:53:56.248757Z","iopub.execute_input":"2024-03-14T09:53:56.249615Z","iopub.status.idle":"2024-03-14T09:53:56.534096Z","shell.execute_reply.started":"2024-03-14T09:53:56.249580Z","shell.execute_reply":"2024-03-14T09:53:56.533133Z"},"trusted":true},"execution_count":null,"outputs":[]}]}