{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.6.6","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":29845,"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\n# import numpy as np # linear algebra\n# import 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\n# import os\n# for 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":"2025-03-13T05:33:03.002068Z","iopub.execute_input":"2025-03-13T05:33:03.002325Z","iopub.status.idle":"2025-03-13T05:33:03.006562Z","shell.execute_reply.started":"2025-03-13T05:33:03.002287Z","shell.execute_reply":"2025-03-13T05:33:03.00578Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dataset_path = '/kaggle/input/deepfake-faces/metadata.csv'","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.008099Z","iopub.execute_input":"2025-03-13T05:33:03.008314Z","iopub.status.idle":"2025-03-13T05:33:03.036586Z","shell.execute_reply.started":"2025-03-13T05:33:03.008266Z","shell.execute_reply":"2025-03-13T05:33:03.036017Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:03.038178Z","iopub.execute_input":"2025-03-13T05:33:03.038461Z","iopub.status.idle":"2025-03-13T05:33:03.252333Z","shell.execute_reply.started":"2025-03-13T05:33:03.038397Z","shell.execute_reply":"2025-03-13T05:33:03.251669Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv(dataset_path)","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.254396Z","iopub.execute_input":"2025-03-13T05:33:03.254842Z","iopub.status.idle":"2025-03-13T05:33:03.367058Z","shell.execute_reply.started":"2025-03-13T05:33:03.254633Z","shell.execute_reply":"2025-03-13T05:33:03.366407Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.368358Z","iopub.execute_input":"2025-03-13T05:33:03.368601Z","iopub.status.idle":"2025-03-13T05:33:03.384243Z","shell.execute_reply.started":"2025-03-13T05:33:03.368561Z","shell.execute_reply":"2025-03-13T05:33:03.383274Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.tail()","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.385808Z","iopub.execute_input":"2025-03-13T05:33:03.386382Z","iopub.status.idle":"2025-03-13T05:33:03.401449Z","shell.execute_reply.started":"2025-03-13T05:33:03.386318Z","shell.execute_reply":"2025-03-13T05:33:03.400597Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.402578Z","iopub.execute_input":"2025-03-13T05:33:03.402911Z","iopub.status.idle":"2025-03-13T05:33:03.41631Z","shell.execute_reply.started":"2025-03-13T05:33:03.402859Z","shell.execute_reply":"2025-03-13T05:33:03.415435Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.420322Z","iopub.execute_input":"2025-03-13T05:33:03.420575Z","iopub.status.idle":"2025-03-13T05:33:03.435967Z","shell.execute_reply.started":"2025-03-13T05:33:03.420534Z","shell.execute_reply":"2025-03-13T05:33:03.434863Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.438396Z","iopub.execute_input":"2025-03-13T05:33:03.438658Z","iopub.status.idle":"2025-03-13T05:33:03.492853Z","shell.execute_reply.started":"2025-03-13T05:33:03.438616Z","shell.execute_reply":"2025-03-13T05:33:03.491943Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.494355Z","iopub.execute_input":"2025-03-13T05:33:03.494802Z","iopub.status.idle":"2025-03-13T05:33:03.514141Z","shell.execute_reply.started":"2025-03-13T05:33:03.494638Z","shell.execute_reply":"2025-03-13T05:33:03.513275Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.515337Z","iopub.execute_input":"2025-03-13T05:33:03.515548Z","iopub.status.idle":"2025-03-13T05:33:03.541451Z","shell.execute_reply.started":"2025-03-13T05:33:03.515511Z","shell.execute_reply":"2025-03-13T05:33:03.54058Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.nunique()","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.542613Z","iopub.execute_input":"2025-03-13T05:33:03.542856Z","iopub.status.idle":"2025-03-13T05:33:03.600319Z","shell.execute_reply.started":"2025-03-13T05:33:03.542817Z","shell.execute_reply":"2025-03-13T05:33:03.599504Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2025-03-13T05:33:03.601756Z","iopub.execute_input":"2025-03-13T05:33:03.602173Z","iopub.status.idle":"2025-03-13T05:33:03.618055Z","shell.execute_reply.started":"2025-03-13T05:33:03.602016Z","shell.execute_reply":"2025-03-13T05:33:03.617249Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2025-03-13T05:33:03.619221Z","iopub.execute_input":"2025-03-13T05:33:03.619431Z","iopub.status.idle":"2025-03-13T05:33:03.636469Z","shell.execute_reply.started":"2025-03-13T05:33:03.619392Z","shell.execute_reply":"2025-03-13T05:33:03.635446Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"categorical, non_categorical, discrete, continuous = classify_features(df)","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.638007Z","iopub.execute_input":"2025-03-13T05:33:03.63832Z","iopub.status.idle":"2025-03-13T05:33:03.696708Z","shell.execute_reply.started":"2025-03-13T05:33:03.638259Z","shell.execute_reply":"2025-03-13T05:33:03.695691Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2025-03-13T05:33:03.697985Z","iopub.execute_input":"2025-03-13T05:33:03.698273Z","iopub.status.idle":"2025-03-13T05:33:03.704486Z","shell.execute_reply.started":"2025-03-13T05:33:03.698225Z","shell.execute_reply":"2025-03-13T05:33:03.703805Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = df.fillna(\"Not Available\")","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.705991Z","iopub.execute_input":"2025-03-13T05:33:03.706295Z","iopub.status.idle":"2025-03-13T05:33:03.74511Z","shell.execute_reply.started":"2025-03-13T05:33:03.706239Z","shell.execute_reply":"2025-03-13T05:33:03.744498Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for i in categorical:\n    print(i,':', df[i].unique())\n    print()","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.746401Z","iopub.execute_input":"2025-03-13T05:33:03.746656Z","iopub.status.idle":"2025-03-13T05:33:03.755495Z","shell.execute_reply.started":"2025-03-13T05:33:03.746606Z","shell.execute_reply":"2025-03-13T05:33:03.754742Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for i in categorical:\n    print(df[i].value_counts())\n    print()","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:03.756895Z","iopub.execute_input":"2025-03-13T05:33:03.757346Z","iopub.status.idle":"2025-03-13T05:33:03.778541Z","shell.execute_reply.started":"2025-03-13T05:33:03.757172Z","shell.execute_reply":"2025-03-13T05:33:03.77793Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2025-03-13T05:33:03.779588Z","iopub.execute_input":"2025-03-13T05:33:03.779843Z","iopub.status.idle":"2025-03-13T05:33:04.099262Z","shell.execute_reply.started":"2025-03-13T05:33:03.779797Z","shell.execute_reply":"2025-03-13T05:33:04.098654Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2025-03-13T05:33:04.10038Z","iopub.execute_input":"2025-03-13T05:33:04.100636Z","iopub.status.idle":"2025-03-13T05:33:04.103756Z","shell.execute_reply.started":"2025-03-13T05:33:04.100583Z","shell.execute_reply":"2025-03-13T05:33:04.103104Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2025-03-13T05:33:04.104941Z","iopub.execute_input":"2025-03-13T05:33:04.105126Z","iopub.status.idle":"2025-03-13T05:33:04.3367Z","shell.execute_reply.started":"2025-03-13T05:33:04.105094Z","shell.execute_reply":"2025-03-13T05:33:04.335797Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:04.337889Z","iopub.execute_input":"2025-03-13T05:33:04.338369Z","iopub.status.idle":"2025-03-13T05:33:04.639567Z","shell.execute_reply.started":"2025-03-13T05:33:04.338188Z","shell.execute_reply":"2025-03-13T05:33:04.638782Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install --upgrade seaborn\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:04.640673Z","iopub.execute_input":"2025-03-13T05:33:04.640968Z","iopub.status.idle":"2025-03-13T05:33:09.669433Z","shell.execute_reply.started":"2025-03-13T05:33:04.640919Z","shell.execute_reply":"2025-03-13T05:33:09.668755Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:09.671447Z","iopub.execute_input":"2025-03-13T05:33:09.671908Z","iopub.status.idle":"2025-03-13T05:33:12.308878Z","shell.execute_reply.started":"2025-03-13T05:33:09.67182Z","shell.execute_reply":"2025-03-13T05:33:12.30759Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:12.31038Z","iopub.execute_input":"2025-03-13T05:33:12.310751Z","iopub.status.idle":"2025-03-13T05:33:14.171391Z","shell.execute_reply.started":"2025-03-13T05:33:12.310697Z","shell.execute_reply":"2025-03-13T05:33:14.169857Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:14.173695Z","iopub.execute_input":"2025-03-13T05:33:14.174378Z","iopub.status.idle":"2025-03-13T05:33:14.75431Z","shell.execute_reply.started":"2025-03-13T05:33:14.174064Z","shell.execute_reply":"2025-03-13T05:33:14.753251Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:14.757146Z","iopub.execute_input":"2025-03-13T05:33:14.7575Z","iopub.status.idle":"2025-03-13T05:33:15.781452Z","shell.execute_reply.started":"2025-03-13T05:33:14.757442Z","shell.execute_reply":"2025-03-13T05:33:15.780588Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:15.782667Z","iopub.execute_input":"2025-03-13T05:33:15.782993Z","iopub.status.idle":"2025-03-13T05:33:16.193248Z","shell.execute_reply.started":"2025-03-13T05:33:15.782941Z","shell.execute_reply":"2025-03-13T05:33:16.192413Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:16.194454Z","iopub.execute_input":"2025-03-13T05:33:16.194938Z","iopub.status.idle":"2025-03-13T05:33:16.855143Z","shell.execute_reply.started":"2025-03-13T05:33:16.194709Z","shell.execute_reply":"2025-03-13T05:33:16.851688Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:16.856665Z","iopub.execute_input":"2025-03-13T05:33:16.857032Z","iopub.status.idle":"2025-03-13T05:33:18.113579Z","shell.execute_reply.started":"2025-03-13T05:33:16.856974Z","shell.execute_reply":"2025-03-13T05:33:18.112833Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:18.114856Z","iopub.execute_input":"2025-03-13T05:33:18.115163Z","iopub.status.idle":"2025-03-13T05:33:20.329266Z","shell.execute_reply.started":"2025-03-13T05:33:18.11511Z","shell.execute_reply":"2025-03-13T05:33:20.328088Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:20.331373Z","iopub.execute_input":"2025-03-13T05:33:20.331941Z","iopub.status.idle":"2025-03-13T05:33:20.417739Z","shell.execute_reply.started":"2025-03-13T05:33:20.331729Z","shell.execute_reply":"2025-03-13T05:33:20.41659Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:20.420869Z","iopub.execute_input":"2025-03-13T05:33:20.421276Z","iopub.status.idle":"2025-03-13T05:33:21.410125Z","shell.execute_reply.started":"2025-03-13T05:33:20.421214Z","shell.execute_reply":"2025-03-13T05:33:21.409552Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Train_set.shape,Val_set.shape,Test_set.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:21.411495Z","iopub.execute_input":"2025-03-13T05:33:21.411823Z","iopub.status.idle":"2025-03-13T05:33:21.417251Z","shell.execute_reply.started":"2025-03-13T05:33:21.411765Z","shell.execute_reply":"2025-03-13T05:33:21.416561Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import cv2","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:21.418658Z","iopub.execute_input":"2025-03-13T05:33:21.418964Z","iopub.status.idle":"2025-03-13T05:33:22.314934Z","shell.execute_reply.started":"2025-03-13T05:33:21.41891Z","shell.execute_reply":"2025-03-13T05:33:22.314313Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:22.316233Z","iopub.execute_input":"2025-03-13T05:33:22.31653Z","iopub.status.idle":"2025-03-13T05:33:22.320239Z","shell.execute_reply.started":"2025-03-13T05:33:22.316467Z","shell.execute_reply":"2025-03-13T05:33:22.319482Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:22.321497Z","iopub.execute_input":"2025-03-13T05:33:22.321775Z","iopub.status.idle":"2025-03-13T05:33:28.049476Z","shell.execute_reply.started":"2025-03-13T05:33:22.321715Z","shell.execute_reply":"2025-03-13T05:33:28.048794Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:28.050553Z","iopub.execute_input":"2025-03-13T05:33:28.050826Z","iopub.status.idle":"2025-03-13T05:33:28.114646Z","shell.execute_reply.started":"2025-03-13T05:33:28.050776Z","shell.execute_reply":"2025-03-13T05:33:28.114047Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:28.116053Z","iopub.execute_input":"2025-03-13T05:33:28.11627Z","iopub.status.idle":"2025-03-13T05:33:29.707773Z","shell.execute_reply.started":"2025-03-13T05:33:28.116235Z","shell.execute_reply":"2025-03-13T05:33:29.706944Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:29.715886Z","iopub.execute_input":"2025-03-13T05:33:29.716305Z","iopub.status.idle":"2025-03-13T05:33:29.723588Z","shell.execute_reply.started":"2025-03-13T05:33:29.716219Z","shell.execute_reply":"2025-03-13T05:33:29.722743Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:33:29.724925Z","iopub.execute_input":"2025-03-13T05:33:29.725186Z","iopub.status.idle":"2025-03-13T05:38:37.27752Z","shell.execute_reply.started":"2025-03-13T05:33:29.725137Z","shell.execute_reply":"2025-03-13T05:38:37.276482Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import layers, models\nfrom functools import partial","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:38:37.278897Z","iopub.execute_input":"2025-03-13T05:38:37.279155Z","iopub.status.idle":"2025-03-13T05:38:46.421478Z","shell.execute_reply.started":"2025-03-13T05:38:37.279107Z","shell.execute_reply":"2025-03-13T05:38:46.420871Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tf.random.set_seed(42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:38:46.422793Z","iopub.execute_input":"2025-03-13T05:38:46.423095Z","iopub.status.idle":"2025-03-13T05:38:46.426617Z","shell.execute_reply.started":"2025-03-13T05:38:46.423042Z","shell.execute_reply":"2025-03-13T05:38:46.425841Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:38:46.427906Z","iopub.execute_input":"2025-03-13T05:38:46.428204Z","iopub.status.idle":"2025-03-13T05:38:54.121325Z","shell.execute_reply.started":"2025-03-13T05:38:46.428144Z","shell.execute_reply":"2025-03-13T05:38:54.120733Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:38:54.122776Z","iopub.execute_input":"2025-03-13T05:38:54.123092Z","iopub.status.idle":"2025-03-13T05:38:54.132487Z","shell.execute_reply.started":"2025-03-13T05:38:54.123033Z","shell.execute_reply":"2025-03-13T05:38:54.131777Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=lr_schedule),\n              loss=\"binary_crossentropy\", metrics=[\"accuracy\"])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:38:54.133466Z","iopub.execute_input":"2025-03-13T05:38:54.13365Z","iopub.status.idle":"2025-03-13T05:38:54.180823Z","shell.execute_reply.started":"2025-03-13T05:38:54.133618Z","shell.execute_reply":"2025-03-13T05:38:54.18016Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:38:54.181757Z","iopub.execute_input":"2025-03-13T05:38:54.181947Z","iopub.status.idle":"2025-03-13T05:38:54.1889Z","shell.execute_reply.started":"2025-03-13T05:38:54.181913Z","shell.execute_reply":"2025-03-13T05:38:54.188182Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:38:54.190054Z","iopub.execute_input":"2025-03-13T05:38:54.190248Z","iopub.status.idle":"2025-03-13T05:50:13.968704Z","shell.execute_reply.started":"2025-03-13T05:38:54.190213Z","shell.execute_reply":"2025-03-13T05:50:13.96767Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = model.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:13.970264Z","iopub.execute_input":"2025-03-13T05:50:13.970545Z","iopub.status.idle":"2025-03-13T05:50:20.967178Z","shell.execute_reply.started":"2025-03-13T05:50:13.970475Z","shell.execute_reply":"2025-03-13T05:50:20.966357Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, confusion_matrix, classification_report","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:20.968343Z","iopub.execute_input":"2025-03-13T05:50:20.968587Z","iopub.status.idle":"2025-03-13T05:50:20.972988Z","shell.execute_reply.started":"2025-03-13T05:50:20.968549Z","shell.execute_reply":"2025-03-13T05:50:20.972107Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_test_pred_binary = (y_pred > 0.5).astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:20.974224Z","iopub.execute_input":"2025-03-13T05:50:20.974503Z","iopub.status.idle":"2025-03-13T05:50:20.992485Z","shell.execute_reply.started":"2025-03-13T05:50:20.97444Z","shell.execute_reply":"2025-03-13T05:50:20.991775Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train_pred = model.predict(X_train)\ny_train_pred_binary = (y_train_pred > 0.5).astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:20.993533Z","iopub.execute_input":"2025-03-13T05:50:20.993776Z","iopub.status.idle":"2025-03-13T05:50:40.323689Z","shell.execute_reply.started":"2025-03-13T05:50:20.993728Z","shell.execute_reply":"2025-03-13T05:50:40.322636Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_accuracy = accuracy_score(y_train, y_train_pred_binary)\nprint(f\"Training Accuracy: {train_accuracy * 100:.2f}%\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:40.325264Z","iopub.execute_input":"2025-03-13T05:50:40.325752Z","iopub.status.idle":"2025-03-13T05:50:40.332746Z","shell.execute_reply.started":"2025-03-13T05:50:40.325657Z","shell.execute_reply":"2025-03-13T05:50:40.331701Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_accuracy = accuracy_score(y_test, y_test_pred_binary)\nprint(f\"Test Accuracy: {test_accuracy * 100:.2f}%\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:40.334055Z","iopub.execute_input":"2025-03-13T05:50:40.334334Z","iopub.status.idle":"2025-03-13T05:50:40.34436Z","shell.execute_reply.started":"2025-03-13T05:50:40.334257Z","shell.execute_reply":"2025-03-13T05:50:40.343535Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:40.345886Z","iopub.execute_input":"2025-03-13T05:50:40.346204Z","iopub.status.idle":"2025-03-13T05:50:40.367437Z","shell.execute_reply.started":"2025-03-13T05:50:40.346146Z","shell.execute_reply":"2025-03-13T05:50:40.366715Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"conf_matrix = confusion_matrix(y_test, y_test_pred_binary)\nprint(\"Confusion Matrix:\")\nprint(conf_matrix)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:40.368493Z","iopub.execute_input":"2025-03-13T05:50:40.368721Z","iopub.status.idle":"2025-03-13T05:50:40.384758Z","shell.execute_reply.started":"2025-03-13T05:50:40.368656Z","shell.execute_reply":"2025-03-13T05:50:40.38382Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import scikitplot as skplt","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:40.385958Z","iopub.execute_input":"2025-03-13T05:50:40.386292Z","iopub.status.idle":"2025-03-13T05:50:40.620973Z","shell.execute_reply.started":"2025-03-13T05:50:40.386235Z","shell.execute_reply":"2025-03-13T05:50:40.62018Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"skplt.metrics.plot_confusion_matrix(y_test, y_test_pred_binary, normalize=True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:40.622141Z","iopub.execute_input":"2025-03-13T05:50:40.622414Z","iopub.status.idle":"2025-03-13T05:50:40.896735Z","shell.execute_reply.started":"2025-03-13T05:50:40.622365Z","shell.execute_reply":"2025-03-13T05:50:40.895566Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class_report = classification_report(y_test, y_test_pred_binary)\nprint(\"Classification Report:\")\nprint(class_report)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:40.89873Z","iopub.execute_input":"2025-03-13T05:50:40.899107Z","iopub.status.idle":"2025-03-13T05:50:40.925285Z","shell.execute_reply.started":"2025-03-13T05:50:40.899047Z","shell.execute_reply":"2025-03-13T05:50:40.924147Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:40.926884Z","iopub.execute_input":"2025-03-13T05:50:40.927283Z","iopub.status.idle":"2025-03-13T05:50:41.150792Z","shell.execute_reply.started":"2025-03-13T05:50:40.927173Z","shell.execute_reply":"2025-03-13T05:50:41.149838Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:41.152013Z","iopub.execute_input":"2025-03-13T05:50:41.15231Z","iopub.status.idle":"2025-03-13T05:50:41.321632Z","shell.execute_reply.started":"2025-03-13T05:50:41.152258Z","shell.execute_reply":"2025-03-13T05:50:41.320841Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras.applications import ResNet50","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:41.322746Z","iopub.execute_input":"2025-03-13T05:50:41.32305Z","iopub.status.idle":"2025-03-13T05:50:41.331326Z","shell.execute_reply.started":"2025-03-13T05:50:41.322992Z","shell.execute_reply":"2025-03-13T05:50:41.330802Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"input_shape = (224, 224, 3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:41.332301Z","iopub.execute_input":"2025-03-13T05:50:41.332592Z","iopub.status.idle":"2025-03-13T05:50:41.345817Z","shell.execute_reply.started":"2025-03-13T05:50:41.332541Z","shell.execute_reply":"2025-03-13T05:50:41.345204Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"base_model = ResNet50(weights='imagenet', include_top=False, input_shape=input_shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:41.347551Z","iopub.execute_input":"2025-03-13T05:50:41.34785Z","iopub.status.idle":"2025-03-13T05:50:46.160648Z","shell.execute_reply.started":"2025-03-13T05:50:41.347804Z","shell.execute_reply":"2025-03-13T05:50:46.159694Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for layer in base_model.layers:\n    layer.trainable = False","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:46.16207Z","iopub.execute_input":"2025-03-13T05:50:46.162304Z","iopub.status.idle":"2025-03-13T05:50:46.171198Z","shell.execute_reply.started":"2025-03-13T05:50:46.162264Z","shell.execute_reply":"2025-03-13T05:50:46.170332Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:46.172393Z","iopub.execute_input":"2025-03-13T05:50:46.172632Z","iopub.status.idle":"2025-03-13T05:50:47.489089Z","shell.execute_reply.started":"2025-03-13T05:50:46.17259Z","shell.execute_reply":"2025-03-13T05:50:47.488496Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_resnet50.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:47.490147Z","iopub.execute_input":"2025-03-13T05:50:47.49034Z","iopub.status.idle":"2025-03-13T05:50:47.505313Z","shell.execute_reply.started":"2025-03-13T05:50:47.490307Z","shell.execute_reply":"2025-03-13T05:50:47.504637Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras import optimizers","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:47.506161Z","iopub.execute_input":"2025-03-13T05:50:47.506338Z","iopub.status.idle":"2025-03-13T05:50:47.524315Z","shell.execute_reply.started":"2025-03-13T05:50:47.506306Z","shell.execute_reply":"2025-03-13T05:50:47.523819Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_resnet50.compile(optimizer=optimizers.Adam(lr=0.001), loss='binary_crossentropy', metrics=['accuracy'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:47.525285Z","iopub.execute_input":"2025-03-13T05:50:47.52551Z","iopub.status.idle":"2025-03-13T05:50:47.580881Z","shell.execute_reply.started":"2025-03-13T05:50:47.525466Z","shell.execute_reply":"2025-03-13T05:50:47.580279Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T05:50:47.581774Z","iopub.execute_input":"2025-03-13T05:50:47.582012Z","iopub.status.idle":"2025-03-13T06:00:38.906817Z","shell.execute_reply.started":"2025-03-13T05:50:47.581964Z","shell.execute_reply":"2025-03-13T06:00:38.905698Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = model_resnet50.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:00:38.908275Z","iopub.execute_input":"2025-03-13T06:00:38.908584Z","iopub.status.idle":"2025-03-13T06:00:53.477618Z","shell.execute_reply.started":"2025-03-13T06:00:38.908536Z","shell.execute_reply":"2025-03-13T06:00:53.476954Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_test_pred_binary = (y_pred > 0.5).astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:00:53.478957Z","iopub.execute_input":"2025-03-13T06:00:53.479258Z","iopub.status.idle":"2025-03-13T06:00:53.483847Z","shell.execute_reply.started":"2025-03-13T06:00:53.479202Z","shell.execute_reply":"2025-03-13T06:00:53.482952Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train_pred = model_resnet50.predict(X_train)\ny_train_pred_binary = (y_train_pred > 0.5).astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:00:53.485033Z","iopub.execute_input":"2025-03-13T06:00:53.485314Z","iopub.status.idle":"2025-03-13T06:01:32.269708Z","shell.execute_reply.started":"2025-03-13T06:00:53.485262Z","shell.execute_reply":"2025-03-13T06:01:32.269033Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_accuracy = accuracy_score(y_train, y_train_pred_binary)\nprint(f\"Training Accuracy: {train_accuracy * 100:.2f}%\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:01:32.27086Z","iopub.execute_input":"2025-03-13T06:01:32.271063Z","iopub.status.idle":"2025-03-13T06:01:32.276834Z","shell.execute_reply.started":"2025-03-13T06:01:32.271026Z","shell.execute_reply":"2025-03-13T06:01:32.276125Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_accuracy = accuracy_score(y_test, y_test_pred_binary)\nprint(f\"Test Accuracy: {test_accuracy * 100:.2f}%\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:01:32.278041Z","iopub.execute_input":"2025-03-13T06:01:32.278259Z","iopub.status.idle":"2025-03-13T06:01:32.289061Z","shell.execute_reply.started":"2025-03-13T06:01:32.278216Z","shell.execute_reply":"2025-03-13T06:01:32.288128Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:01:32.290192Z","iopub.execute_input":"2025-03-13T06:01:32.290383Z","iopub.status.idle":"2025-03-13T06:01:32.307842Z","shell.execute_reply.started":"2025-03-13T06:01:32.290349Z","shell.execute_reply":"2025-03-13T06:01:32.307204Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"conf_matrix = confusion_matrix(y_test, y_test_pred_binary)\nprint(\"Confusion Matrix:\")\nprint(conf_matrix)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:01:32.309004Z","iopub.execute_input":"2025-03-13T06:01:32.309235Z","iopub.status.idle":"2025-03-13T06:01:32.318406Z","shell.execute_reply.started":"2025-03-13T06:01:32.309186Z","shell.execute_reply":"2025-03-13T06:01:32.317796Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"skplt.metrics.plot_confusion_matrix(y_test, y_test_pred_binary, normalize=True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:01:32.319301Z","iopub.execute_input":"2025-03-13T06:01:32.319495Z","iopub.status.idle":"2025-03-13T06:01:32.632181Z","shell.execute_reply.started":"2025-03-13T06:01:32.319464Z","shell.execute_reply":"2025-03-13T06:01:32.630982Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class_report = classification_report(y_test, y_test_pred_binary)\nprint(\"Classification Report:\")\nprint(class_report)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:01:32.634232Z","iopub.execute_input":"2025-03-13T06:01:32.634616Z","iopub.status.idle":"2025-03-13T06:01:32.657999Z","shell.execute_reply.started":"2025-03-13T06:01:32.634557Z","shell.execute_reply":"2025-03-13T06:01:32.657029Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:01:32.659324Z","iopub.execute_input":"2025-03-13T06:01:32.659657Z","iopub.status.idle":"2025-03-13T06:01:32.998876Z","shell.execute_reply.started":"2025-03-13T06:01:32.659603Z","shell.execute_reply":"2025-03-13T06:01:32.997352Z"}},"outputs":[],"execution_count":null},{"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":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T06:01:33.001027Z","iopub.execute_input":"2025-03-13T06:01:33.001451Z","iopub.status.idle":"2025-03-13T06:01:33.337715Z","shell.execute_reply.started":"2025-03-13T06:01:33.001378Z","shell.execute_reply":"2025-03-13T06:01:33.336517Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}