{"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\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":"2024-11-14T08:40:42.983055Z","iopub.execute_input":"2024-11-14T08:40:42.984011Z","iopub.status.idle":"2024-11-14T08:40:42.988576Z","shell.execute_reply.started":"2024-11-14T08:40:42.983975Z","shell.execute_reply":"2024-11-14T08:40:42.987446Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dataset_path = '/kaggle/input/deepfake-faces/metadata.csv'","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:42.990113Z","iopub.execute_input":"2024-11-14T08:40:42.990407Z","iopub.status.idle":"2024-11-14T08:40:42.999924Z","shell.execute_reply.started":"2024-11-14T08:40:42.990382Z","shell.execute_reply":"2024-11-14T08:40:42.998944Z"},"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":"2024-11-14T08:40:43.001249Z","iopub.execute_input":"2024-11-14T08:40:43.001584Z","iopub.status.idle":"2024-11-14T08:40:43.299470Z","shell.execute_reply.started":"2024-11-14T08:40:43.001552Z","shell.execute_reply":"2024-11-14T08:40:43.298735Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv(dataset_path)","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.300438Z","iopub.execute_input":"2024-11-14T08:40:43.300792Z","iopub.status.idle":"2024-11-14T08:40:43.477576Z","shell.execute_reply.started":"2024-11-14T08:40:43.300767Z","shell.execute_reply":"2024-11-14T08:40:43.476584Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.480906Z","iopub.execute_input":"2024-11-14T08:40:43.481286Z","iopub.status.idle":"2024-11-14T08:40:43.499650Z","shell.execute_reply.started":"2024-11-14T08:40:43.481257Z","shell.execute_reply":"2024-11-14T08:40:43.498774Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.tail()","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.501021Z","iopub.execute_input":"2024-11-14T08:40:43.501636Z","iopub.status.idle":"2024-11-14T08:40:43.511030Z","shell.execute_reply.started":"2024-11-14T08:40:43.501600Z","shell.execute_reply":"2024-11-14T08:40:43.510092Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.512339Z","iopub.execute_input":"2024-11-14T08:40:43.512703Z","iopub.status.idle":"2024-11-14T08:40:43.519053Z","shell.execute_reply.started":"2024-11-14T08:40:43.512671Z","shell.execute_reply":"2024-11-14T08:40:43.518251Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.520229Z","iopub.execute_input":"2024-11-14T08:40:43.520589Z","iopub.status.idle":"2024-11-14T08:40:43.527939Z","shell.execute_reply.started":"2024-11-14T08:40:43.520553Z","shell.execute_reply":"2024-11-14T08:40:43.527082Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.529329Z","iopub.execute_input":"2024-11-14T08:40:43.529647Z","iopub.status.idle":"2024-11-14T08:40:43.583406Z","shell.execute_reply.started":"2024-11-14T08:40:43.529620Z","shell.execute_reply":"2024-11-14T08:40:43.582577Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.584569Z","iopub.execute_input":"2024-11-14T08:40:43.584885Z","iopub.status.idle":"2024-11-14T08:40:43.616634Z","shell.execute_reply.started":"2024-11-14T08:40:43.584854Z","shell.execute_reply":"2024-11-14T08:40:43.615855Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.617665Z","iopub.execute_input":"2024-11-14T08:40:43.618312Z","iopub.status.idle":"2024-11-14T08:40:43.658092Z","shell.execute_reply.started":"2024-11-14T08:40:43.618285Z","shell.execute_reply":"2024-11-14T08:40:43.657374Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.nunique()","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.659105Z","iopub.execute_input":"2024-11-14T08:40:43.659360Z","iopub.status.idle":"2024-11-14T08:40:43.703665Z","shell.execute_reply.started":"2024-11-14T08:40:43.659338Z","shell.execute_reply":"2024-11-14T08:40:43.702957Z"},"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":"2024-11-14T08:40:43.704950Z","iopub.execute_input":"2024-11-14T08:40:43.705287Z","iopub.status.idle":"2024-11-14T08:40:43.713826Z","shell.execute_reply.started":"2024-11-14T08:40:43.705255Z","shell.execute_reply":"2024-11-14T08:40:43.713024Z"},"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":"2024-11-14T08:40:43.718643Z","iopub.execute_input":"2024-11-14T08:40:43.718963Z","iopub.status.idle":"2024-11-14T08:40:43.725702Z","shell.execute_reply.started":"2024-11-14T08:40:43.718940Z","shell.execute_reply":"2024-11-14T08:40:43.724783Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"categorical, non_categorical, discrete, continuous = classify_features(df)","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.726881Z","iopub.execute_input":"2024-11-14T08:40:43.727432Z","iopub.status.idle":"2024-11-14T08:40:43.771735Z","shell.execute_reply.started":"2024-11-14T08:40:43.727398Z","shell.execute_reply":"2024-11-14T08:40:43.771079Z"},"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":"2024-11-14T08:40:43.772666Z","iopub.execute_input":"2024-11-14T08:40:43.772910Z","iopub.status.idle":"2024-11-14T08:40:43.777376Z","shell.execute_reply.started":"2024-11-14T08:40:43.772888Z","shell.execute_reply":"2024-11-14T08:40:43.776550Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = df.fillna(\"Not Available\")","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:43.778470Z","iopub.execute_input":"2024-11-14T08:40:43.778767Z","iopub.status.idle":"2024-11-14T08:40:43.817130Z","shell.execute_reply.started":"2024-11-14T08:40:43.778737Z","shell.execute_reply":"2024-11-14T08:40:43.816443Z"},"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":"2024-11-14T08:40:43.818203Z","iopub.execute_input":"2024-11-14T08:40:43.818890Z","iopub.status.idle":"2024-11-14T08:40:43.829645Z","shell.execute_reply.started":"2024-11-14T08:40:43.818857Z","shell.execute_reply":"2024-11-14T08:40:43.828927Z"},"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":"2024-11-14T08:40:43.830693Z","iopub.execute_input":"2024-11-14T08:40:43.830972Z","iopub.status.idle":"2024-11-14T08:40:43.846316Z","shell.execute_reply.started":"2024-11-14T08:40:43.830944Z","shell.execute_reply":"2024-11-14T08:40:43.845468Z"},"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":"2024-11-14T08:40:43.847508Z","iopub.execute_input":"2024-11-14T08:40:43.848235Z","iopub.status.idle":"2024-11-14T08:40:44.821690Z","shell.execute_reply.started":"2024-11-14T08:40:43.848208Z","shell.execute_reply":"2024-11-14T08:40:44.820929Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-11-14T08:40:44.822867Z","iopub.execute_input":"2024-11-14T08:40:44.823138Z","iopub.status.idle":"2024-11-14T08:40:44.827228Z","shell.execute_reply.started":"2024-11-14T08:40:44.823113Z","shell.execute_reply":"2024-11-14T08:40:44.826360Z"},"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":"2024-11-14T08:40:44.828661Z","iopub.execute_input":"2024-11-14T08:40:44.828933Z","iopub.status.idle":"2024-11-14T08:40:45.188167Z","shell.execute_reply.started":"2024-11-14T08:40:44.828908Z","shell.execute_reply":"2024-11-14T08:40:45.187303Z"},"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":"2024-11-14T08:40:45.189245Z","iopub.execute_input":"2024-11-14T08:40:45.189524Z","iopub.status.idle":"2024-11-14T08:40:45.585119Z","shell.execute_reply.started":"2024-11-14T08:40:45.189497Z","shell.execute_reply":"2024-11-14T08:40:45.584179Z"}},"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":"2024-11-14T08:40:45.586286Z","iopub.execute_input":"2024-11-14T08:40:45.586570Z","iopub.status.idle":"2024-11-14T08:40:47.209277Z","shell.execute_reply.started":"2024-11-14T08:40:45.586523Z","shell.execute_reply":"2024-11-14T08:40:47.208401Z"}},"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":"2024-11-14T08:40:47.210702Z","iopub.execute_input":"2024-11-14T08:40:47.211355Z","iopub.status.idle":"2024-11-14T08:40:48.731218Z","shell.execute_reply.started":"2024-11-14T08:40:47.211317Z","shell.execute_reply":"2024-11-14T08:40:48.730314Z"}},"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":"2024-11-14T08:40:48.732357Z","iopub.execute_input":"2024-11-14T08:40:48.732658Z","iopub.status.idle":"2024-11-14T08:40:49.067507Z","shell.execute_reply.started":"2024-11-14T08:40:48.732631Z","shell.execute_reply":"2024-11-14T08:40:49.066439Z"}},"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":"2024-11-14T08:40:49.068771Z","iopub.execute_input":"2024-11-14T08:40:49.070300Z","iopub.status.idle":"2024-11-14T08:40:49.946935Z","shell.execute_reply.started":"2024-11-14T08:40:49.070273Z","shell.execute_reply":"2024-11-14T08:40:49.946060Z"}},"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":"2024-11-14T08:40:49.948190Z","iopub.execute_input":"2024-11-14T08:40:49.948556Z","iopub.status.idle":"2024-11-14T08:40:50.529556Z","shell.execute_reply.started":"2024-11-14T08:40:49.948507Z","shell.execute_reply":"2024-11-14T08:40:50.528464Z"}},"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":"2024-11-14T08:40:50.531137Z","iopub.execute_input":"2024-11-14T08:40:50.531497Z","iopub.status.idle":"2024-11-14T08:40:51.030204Z","shell.execute_reply.started":"2024-11-14T08:40:50.531454Z","shell.execute_reply":"2024-11-14T08:40:51.029306Z"}},"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":"2024-11-14T08:40:51.031712Z","iopub.execute_input":"2024-11-14T08:40:51.032044Z","iopub.status.idle":"2024-11-14T08:40:52.235315Z","shell.execute_reply.started":"2024-11-14T08:40:51.032010Z","shell.execute_reply":"2024-11-14T08:40:52.234402Z"}},"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":"2024-11-14T08:40:52.236718Z","iopub.execute_input":"2024-11-14T08:40:52.237027Z","iopub.status.idle":"2024-11-14T08:40:52.985359Z","shell.execute_reply.started":"2024-11-14T08:40:52.236983Z","shell.execute_reply":"2024-11-14T08:40:52.984497Z"}},"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":"2024-11-14T08:40:52.986586Z","iopub.execute_input":"2024-11-14T08:40:52.986859Z","iopub.status.idle":"2024-11-14T08:40:53.038924Z","shell.execute_reply.started":"2024-11-14T08:40:52.986834Z","shell.execute_reply":"2024-11-14T08:40:53.038089Z"}},"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":"2024-11-14T08:40:53.040112Z","iopub.execute_input":"2024-11-14T08:40:53.040426Z","iopub.status.idle":"2024-11-14T08:40:53.295704Z","shell.execute_reply.started":"2024-11-14T08:40:53.040398Z","shell.execute_reply":"2024-11-14T08:40:53.294770Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Train_set.shape,Val_set.shape,Test_set.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:40:53.296855Z","iopub.execute_input":"2024-11-14T08:40:53.297147Z","iopub.status.idle":"2024-11-14T08:40:53.303634Z","shell.execute_reply.started":"2024-11-14T08:40:53.297119Z","shell.execute_reply":"2024-11-14T08:40:53.302688Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import cv2","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:40:53.304832Z","iopub.execute_input":"2024-11-14T08:40:53.305110Z","iopub.status.idle":"2024-11-14T08:40:53.488073Z","shell.execute_reply.started":"2024-11-14T08:40:53.305085Z","shell.execute_reply":"2024-11-14T08:40:53.487270Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:41:09.743066Z","iopub.execute_input":"2024-11-14T08:41:09.743432Z","iopub.status.idle":"2024-11-14T08:41:09.747984Z","shell.execute_reply.started":"2024-11-14T08:41:09.743403Z","shell.execute_reply":"2024-11-14T08:41:09.746965Z"}},"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":"2024-11-14T08:41:11.278207Z","iopub.execute_input":"2024-11-14T08:41:11.279126Z","iopub.status.idle":"2024-11-14T08:41:14.686323Z","shell.execute_reply.started":"2024-11-14T08:41:11.279084Z","shell.execute_reply":"2024-11-14T08:41:14.685367Z"}},"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":"2024-11-14T08:41:17.534648Z","iopub.execute_input":"2024-11-14T08:41:17.535083Z","iopub.status.idle":"2024-11-14T08:41:17.566997Z","shell.execute_reply.started":"2024-11-14T08:41:17.535046Z","shell.execute_reply":"2024-11-14T08:41:17.566114Z"}},"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":"2024-11-14T08:41:18.776078Z","iopub.execute_input":"2024-11-14T08:41:18.776423Z","iopub.status.idle":"2024-11-14T08:41:20.904552Z","shell.execute_reply.started":"2024-11-14T08:41:18.776394Z","shell.execute_reply":"2024-11-14T08:41:20.903581Z"}},"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":"2024-11-14T08:41:20.906066Z","iopub.execute_input":"2024-11-14T08:41:20.906371Z","iopub.status.idle":"2024-11-14T08:41:20.912754Z","shell.execute_reply.started":"2024-11-14T08:41:20.906344Z","shell.execute_reply":"2024-11-14T08:41:20.911821Z"}},"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":"2024-11-14T08:41:21.359213Z","iopub.execute_input":"2024-11-14T08:41:21.359974Z","iopub.status.idle":"2024-11-14T08:44:18.414586Z","shell.execute_reply.started":"2024-11-14T08:41:21.359943Z","shell.execute_reply":"2024-11-14T08:44:18.413742Z"}},"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":"2024-11-14T08:44:18.416330Z","iopub.execute_input":"2024-11-14T08:44:18.416651Z","iopub.status.idle":"2024-11-14T08:44:29.570988Z","shell.execute_reply.started":"2024-11-14T08:44:18.416624Z","shell.execute_reply":"2024-11-14T08:44:29.570184Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tf.random.set_seed(42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:44:29.572116Z","iopub.execute_input":"2024-11-14T08:44:29.572685Z","iopub.status.idle":"2024-11-14T08:44:29.578506Z","shell.execute_reply.started":"2024-11-14T08:44:29.572657Z","shell.execute_reply":"2024-11-14T08:44:29.577588Z"}},"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":"2024-11-14T08:44:29.581463Z","iopub.execute_input":"2024-11-14T08:44:29.581907Z","iopub.status.idle":"2024-11-14T08:44:30.785888Z","shell.execute_reply.started":"2024-11-14T08:44:29.581873Z","shell.execute_reply":"2024-11-14T08:44:30.785092Z"}},"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":"2024-11-14T08:44:30.787056Z","iopub.execute_input":"2024-11-14T08:44:30.787353Z","iopub.status.idle":"2024-11-14T08:44:30.791971Z","shell.execute_reply.started":"2024-11-14T08:44:30.787326Z","shell.execute_reply":"2024-11-14T08:44:30.791096Z"}},"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":"2024-11-14T08:44:30.792996Z","iopub.execute_input":"2024-11-14T08:44:30.793249Z","iopub.status.idle":"2024-11-14T08:44:30.829127Z","shell.execute_reply.started":"2024-11-14T08:44:30.793228Z","shell.execute_reply":"2024-11-14T08:44:30.828427Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:44:30.830102Z","iopub.execute_input":"2024-11-14T08:44:30.830360Z","iopub.status.idle":"2024-11-14T08:44:30.873034Z","shell.execute_reply.started":"2024-11-14T08:44:30.830337Z","shell.execute_reply":"2024-11-14T08:44:30.872199Z"}},"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":"2024-11-14T08:44:30.874261Z","iopub.execute_input":"2024-11-14T08:44:30.874936Z","iopub.status.idle":"2024-11-14T08:54:36.803423Z","shell.execute_reply.started":"2024-11-14T08:44:30.874904Z","shell.execute_reply":"2024-11-14T08:54:36.802645Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = model.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:54:36.804718Z","iopub.execute_input":"2024-11-14T08:54:36.805011Z","iopub.status.idle":"2024-11-14T08:54:44.163724Z","shell.execute_reply.started":"2024-11-14T08:54:36.804984Z","shell.execute_reply":"2024-11-14T08:54:44.162770Z"}},"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":"2024-11-14T08:54:44.167381Z","iopub.execute_input":"2024-11-14T08:54:44.167691Z","iopub.status.idle":"2024-11-14T08:54:44.172008Z","shell.execute_reply.started":"2024-11-14T08:54:44.167664Z","shell.execute_reply":"2024-11-14T08:54:44.171067Z"}},"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":"2024-11-14T08:54:44.173193Z","iopub.execute_input":"2024-11-14T08:54:44.173986Z","iopub.status.idle":"2024-11-14T08:54:44.183636Z","shell.execute_reply.started":"2024-11-14T08:54:44.173959Z","shell.execute_reply":"2024-11-14T08:54:44.182732Z"}},"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":"2024-11-14T08:54:44.184890Z","iopub.execute_input":"2024-11-14T08:54:44.185199Z","iopub.status.idle":"2024-11-14T08:55:04.238271Z","shell.execute_reply.started":"2024-11-14T08:54:44.185173Z","shell.execute_reply":"2024-11-14T08:55:04.237460Z"}},"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":"2024-11-14T08:55:04.239563Z","iopub.execute_input":"2024-11-14T08:55:04.239884Z","iopub.status.idle":"2024-11-14T08:55:04.247265Z","shell.execute_reply.started":"2024-11-14T08:55:04.239854Z","shell.execute_reply":"2024-11-14T08:55:04.246298Z"}},"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":"2024-11-14T08:55:04.248514Z","iopub.execute_input":"2024-11-14T08:55:04.248858Z","iopub.status.idle":"2024-11-14T08:55:04.257176Z","shell.execute_reply.started":"2024-11-14T08:55:04.248827Z","shell.execute_reply":"2024-11-14T08:55:04.256315Z"}},"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":"2024-11-14T08:55:04.259004Z","iopub.execute_input":"2024-11-14T08:55:04.259449Z","iopub.status.idle":"2024-11-14T08:55:04.275463Z","shell.execute_reply.started":"2024-11-14T08:55:04.259415Z","shell.execute_reply":"2024-11-14T08:55:04.274755Z"}},"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":"2024-11-14T08:55:04.276544Z","iopub.execute_input":"2024-11-14T08:55:04.276857Z","iopub.status.idle":"2024-11-14T08:55:04.284946Z","shell.execute_reply.started":"2024-11-14T08:55:04.276827Z","shell.execute_reply":"2024-11-14T08:55:04.283999Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import scikitplot as skplt","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:55:04.286185Z","iopub.execute_input":"2024-11-14T08:55:04.286576Z","iopub.status.idle":"2024-11-14T08:55:04.492486Z","shell.execute_reply.started":"2024-11-14T08:55:04.286524Z","shell.execute_reply":"2024-11-14T08:55:04.491590Z"}},"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":"2024-11-14T08:55:04.493807Z","iopub.execute_input":"2024-11-14T08:55:04.494152Z","iopub.status.idle":"2024-11-14T08:55:04.778658Z","shell.execute_reply.started":"2024-11-14T08:55:04.494119Z","shell.execute_reply":"2024-11-14T08:55:04.777774Z"}},"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":"2024-11-14T08:55:04.779920Z","iopub.execute_input":"2024-11-14T08:55:04.780313Z","iopub.status.idle":"2024-11-14T08:55:04.798674Z","shell.execute_reply.started":"2024-11-14T08:55:04.780277Z","shell.execute_reply":"2024-11-14T08:55:04.797859Z"}},"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":"2024-11-14T08:55:04.800196Z","iopub.execute_input":"2024-11-14T08:55:04.800613Z","iopub.status.idle":"2024-11-14T08:55:05.088181Z","shell.execute_reply.started":"2024-11-14T08:55:04.800575Z","shell.execute_reply":"2024-11-14T08:55:05.087291Z"}},"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":"2024-11-14T08:55:05.089395Z","iopub.execute_input":"2024-11-14T08:55:05.089696Z","iopub.status.idle":"2024-11-14T08:55:05.446198Z","shell.execute_reply.started":"2024-11-14T08:55:05.089670Z","shell.execute_reply":"2024-11-14T08:55:05.445251Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras.applications import ResNet50","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:55:05.447469Z","iopub.execute_input":"2024-11-14T08:55:05.447819Z","iopub.status.idle":"2024-11-14T08:55:05.453369Z","shell.execute_reply.started":"2024-11-14T08:55:05.447791Z","shell.execute_reply":"2024-11-14T08:55:05.452428Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"input_shape = (224, 224, 3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:55:05.454526Z","iopub.execute_input":"2024-11-14T08:55:05.454823Z","iopub.status.idle":"2024-11-14T08:55:05.463942Z","shell.execute_reply.started":"2024-11-14T08:55:05.454798Z","shell.execute_reply":"2024-11-14T08:55:05.463140Z"}},"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":"2024-11-14T08:55:05.464955Z","iopub.execute_input":"2024-11-14T08:55:05.465260Z","iopub.status.idle":"2024-11-14T08:55:08.407100Z","shell.execute_reply.started":"2024-11-14T08:55:05.465222Z","shell.execute_reply":"2024-11-14T08:55:08.406300Z"}},"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":"2024-11-14T08:55:08.408187Z","iopub.execute_input":"2024-11-14T08:55:08.408478Z","iopub.status.idle":"2024-11-14T08:55:08.419011Z","shell.execute_reply.started":"2024-11-14T08:55:08.408451Z","shell.execute_reply":"2024-11-14T08:55:08.418161Z"}},"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":"2024-11-14T08:55:08.420130Z","iopub.execute_input":"2024-11-14T08:55:08.420471Z","iopub.status.idle":"2024-11-14T08:55:08.997270Z","shell.execute_reply.started":"2024-11-14T08:55:08.420445Z","shell.execute_reply":"2024-11-14T08:55:08.996478Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_resnet50.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:55:08.998380Z","iopub.execute_input":"2024-11-14T08:55:08.998698Z","iopub.status.idle":"2024-11-14T08:55:09.038323Z","shell.execute_reply.started":"2024-11-14T08:55:08.998671Z","shell.execute_reply":"2024-11-14T08:55:09.037649Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras import optimizers","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T08:55:09.044418Z","iopub.execute_input":"2024-11-14T08:55:09.044701Z","iopub.status.idle":"2024-11-14T08:55:09.048885Z","shell.execute_reply.started":"2024-11-14T08:55:09.044677Z","shell.execute_reply":"2024-11-14T08:55:09.047944Z"}},"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":"2024-11-14T08:55:09.050129Z","iopub.execute_input":"2024-11-14T08:55:09.051064Z","iopub.status.idle":"2024-11-14T08:55:09.067010Z","shell.execute_reply.started":"2024-11-14T08:55:09.051028Z","shell.execute_reply":"2024-11-14T08:55:09.066332Z"}},"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":"2024-11-14T08:55:09.068072Z","iopub.execute_input":"2024-11-14T08:55:09.068396Z","iopub.status.idle":"2024-11-14T09:03:21.966903Z","shell.execute_reply.started":"2024-11-14T08:55:09.068364Z","shell.execute_reply":"2024-11-14T09:03:21.966010Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = model_resnet50.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-14T09:03:21.968294Z","iopub.execute_input":"2024-11-14T09:03:21.968625Z","iopub.status.idle":"2024-11-14T09:03:36.415080Z","shell.execute_reply.started":"2024-11-14T09:03:21.968597Z","shell.execute_reply":"2024-11-14T09:03:36.414292Z"}},"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":"2024-11-14T09:03:36.416314Z","iopub.execute_input":"2024-11-14T09:03:36.416628Z","iopub.status.idle":"2024-11-14T09:03:36.421431Z","shell.execute_reply.started":"2024-11-14T09:03:36.416601Z","shell.execute_reply":"2024-11-14T09:03:36.420260Z"}},"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":"2024-11-14T09:03:36.427636Z","iopub.execute_input":"2024-11-14T09:03:36.428331Z","iopub.status.idle":"2024-11-14T09:04:14.074886Z","shell.execute_reply.started":"2024-11-14T09:03:36.428305Z","shell.execute_reply":"2024-11-14T09:04:14.074042Z"}},"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":"2024-11-14T09:04:14.076067Z","iopub.execute_input":"2024-11-14T09:04:14.076352Z","iopub.status.idle":"2024-11-14T09:04:14.083687Z","shell.execute_reply.started":"2024-11-14T09:04:14.076328Z","shell.execute_reply":"2024-11-14T09:04:14.082717Z"}},"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":"2024-11-14T09:04:14.084765Z","iopub.execute_input":"2024-11-14T09:04:14.085049Z","iopub.status.idle":"2024-11-14T09:04:14.095156Z","shell.execute_reply.started":"2024-11-14T09:04:14.085023Z","shell.execute_reply":"2024-11-14T09:04:14.094170Z"}},"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":"2024-11-14T09:04:14.096293Z","iopub.execute_input":"2024-11-14T09:04:14.096619Z","iopub.status.idle":"2024-11-14T09:04:14.112994Z","shell.execute_reply.started":"2024-11-14T09:04:14.096584Z","shell.execute_reply":"2024-11-14T09:04:14.112287Z"}},"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":"2024-11-14T09:04:14.114051Z","iopub.execute_input":"2024-11-14T09:04:14.114637Z","iopub.status.idle":"2024-11-14T09:04:14.122246Z","shell.execute_reply.started":"2024-11-14T09:04:14.114604Z","shell.execute_reply":"2024-11-14T09:04:14.121332Z"}},"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":"2024-11-14T09:04:14.123484Z","iopub.execute_input":"2024-11-14T09:04:14.123818Z","iopub.status.idle":"2024-11-14T09:04:14.409483Z","shell.execute_reply.started":"2024-11-14T09:04:14.123793Z","shell.execute_reply":"2024-11-14T09:04:14.408716Z"}},"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":"2024-11-14T09:04:14.410493Z","iopub.execute_input":"2024-11-14T09:04:14.410807Z","iopub.status.idle":"2024-11-14T09:04:14.429155Z","shell.execute_reply.started":"2024-11-14T09:04:14.410781Z","shell.execute_reply":"2024-11-14T09:04:14.428372Z"}},"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":"2024-11-14T09:04:14.430314Z","iopub.execute_input":"2024-11-14T09:04:14.430741Z","iopub.status.idle":"2024-11-14T09:04:14.663613Z","shell.execute_reply.started":"2024-11-14T09:04:14.430709Z","shell.execute_reply":"2024-11-14T09:04:14.662767Z"}},"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":"2024-11-14T09:04:14.664786Z","iopub.execute_input":"2024-11-14T09:04:14.665125Z","iopub.status.idle":"2024-11-14T09:04:14.941523Z","shell.execute_reply.started":"2024-11-14T09:04:14.665092Z","shell.execute_reply":"2024-11-14T09:04:14.940649Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}